users@jersey.java.net

Re: [Jersey] Re: no error message displayed on json deserialization failure during POST

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 17 Mar 2010 15:35:50 +0100

On Mar 17, 2010, at 3:08 PM, shan25 wrote:

>
> Hi Paul,
>
> Looks like the response has the error message that i was looking for
> but
> unfortunately it was some crazy message from the flex side.. But i
> could
> only notice that after enabling request/response log as you
> mentioned ?
> would have helped if it could have logged it as an error/warn in the
> server
> log as well. im guessing it would have been intentional not to log
> and put
> it back as a response?
>

Yes, Jackson is doing that and is signaling to the client that it is
in error, 400 status code, because it has sent a malformed request
entity.

Jersey should not be logging such things unless you explicitly say so
because they are not really server-side errors.

That is why request/response logging is so useful for debugging
purposes :-)

You can also enabling tracing:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/core/ResourceConfig.html
#FEATURE_TRACE

and in conjunction with response logging will give you more info
embedded in the response to how Jersey produced the response.

Paul.




> other response inline to your msg.
>
> Server log before filter
> ---------------------
> 19:09:49,525 INFO [TomcatDeployer] deploy, ctxPath=/components,
> warUrl=.../depl
> oy/components.war/
> 19:09:52,993 ERROR [STDERR] Mar 17, 2010 7:09:52 PM
> com.sun.jersey.api.core.WebA
> ppResourceConfig init
> INFO: Scanning for root resource and provider classes in the Web app
> resource pa
> ths:
> /WEB-INF/lib
> /WEB-INF/classes
> 19:09:54,743 ERROR [STDERR] Mar 17, 2010 7:09:54 PM
> com.sun.jersey.api.core.Scan
> ningResourceConfig logClasses
> INFO: Root resource classes found:
> class upm.prototype.rest.HelloWorld
> 19:09:54,743 ERROR [STDERR] Mar 17, 2010 7:09:54 PM
> com.sun.jersey.api.core.Scan
> ningResourceConfig logClasses
> INFO: Provider classes found:
> class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
> class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
> class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
> class org.codehaus.jackson.jaxrs.JacksonJsonProvider
> class
> org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider
> 19:09:55,025 ERROR [STDERR] Mar 17, 2010 7:09:55 PM
> com.sun.jersey.server.impl.a
> pplication.WebApplicationImpl initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.1.5
> 01/20/2010 03:55
> PM'
>
> 19:09:57,665 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console,
> warUrl=.../dep
> loy/jmx-console.war/
> 19:09:57,931 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on
> http-127.0.0.1-8
> 090
> 19:09:58,118 INFO [AjpProtocol] Starting Coyote AJP/1.3 on
> ajp-127.0.0.1-8009
> 19:09:58,150 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build:
> SVNTag=JBos
> s_4_2_2_GA date=200710221139)] Started in 22s:188ms
>
> Server Log After Enabling request/response logging
> ---------------------------------------
>
> 19:07:19,354 INFO [TomcatDeployer] deploy, ctxPath=/components,
> warUrl=.../depl
> oy/components.war/
> 19:07:24,651 ERROR [STDERR] Mar 17, 2010 7:07:24 PM
> com.sun.jersey.api.core.WebA
> ppResourceConfig init
> INFO: Scanning for root resource and provider classes in the Web app
> resource pa
> ths:
> /WEB-INF/lib
> /WEB-INF/classes
> 19:07:26,338 ERROR [STDERR] Mar 17, 2010 7:07:26 PM
> com.sun.jersey.api.core.Scan
> ningResourceConfig logClasses
> INFO: Root resource classes found:
> class upm.prototype.rest.HelloWorld
> 19:07:26,338 ERROR [STDERR] Mar 17, 2010 7:07:26 PM
> com.sun.jersey.api.core.Scan
> ningResourceConfig logClasses
> INFO: Provider classes found:
> class
> org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider
> class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
> class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
> class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
> class org.codehaus.jackson.jaxrs.JacksonJsonProvider
> 19:07:26,666 ERROR [STDERR] Mar 17, 2010 7:07:26 PM
> com.sun.jersey.server.impl.a
> pplication.WebApplicationImpl initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.1.5
> 01/20/2010 03:55
> PM'
>
> 19:07:29,588 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console,
> warUrl=.../dep
> loy/jmx-console.war/
> 19:07:29,932 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on
> http-127.0.0.1-8
> 090
> 19:07:30,229 INFO [AjpProtocol] Starting Coyote AJP/1.3 on
> ajp-127.0.0.1-8009
> 19:07:30,244 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build:
> SVNTag=JBos
> s_4_2_2_GA date=200710221139)] Started in 34s:859ms
> 19:07:50,963 ERROR [STDERR] Mar 17, 2010 7:07:50 PM
> com.sun.jersey.api.container
> .filter.LoggingFilter filter
> INFO: 1 * Server in-bound request
> 1 > POST http://localhost:8090/components/helloworld2
> 1 > host: localhost:8090
> 1 > user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> 1.9.1.8)
> Geck
> o/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)
> 1 > accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> 1 > accept-language: en-us,ja;q=0.7,en;q=0.3
> 1 > accept-encoding: gzip,deflate
> 1 > accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> 1 > keep-alive: 300
> 1 > connection: keep-alive
> 1 > cookie: JSESSIONID=E377F064BF1A89AE61B5F22A72C5C4D2
> 1 > content-type: application/json
> 1 > content-length: 163
> 1 >
> {"userPassword
> ":"naemdsf","description":null,"csAddresses":null,"givenName":"nae
> mdsf
> ","testfield
> ":null,"loginName":"naemdsf","middleName":null,"surname":"naemds
> f"}
> 19:07:51,822 ERROR [STDERR] Mar 17, 2010 7:07:51 PM
> com.sun.jersey.api.container
> .filter.LoggingFilter$Adapter finish
> INFO: 1 * Server out-bound response
> 1 < 400
> 1 < Content-Type: text/plain
> 1 <
> Unrecognized field "testfield" (Class upm.prototype.rest.dto.User), no
> t marked as ignorable
> at [Source: java.io.ByteArrayInputStream_at_11f74aa; line: 1, column: 86]
>
>
> Paul Sandoz wrote:
>>
>> Hi Shankar,
>>
>> Is it possible to send me the server log?
>>
>> Also can you enable server-side request/response logging as i would
>> like to see what is sent to and what returned from Jersey?
>>
>>
>> https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html
>>
>>
>> What do you mean by "Jersey 1.1.4 with jsersey 1.1.5"? is there a
>> typo?
>>
>> Shankar - Sorry type. Using Jersey 1.1.5
>>
>>
>> Plus what do you mean when you say "throws mapping exception when i
>> explicitly get the body POSTed as String and then use
>> mapper.readValue"? is this referring to flex client side?
>>
>> Shankar - I did something like this and got the exception in the
>> server
>> log
>>
>> @POST
>> @Consumes(MediaType.APPLICATION_JSON)
>> @Produces(MediaType.APPLICATION_JSON)
>> public String postUser(String body) throws Exception{
>>
>> ObjectMapper mapper = new ObjectMapper();
>> User user = mapper.readValue(body, User.class);
>> return "success";
>>
>> }
>>
>> Paul.
>>
>> On Mar 17, 2010, at 11:48 AM, Shankar K wrote:
>>
>>> if there is a problem during de-serialization of JSON body(POST) the
>>> resulting ERROR isn't logged. I have pasted below the method which
>>> accepts the POST request. I'm using a Flex Client which has been
>>> throwing infamous Error #2032: Stream whenever I POST and my server
>>> never had any error message logged indicating the problem. After
>>> going in different directions to solve it (mostly in the flex side)
>>> realized that it was due to issues during deserialization ( throws
>>> mapping exception when i explicitly get the body POSTed as String
>>> and then use mapper.readValue).
>>>
>>> Am i missing something to see these logs? Btw, I get other ERROR
>>> logs from jersey such as this -- 16:07:21,304 ERROR [STDERR] Mar 17,
>>> 2010 4:07:21 PM
>>> com.sun.jersey.server.impl.application.WebApplicationImpl initiate
>>>
>>> @POST
>>> @Consumes("application/json")
>>> @Produces("application/json")
>>> public String postUser(User body) throws Exception{
>>>
>>> return body.getGivenName();
>>>
>>> }
>>>
>>> I'm using Jersey 1.1.4 with jsersey 1.1.5 and jackson 1.4.3.
>>>
>>> Appreciate your response!!
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/no-error-message-displayed-on-json-deserialization-failure-during-POST-tp4749384p4750456.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>