Consuming JSON object in Jersey service

As already suggested, changing the @Consumes Content-Type to text/plain will work, but it doesn’t seem right from an REST API point of view. Imagine your customer having to POST JSON to your API but needing to specify the Content-Type header as text/plain. It’s not clean in my opinion. In simple terms, if your API accepts … Read more

How do I access the HTTP request?

You can use the @Context annotation: @POST @Path(“/test”) @Produces(MediaType.APPLICATION_JSON) public String showTime( @FormParam(“username”) String userName, @Context HttpServletRequest httpRequest ) { // The method body }

Uploading file using Jersey over RESTfull service and The resource configuration is not modifiable?

In order to use multipart in your Jersey application you need to register MultiPartFeature in your application, i.e.: public class ApplicationConfig extends Application { public Set<Class<?>> getClasses() { final Set<Class<?>> resources = new HashSet<Class<?>>(); // Add your resources. resources.add(UploadFileService.class); // Add additional features such as support for Multipart. resources.add(MultiPartFeature.class); return resources; } } For more … Read more

WARNING: The (sub)resource method contains empty path annotation

The warning means you have a resource method annotated with @Path(“https://stackoverflow.com/”) or @Path(“”). For instance @Path(“test”) public class Test { @GET @Path(“https://stackoverflow.com/”) public String test(){} } Not sure why Jersey would give a warning, maybe just to make sure that’s what you really want. The reason is that a resource method with @Path(“https://stackoverflow.com/”) is redundant, … Read more

Deploying a Jersey webapp on Jboss AS 7

it has already been mentioned in this post : https://community.jboss.org/message/744530#744530 , you can just ask the resteasy module to not scan for other JAX RS implementations in your webapp; just add this to your web.xml : <context-param> <param-name>resteasy.scan</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>resteasy.scan.providers</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>resteasy.scan.resources</param-name> <param-value>false</param-value> </context-param> worked fine for me

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

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri

You’re using both Jersey 1 & 2 (Jersey 1 is an explicit dependency, Jersey 2 is a transitive dependency of jersey-test-framework-provider-jdk-http) and that’s not possible – so the classloader is picking up the wrong URIBuilder class. The Jersey dependencies in group com.sun.jersey are all Jersey version 1. Jersey version 2 uses the group org.glassfish.jersey. You … Read more

JAX-RS using exception mappers

Is InvalidDataException getting wrapped in a PersistenceException? Maybe you could do something like the following: @Provider public class PersistenceMapper implements ExceptionMapper<PersistenceException> { @Override public Response toResponse(PersistenceException arg0) { if(arg0.getCause() instanceof InvalidDataException) { return Response.status(Response.Status.BAD_REQUEST).build(); } else { … } } }

Post empty body with Jersey 2 client

I can’t find this in the doc’s anywhere, but I believe you can use null to get an empty body: final MyClass result = ClientBuilder.newClient() .target(“http://localhost:8080”) .path(“path”) .queryParam(“key”, “value”) .request(APPLICATION_JSON) .post(Entity.json(null), MyClass.class)

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