JAX-RS jersey ExceptionMappers User-Defined Exception

You need to annotate your exception mapper with @Provider, otherwise it will never get registered with the JAX-RS runtime. @Provider public class UserNotFoundMapper implements ExceptionMapper<UserNotFoundException> { @Override public Response toResponse(UserNotFoundException ex) { return Response.status(404).entity(ex.getMessage()).type(“text/plain”) .build(); } }

jaxrs-api VS jsr311-api VS javax.ws.rs-api VS jersey-core VS jaxrs-ri

I’ll first get to the question “JSR311 it is a specification request. Which means it is supposed to be a document. Why then is it a jar?” Except the last (jersey-core), all those jars are “specification” jars. The JAX-RS (as well as many other Java) specifications define contracts (or interfaces) that implementators should implement the … Read more

Jersey/JAX-RS : How to cascade beans-validation recursively with @Valid automatically?

Actually, according to the specification, adding @Valid is exactly for this usecase. From the JSR 303 specification: In addition to supporting instance validation, validation of graphs of object is also supported. The result of a graph validation is returned as a unified set of constraint violations. Consider the situation where bean X contains a field … Read more

Jersey + Jackson JSON date format serialization – how to change the format or use custom JacksonJsonProvider

I managed to do it in Resteasy “the JAX-RS way”, so it should work on every compliant implementation like Jersey (recently successfully tested on JEE7 server Wildfly 8, it just required a few changes to the Jackson part because they changed a few APIs). You must define a ContextResolver (check that Produces contains the correct … Read more

What objects can I inject using the @Context annotation?

The @Context annotation allows you to inject request/response context details into JAX-RS provider and resource classes. Injection can be performed into a class field, a bean property or a method parameter. The following list summarizes all the types that can be injected using the @Context annotation, according to the JAX-RS 2.0 specification: javax.ws.rs.core.Application javax.ws.rs.core.HttpHeaders javax.ws.rs.core.Request … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)