How to return a partial JSON response using Java?

If you use Jackson (a great JSON lib – kind of the standard for Java I believe), you may use the @View annotation to filter what you want in the resulting object. I understand that you want something dynamic so it’s a bit more complicated. You will find what you are looking for here: http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html … Read more

Optional @PathParam in Jax-RS

The problem was the lack of whitespace before the colon: @Path(“/mypath{param1: (/param1)?}”) should be: @Path(“/mypath{param1 : (/param1)?}”) Apparently it’s a bug, because the specification makes the whitespace around the colon optional. I also found that I’m not the first bitten by this bug.

Design Pattern to model Request and Response Objects for Webservices

The big problem I see in all the answers so far including the question is that they all violate the principal of separation of concerns, information hiding and encapsulation. In all answers request (and response) classes are tightly coupled to model classes. That is a more serious issue and raises a question more important than … Read more

Handling custom error response in JAX-RS 2.0 client library

I believe you want to do something like this: Response response = builder.get( Response.class ); if ( response.getStatusCode() != Response.Status.OK.getStatusCode() ) { System.out.println( response.getStatusType() ); return null; } return response.readEntity( MyEntity.class ); Another thing you can try (since I don’t know where this API puts stuff — i.e. in the header or entity or what) … Read more

In JAX RS, differences between returning Response and Bean or Collection of Beans (DTO)

The differences are explained in the JAX-RS specification: 3.3.3 Return Type Resource methods MAY return void, Response, GenericEntity, or another Java type, these return types are mapped to a response entity body as follows: void Results in an empty entity body with a 204 status code. Response Results in an entity body mapped from the … Read more

Logging request and response in one place with JAX-RS

You can create filters and easily bind them to the endpoints you need to log, keeping your endpoints lean and focused on the business logic. Defining a name binding annotation To bind filters to your REST endpoints, JAX-RS provides the meta-annotation @NameBinding and it can be used as following: @NameBinding @Retention(RUNTIME) @Target({TYPE, METHOD}) public @interface … Read more

How does one intercept a request during the Jersey lifecycle?

I’ve found the answer. First, create a class that implements ContainerRequestFilter. The interface specifies the following method, in which the filtering takes place. The ContainerRequest object contains information about the current request. public ContainerRequest filter(ContainerRequest req); After that, include the following XML in the servlet configuration in web.xml <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>path.to.filtering.class</param-value> </init-param> Sources: http://jersey.576304.n2.nabble.com/ContainerRequestFilter-and-Resources-td4419975.html http://markmail.org/message/p7yxygz4wpakqno5

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