Questions tagged [exceptionmapper]

JAX-RS contract for a provider that maps Java exceptions to Response.

From Javadoc

public interface ExceptionMapper<E extends Throwable>

Contract for a provider that maps Java exceptions to Response.

Providers implementing ExceptionMapper contract must be either programmatically registered in a JAX-RS runtime or must be annotated with @Provider annotation to be automatically discovered by the JAX-RS runtime during a provider scanning phase.

46 questions
11
votes
3 answers

Jersey unable to catch any Jackson Exception

For my REST api I'm using jersey and ExceptionMapper to catch global exceptions. It works well all the exception my app throws but I'm unable to catch exception thrown by jackson. For example one of my endpoint accept an object that contains an…
Johny19
  • 5,364
  • 14
  • 61
  • 99
5
votes
4 answers

how to map JSON parsing related errors to json response in jersey

I defined a datatype and its API: public class DataType { @Column private String name; } // API is: public class DataTypeAPI { @POST @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) …
BAE
  • 8,550
  • 22
  • 88
  • 171
5
votes
1 answer

Catching any exception Jackson throws with a single ExceptionMapper

I have a JAX-RS project that uses Jackson to handle JSON conversions. When Jackson throws an exception, it automatically returns a string with the error description. Since I want to return a custom JSON object, I created an ExceptionMapper. The…
vixprogram
  • 61
  • 2
5
votes
3 answers

Jersey ExceptionMapper not being invoked

I am trying to invoke this exception mapper to return a 404 not found response but it keeps returning 500 internal error. Jersey version is 2.22.1. Code snippet below. Appreciate all help. Thanks. Exception mapper class. package…
Ralf Zhang
  • 171
  • 1
  • 2
  • 4
5
votes
0 answers

JAX-RS exception handling and ExceptionMapper

I have implemented some custom exceptions like: NotFoundException, BadRequestException, and for each of them I have implemented its own ExceptionMapper like NotFoundExceptionMapper, BadRequestExceptionMapper and also something like…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
4
votes
1 answer

Jersey test - ExceptionMapper is not invoked

I have REST web service which I test with Jersey Test, Mockito, Junit. When web service method is executed successfully, I get correct response. In case of invalid data, custom exception is thrown which must be handled by ExceptionMapper. It should…
4
votes
2 answers

JAXRS/Jersey 2 - Validation errors does not invoke the ExceptionMapper

using latest Jersey (2.22.1), I've successfully created my custom validators for various needs. But my custom ExceptionMapper (registered as a provider in web.xml) is not invoked when a ConstraintViolationException occurs, altough it is defined as…
spi
  • 626
  • 4
  • 19
3
votes
0 answers

use exceptionMapper for restcontroller so that jersey and restcontroller can coexist

I was using spring boot with Jersey 1. Used ExceptionMapper to handle the exceptions globally. Now we are planning to migrate to spring MVC for restful purpose. So, changing few of the endpoints to use dispatcher servlet. Is there any way to handle…
Ajay
  • 4,134
  • 3
  • 20
  • 19
3
votes
1 answer

ExceptionMapper not working as expected

I am using jersey for REST web services. I am handling all 404 responses by throwing NotFoundException(Package com.sun.jersey.api) whenever I don't get any object from service layer. e.g.…
dk_123
  • 41
  • 1
  • 2
2
votes
1 answer

Why CORSFilter conflicts with ExceptionMapper?

I have this Java thorntail application, where I wanted to catch all uncaught exceptions. I wanted to respond with 500 instead of the default error page that JAXRS gives, so I just used implementation of ExceptionMapper. Did the testing…
trimpirim
  • 71
  • 1
  • 7
2
votes
2 answers

JAX-RS (jersey implementation) ExceptionMapper aren't catching ConstraintViolationException

I have an ExceptionMapper as a @Provider for handling all of my exceptions. So it is obvious that my class implements ExceptionMapper and we as know, all exceptions are extended Throwable somehow. Now I used jax-rs @NotNull to checking my…
Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37
2
votes
1 answer

Multiple ExceptionMappers in Jersey

Assume I have two ExceptionMappers: public class WebApplicationExceptionMapper implements ExceptionMapper ( class WebApplicationException extends RuntimeException ) public class GenericExceptionMapper implements…
BAE
  • 8,550
  • 22
  • 88
  • 171
2
votes
1 answer

JAX-RS Exception Mapper not working in Grizzly container

Working on a Jersey web application with a team, as the project got bigger and bigger, we decided to switch from Tomcat to Grizzly to allow deploying parts of the project on different port numbers. What I've found out now, that the custom exception…
logi0517
  • 813
  • 1
  • 13
  • 32
2
votes
1 answer

How to retrieve resource method's Annoations in MessageBodyWriter in Jersey?

jersey 2.21. I have a resource file like below …… @POST @Path("/userReg") @Produces("application/json;charset=UTF-8") public JsonResp userReg(UserRegReq userRegReq) throws LoginNameExists { HttpHeaderUtils.parseHeaders(userRegReq, headers); …
Joey
  • 23
  • 6
2
votes
0 answers

How to change swagger response for exception

I am using spring boot with swagger for REST API services. The swagger returns the response in the following format when exception occurs { "timestamp": 1449742584285, "status": 500, "error": "Internal Server Error", "exception":…
Achaius
  • 5,904
  • 21
  • 65
  • 122
1
2 3 4