我在客户端收到“Json.parse:unexpected end of data”,当我使用 GWT 向我的 API 发出休息请求时。
客户端代码:
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) {
}
}
我的 API 代码:
@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);
}
我在邮递员中调用的相同 API 具有以下值: HEADERs :
Content-Type : application/x-www-form-urlencoded
要求 :{"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"}
我得到了预期的回应。
我认为问题是由于“接受”标头造成的。我尝试过使用“ / ”、“application/x-www-form-urlencoded”,但我得到了同样的错误。
我在邮递员中得到的回复:
{
"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
}
在浏览器中检查客户端后收到响应头。
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
我正在使用 GWT 2.5 版本。
我收到以下错误:
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)
在线
JSONValue jsonValue = JSONParser.parseStrict(response.getText())