3

How can I intercept a parse error in my Jersey REST application? I already registered an ExceptionMapper<Exception> but those don't get caught.

It returns the following to the client

Unexpected character ('y' (code 121)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.catalina.connector.CoyoteInputStream@161d5f3; line: 1, column: 92] 

But I want to send my own Response.

7
  • 1
    How did you define and register your ExceptionMapper? Are you sure it's registered and applicable for the exception being thrown? Commented Dec 27, 2012 at 16:56
  • Yes, I'm sure because it captures other exceptions. It should capture any exception deriving from Exception. I also tried with Throwable just to be sure. Commented Dec 27, 2012 at 17:06
  • 1
    You can always catch this exception and return appropriate Response. Commented Dec 28, 2012 at 10:15
  • 1
    Yes, my exception mapper works, but not for those... Commented May 22, 2013 at 13:15
  • 1
    For anyone coming across this, here is the answer Commented Aug 9, 2017 at 9:01

1 Answer 1

0

I'm guessing however your ExceptionMapper is registered, it isn't being applied to other packages, where you're invoking the Jersey library code to parse JSON.

Surround all calls to Jersey for parsing in a Try{ }catch() block, where the catch should return an error code and not process further.

Alternatively, it looks like Tomcat might be throwing the error before it even gets to your application. Maybe an issue with the way it is configured, or the way the client is communicating? Is this plaintext HTTP?

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not calling jersey; jersey calls my code. And I'm not using tomcat.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.