users@jersey.java.net

[Jersey] Re: question on exception handling

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Wed, 29 Jun 2016 00:59:12 -0400

I suspect that returning null will result in an HTTP 204 ("No Content")
response. Try it and let us know :)

Gili

On 2016-06-29 12:40 AM, Richard Sand wrote:
> That does help, thanks! You are right, the exception was actually
> caused by an interrupted request, not something in the resource code.
> No wonder I couldn't find it :-)
>
> Do you know what the default behavior is for a resource that returns a
> null object? Sorry I know I can test this to figure it out myself but
> I'd like to know what other developers of Jersey services typically do
> in such cases. Thanks!
>
> -Richard
>> cowwoc <mailto:cowwoc_at_bbs.darktech.org>
>> June 28, 2016 at 1:06 AM
>> It's not clear whether these two exceptions are actually related. I
>> will comment on the second exception though: your resource method was
>> in the process of reading the HTTP request body and converting it
>> into an object (whatever parameters you declared on your method) but
>> someone terminated the connection before it could complete the
>> conversion. For example, if your method takes a Date parameter but
>> the HTTP body was empty, you'd get this error.
>>
>> I hope this helps.
>>
>> Gili
>>
>>
>>
>>
>> Richard Sand <mailto:rsand_at_idfconnect.com>
>> June 28, 2016 at 12:56 AM
>> Hi all - I'm seeing an exception coming back from Jersey for one of
>> my test cases and I can't determine exactly where its coming from in
>> my code. I suspect its a NPE from within the class that my resource
>> is returning but I'm not sure.
>>
>> Couple of questions:
>>
>> 1) When a resource returns a JAXB class as opposed to a Response
>> object, what actually is supposed to happen if the returned object is
>> null?
>>
>> 2) If the response is going to be null, is it better generate an
>> exception that gets mapped in Jersey to provide a more interesting
>> response to the client?
>>
>> Here is my stack trace - is this caused by an NPE or other runtime
>> exception in the returned class during the marshaling?
>>
>> 2016-06-27 16:04:54.993 [tomcat-http--3] DEBUG
>> c.s.j.s.container.ContainerResponse - Mapped exception to response: 405
>> javax.ws.rs.WebApplicationException: null
>> at
>> com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66)
>> at
>> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
>> at
>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
>> at
>> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
>> .....
>> 2016-06-27 16:05:26.511 [tomcat-http--4] ERROR
>> c.s.j.s.container.ContainerResponse - The exception contained within
>> MappableContainerException could not be mapped to a response,
>> re-throwing to the HTTP container
>> java.io.EOFException: No content to map to Object due to end of input
>> at
>> org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2766)
>> at
>> org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682)
>> at
>> org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
>> at
>> org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
>> at
>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:490)
>> at
>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:555)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider.processForm(FormDispatchProvider.java:103)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider.access$000(FormDispatchProvider.java:68)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider$FormParameterProvider.getInjectableValues(FormDispatchProvider.java:115)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:183)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
>> at
>> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
>> at
>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
>> at
>> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
>> at
>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
>> at
>> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
>> at
>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>>
>>
>> Thanks for any help!
>>
>> -Richard
>