How to fix Jersey POST request parameters warning?

For me the warning was showing for POST application/x-www-form-urlencoded. And I am using Spring Boot which has an HiddenHttpMethodFilter that does a getParameter before anything else… So I ended up doing this nasty override: @Bean public HiddenHttpMethodFilter hiddenHttpMethodFilter() { return new HiddenHttpMethodFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException … 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

How to add Headers on RESTful call using Jersey Client API

I use the header(name, value) method and give the return to webResource var: Client client = Client.create(); WebResource webResource = client.resource(“uri”); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add(“json”, js); //set parametes for request appKey = “Bearer ” + appKey; // appKey is unique number //Get response from RESTful Server get(ClientResponse.class); ClientResponse response = webResource.queryParams(queryParams) .header(“Content-Type”, … Read more

jersey security and session management

Session management is the purview of the container in which Jersey is deployed. In most production cases, it will be deployed within a container that performs session management. The code below is a simple example of a jersey resource that gets the session object and stores values in the session and retrieves them on subsequent … 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

Session management : How to generate Authentication token for REST service ? (Jersey)

For simplicity sake, I generate my own authentication token using UUID before encrypting the entire token with Jasypt:- String key = UUID.randomUUID().toString().toUpperCase() + “|” + someImportantProjectToken + “|” + userName + “|” + creationDateTime; StandardPBEStringEncryptor jasypt = new StandardPBEStringEncryptor(); … // this is the authentication token user will send in order to use the web … Read more

Jersey ContainerRequestFilter not triggered

Okay, I didn’t get that the jersey.config.server.provider.packages init param needs to reference not only service classes (API endpoints) but ALL the classes including filters. Now it works : <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.hck.debate.rest.controller;com.hck.debate.rest.security</param-value> </init-param> <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>com.hck.debate.rest.security.AuthFilter</param-value> </init-param>

Handling Multiple Query Parameters in Jersey

If you change the type of your item method parameter from String to a collection such as List<String>, you should get a collection that holds all the values you are looking for. @GET @Path(“/foo”) @Produces(“text/plain”) public String methodImCalling(@DefaultValue(“All”) @QueryParam(value = “item”) final List<String> item) { return “values are ” + item; } The JAX-RS specification … Read more