简体   繁体   中英

A rest that call another rest and response “400 bad request”

I'm programming in Java a REST that calls another REST. The response from the second REST is transformed into a object and added into a List, and when the List has 12 elements, the REST response should be "400 bad request".

I'm receiving the error in the GET of this method. I have a foreach that calls this method 20 times. The first 11 times work, but the 12th time I receive the bad request.

Client call:

private String callAcountingDebitCreditServiceAcount(
            long originalOption, long codeInstance, long codeCompany, String codeBranch,
            String codeOffice, String currency, String inputCost, long operationNumber,
            String jsonResult, long originalOptionMenu, long codeTrans, String tableName,
            String pkJson)
    throws UnsupportedEncodingException, IOException {
        String jsonFuente = jsonResult;
        jsonFuente = URLEncoder.encode(jsonFuente, "utf-8");
        String pkj = URLEncoder.encode(pkJson, "utf-8");
        String URLrest = "http://llacsaa-server:9080/JorupeInstanceWS/webresources/accountingDebitCreditService";
        String respuestaStr = ClientBuilder.newClient()
            .target(URLrest)
            .queryParam("codeInstance", codeInstance)
            .queryParam("codeCompany", codeCompany)
            .queryParam("codeTrans", codeTrans)
            .queryParam("codeBrach", codeBranch)
            .queryParam("codeOffice", codeOffice)
            .queryParam("originalOption", originalOption)
            .queryParam("currency", currency)
            .queryParam("inputCost", inputCost)
            .queryParam("operationNumber", operationNumber)
            .queryParam("jsonArrayScreen", jsonFuente)
            .queryParam("originalOptionMenu", originalOptionMenu)
            .queryParam("tableName", tableName)
            .queryParam("pkJson", pkj)
            .request()
            .get(String.class);
        ResponseRest respuesta = new ResponseRest();
        return respuesta.process(respuestaStr).toString();
    }

Enpoint code:

@Stateless
@Path("accountingDebitCreditService")
public class AccountingDebitCreditREST {

@Inject
private ServiceRegistry services;

@GET
@Produces(MediaType.APPLICATION_JSON)
public ResponseRest accountingDebitCredit(
        @QueryParam("originalOption") long originalOption,
        @QueryParam("codeInstance") long codeInstance,
        @QueryParam("codeCompany") long codeCompany,
        @QueryParam("codeBrach") String codeBranch,
        @QueryParam("codeOffice") String codeOffice,
        @QueryParam("currency") String currency,
        @QueryParam("inputCost") String inputCost,
        @QueryParam("operationNumber") long operationNumber,
        @QueryParam("jsonArrayScreen") String jsonArrayScreen,
        @QueryParam("originalOptionMenu") long originalOptionMenu,
        @QueryParam("codeTrans") long codeTrans,
        @QueryParam("tableName") String tableName,
        @QueryParam("pkJson") String pkJson)

Did you try replacing

.request()

By:

.request(MediaType.APPLICATION_JSON_TYPE)

And don't forget the import:

import javax.ws.rs.core.MediaType;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM