jersey icon indicating copy to clipboard operation
jersey copied to clipboard

I can't capture ProcessingException when sending object instead of array

Open glassfishrobot opened this issue 9 years ago • 10 comments

Every time you send an object instead of an expected array I get an javax.ws.rs.ProcessingException that cannot be captured by a ExceptionMapper<Exception> I have tried different jersey 2.0 versions with the same result.

http://stackoverflow.com/questions/41544413/i-cant-capture-processingexception-when-sending-object-instead-of-array

Environment

Ubuntu or Windows / JDK 1.7 / Tomat 7

Affected Versions

[2.25]

glassfishrobot avatar Jan 16 '17 09:01 glassfishrobot

Reported by Dissident

glassfishrobot avatar Jan 16 '17 09:01 glassfishrobot

@pavelbucek said: Can you please share complete project? (ideally as github project, with described reproducer / curl command)

The exception here means that Jersey created incorrect mode somewhere - it tries to invoke resource method with different number of parameters. I haven't seen that before and the information on stackoveflow is not enough to reproduce the issue locally.

glassfishrobot avatar Jan 16 '17 09:01 glassfishrobot

dissident said: http://www.jcgonzalez.com/img/TestJersey.zip This is a maven project.

http://localhost:8080/TestJersey/rest/hello/post Content-Type: application/json

I'm using RestClient for Firefox

Result OK [

{ "test":"123456" }

]

Result error

{ "test":"123456" }

glassfishrobot avatar Jan 16 '17 09:01 glassfishrobot

@pavelbucek said: so you are expecting an array and you send just an element and you'll get this exception, is that correct?

Also, your GenericException, which implements ExceptionMapper, is not annotated with @Provider. @Path is only for resource classes.

Can you re-run the test and evaluate again?

glassfishrobot avatar Jan 16 '17 09:01 glassfishrobot

dissident said: Now the issue seems to be that I can't capture a java.lang.IllegalArgumentException when I expect and array and I just send an element.

public Response testInJSON(@Valid Test[] test) {

http://www.jcgonzalez.com/img/TestJersey2.zip

glassfishrobot avatar Jan 16 '17 10:01 glassfishrobot

dissident said: It seemed to work fine for a moment. The ProcessingException problem still persist.

glassfishrobot avatar Jan 16 '17 10:01 glassfishrobot

schivmeister said: Any updates on this? I can confirm – I spent quite some time trying to debug this. It is not until I was composing a StackOverFlow post that I was led to the related question.

I am trying to produce a custom HTTP response for when the client submits an instance body but the endpoint expects a collection. In such cases the server (or Tomcat) produces 500 Internal Server Error, with a message pointing to "javax.ws.rs.ProcessingException: Resource Java method invocation error."

It looks like a child of ServletException, and the root cause is an IllegalArgumentException, but none of the three allowed me to filter for the exception in an ExceptionMapper. I then tried just Exception out of desperation, and to my shock, it did not catch the error either. My belief then was that the exception is produced before Jersey kicks in and handles the request and/or the exception mappers, and therefore the application is unable to map it.

Some pointers to workarounds would help, as I managed to catch the inverse of the problem (client submits collection body but server expects instance) with QueryException (it is outside of a WebApplicationException). So I am holding on to the belief that I can still map this one.

glassfishrobot avatar Apr 17 '17 13:04 glassfishrobot

This issue was imported from java.net JIRA JERSEY-3222

glassfishrobot avatar Apr 25 '17 05:04 glassfishrobot

Shortly before the 1-year-anniversary of this bug -- will there ever be progress on it?

xamde avatar Jan 04 '18 15:01 xamde

Shortly after the 1 year anniversary --- +1.

nemrod avatar Jan 30 '18 12:01 nemrod