I am getting "Json.parse:unexpected end of data" in my client side,When i make rest request to my API using GWT.
Client side code :
private void executeUnAccountedTransactionByService(String requestJson)
{
String requestData = "request=" + URL.encodeQueryString(requestJson);
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(postPaymentUrl));
builder.setHeader("Content-Type","application/x-www-form-urlencoded");
builder.setHeader("Accept","application/json") ;
try {
builder.sendRequest(requestData, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
JSONValue jsonValue = JSONParser.parseStrict(response.getText());
JSONObject responseObject = jsonValue.isObject();
//my logic
}
@Override
public void onError(Request request, Throwable exception) {
}
});
}
catch (RequestException e) {
}
}
My API Code :
@RequestMapping(value = "/url",
method = RequestMethod.POST)
public @ResponseBody ResponseEntity<?> processPayment(
@RequestParam("request") String payRequestJson,
HttpServletRequest servletRequest) {
PutUnAccountedTransaction unAccountedTransaction = null ;
try {
LOGGER.info("request recieved unaccounted transaction : " +
payRequestJson);
unAccountedTransaction = objectMapper.readValue(payRequestJson, PutUnAccountedTransaction.class) ;
} catch (Exception e) {
//currenlty handling success case only.
return ResponseEntity.ok(unAccountedTransaction);
}
return ResponseEntity.ok(unAccountedTransaction);
}
The same API I call in postman with following values: HEADERs :
Content-Type : application/x-www-form-urlencoded
request : {"applicationIdentiferICC":"jh2b32vy","amount":"100","authCode":"hhbjhbjh","orderNumber":"jhsbhjb","dateTimeInUTC":"03/01/2017 07:20:57","gatewayName":"gatewayname","transactionReference":"asdhgwvg","dealerId":"bhjhahdbj","cardType":"VISA","terminalId":"jjhbjhbhjbj","userReference":"bjhbjh","paymentType":"EMV_CHIP","expMonth":"09","expYear":"19","cardNumber":"1111"}
and I am getting expected response back.
I thought the problem is due to "Accept" header .I have tried with "/","application/x-www-form-urlencoded" ,But I am getting same error.
the response I am getting back in postman:
{
"gatewayName": "credit-call",
"dealerId": 1278,
"terminalId": "jjhbjhbhjbj",
"amount": 100,
"orderNumber": "jhsbhjb",
"cardNumber": "9111",
"cardType": "Disc",
"dateTimeInUTC": "03/01/2017 07:20:57",
"paymentType": "EMV_CHIP",
"authCode": "hhbjhbjh",
"transactionReference": "asdhgwvg",
"userReference": "bjhbjh",
"applicationIdentiferICC": "jh2b32vy",
"expMonth": 9,
"expYear": 12,
"dateTimeInPST": null,
"inoiceGuid": null,
"description": null
}
Response heades recieved after inspecting client in browser.
Server: Apache-Coyote/1.1
X-Application-Context: postpayment:devvm
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 01 Mar 2017 15:28:17 GMT
I am using GWT 2.5 version.
I am getting following error :
java.lang.IllegalArgumentException: empty argument
at com.google.gwt.json.client.JSONParser.parse(JSONParser.java:210)
at com.google.gwt.json.client.JSONParser.parseStrict(JSONParser.java:87)
at line
JSONValue jsonValue = JSONParser.parseStrict(response.getText())
Check your response JSON and confirm that it is valid. The error indicates that the request is just fine, but that when the response JSON string gets to the browser
JSONParser.parseStrict(response.getText())cannot parse it because it isn't legal JSON.Share the response JSON and the response headers here if you need more help.