users@jersey.java.net

[Jersey] Jersey hangs when invalid JSON is sent in POST request

From: nbaliga <nbaliga_at_cleartrial.com>
Date: Thu, 24 Mar 2011 12:32:33 -0700 (PDT)

Hello,
I'm am noticing that when I am sending incorrect JSON (such as a closing ]
missing for e.g.), Jersey seems to hang without coming back with any kind of
an error message.

I have JAXB annotated POJOs and everything works when the happy path is
followed. I am able to POST JSON, GET JSON as well as XML.

The thread dump is as below:
Grizzly-9998-WorkerThread(0)@3183 daemon, prio=10, in group 'Grizzly',
status: 'runnable'
  java.lang.Thread.State: RUNNABLE
          at
com.sun.jersey.json.impl.reader.JsonXmlStreamReader.nextToken(JsonXmlStreamReader.java:160)
          at
com.sun.jersey.json.impl.reader.JsonXmlStreamReader.readNext(JsonXmlStreamReader.java:187)
          at
com.sun.jersey.json.impl.reader.JsonXmlStreamReader.readNext(JsonXmlStreamReader.java:178)
          at
com.sun.jersey.json.impl.reader.JsonXmlStreamReader.next(JsonXmlStreamReader.java:448)
          at
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:192)
          at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
          at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
          at
com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalJAXBElementFromJSON(BaseJSONUnmarshaller.java:108)
          at
com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalFromJSON(BaseJSONUnmarshaller.java:97)
          at
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.readFrom(JSONRootElementProvider.java:125)
          at
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:109)
          at
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:454)
...
...

Any pointers on how I can go about getting an exception or something thrown
so that I can return appropriate error messages to consumers of my API?

I do not have any configuration on Jersey, save the Logging and Gzip
filters. Everything else is out of the box. I am using Jersey 1.4, but I've
tried upgrading to 1.5 and am seeing the same problem.

- Thanks.

--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-hangs-when-invalid-JSON-is-sent-in-POST-request-tp6205397p6205397.html
Sent from the Jersey mailing list archive at Nabble.com.