Unexpected end of input : Spring + Jackson + Json - json

I am using spring framework. From a jsp page I am doing an ajax call which gives call to a controller written using spring framework. From this ajax call a json is passed as controller parameters.
I guess that if the json is small then everything is working fine but if the json length increases then I am getting following exception in the tomcat -
org.springframework.http.converter.HttpMessageNotReadableException:
Could not read JSON: Unexpected end-of-input in VALUE_STRING at
[Source: org.apache.catalina.connector.CoyoteInputStream#147fb5c4;
line: 1, column: 6454794]; nested exception is
org.codehaus.jackson.JsonParseException: Unexpected end-of-input in
VALUE_STRING at [Source:
org.apache.catalina.connector.CoyoteInputStream#147fb5c4; line: 1,
column: 6454794]
Above exception is not coming every time for a big json. In the brower console & also in the network tab I am not getting anything(so not able to capture the json).
can some one please help me out in understanding what may be the cause for this issue & how to resolve this. Its really difficult to debug this scenario as its not always getting reproduced.

Related

Spring SocketException cause JSON Parse Error

I have a Spring Boot Application, and use restTemplate to send http request to other services, problem is from time to time(not frequent) I got this Json parse exception. Retry will be successful.
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Connection reset;
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Connection reset (through reference chain: Response["data"]->java.util.ArrayList[23])\n
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:240)\n
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:225)\n
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:96)\n
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:934)\n
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:918)\n
It seems like a simple Json parse error, however I notice that in the call stack there is another cause
Caused by: java.net.SocketException: Connection reset\n
at java.net.SocketInputStream.read(SocketInputStream.java:189)\n
at java.net.SocketInputStream.read(SocketInputStream.java:121)\n
My question will this IO exception cause Json parse error.
My guess is because of TCP issue, part of Json data is lost, then Json cannot be properly parsed by the ObjectMapper.

JSON JavaScriptSerializer maxJsonLength exception (but very small payload)

I'm having an intermittent issue in MVC5 with the JSON parser throwing a System.InvalidOperationException:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Straight forward enough, but when I look at the request details, I have no idea why this would happen as the payload is very small:
(not sure how to scrape a raw request from chrome debugger, so):
The response is straightforward enough:
Any ideas on something a little less normal that might be causing this?
The problem was not in the size of the JSON request, but rather in the size of the JSON response.
return Json(model);
This the model was too large, and that's where the exception was coming from (why this wasn't raising in debug instance or logging the exception I'll have to look into...)

JsonSerializer throwing org.codehaus.jackson.map.JsonMappingException: 4000 (through reference chain: during serialization

I'm getting
java.lang.ArrayIndexOutOfBoundsException: 4000
exception during JsonSerializer with a particular Object value and rest call is resulting in
500Internal Server Error.
below is the exception returned to Dispatcher Servlet after the call is returned back to the client from Rest API call.
org.codehaus.jackson.map.JsonMappingException: 4000 (through reference
chain:
I have tried upgrading the jackson jar version also from 1.9.2 to 1.9.5 and 1.9.13, but still throwing the same exception.
I have tried making all involved POJO objects as serializable also.
If I modify anything in JSON data call is successful with Response 200.
I can't use JSON ignore property also as fields all required.
The same code works fine for other transaction.
Please share some knowledge on it.

What JSON do I send when I POST using the JIRA REST API?

I'm using /rest/api/2/screens/{screenId}/tabs/{tabId}/fields to POST fields into a tab in JIRA but I can't figure out how the JSON that I'm POSTing should be structured.
I'm receiving this error message, which is extremely difficult to understand (and Google has been minimal help): string(298) "{"errorMessages":["Unrecognized field \"id\" (Class com.atlassian.jira.rest.v2.issue.AddFieldBean), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream#5383f8a; line: 1, column: 8] (through reference chain: com.atlassian.jira.rest.v2.issue.AddFieldBean[\"id\"])"]}"
Here's the JSON that I'm currently sending: '{"id":"customfield_11930","name":"1st Review Ready"}';
I found the correct JSON structure: {"fieldId":"id"}

Message relay for JSON data in wso2ESB

I am trying to build a simple POC using wso2ESB. I've created a simple pass through proxy service with an Alfresco service http://www.alfresco.com/
The problem is I am not getting the full JSON data. I've read it has something to do with the axis2-JSON and that it causes problems when one has JSONArray in the root. So I've decided to use message relay.
WSO2 ESB Unable to convert complete JSON data to XML
I've edited the axis2.xml as described in the documentation thus adding the following lines
<messageFormatter contentType="application/json"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
and
<messageBuilder contentType="application/xml"
class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
But after I've restarted the server when I try to use the proxy server through the firefox REST plugin the ESB throws the following exception
[2012-07-12 10:02:29,125] WARN - ClientWorker Unexpected response received. HTTP response co
de : 405 HTTP status : Method Not Allowed exception : SOAP message MUST NOT contain a Documen
t Type Declaration(DTD)
[2012-07-12 10:02:29,125] ERROR - NativeWorkerPool Uncaught exception
java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to org.
apache.axiom.om.OMElement
at org.apache.synapse.util.MessageHelper.cloneSOAPFault(MessageHelper.java:441)
at org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:254)
at org.apache.synapse.core.axis2.SOAPUtils.convertSOAP11toSOAP12(SOAPUtils.java:95)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbac
kReceiver.java:323)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackRecei
ver.java:160)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.synapse.transport.nhttp.ClientWorker.run(ClientWorker.java:275)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.ja
va:173)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
What causes this? Is the problem that ESB still tries to convert the JSON object instead of trying to relay it?
Is there another workaround in parsing these JSON objects (i.e. adding artificial root to the JSON object?)
at the builders you need to set the application/json to use org.wso2.carbon.relay.BinaryRelayBuilder as well.