How to inject an object into jersey request context?

You could just use ContainterRequestContext.setProperty(String, Object). Then just inject the ContainerRequestContext @Override public void filter(ContainerRequestContext crc) throws IOException { MyObject obj = new MyObject(); crc.setProperty(“myObject”, myObject); } @POST public Response getResponse(@Context ContainerRequestContext crc) { return Response.ok(crc.getProperty(“myObject”)).build(); } Another option to inject the MyObject directly is to use the HK2 functionality Jersey 2 offers. Create a … Read more

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

How I return HTTP 404 JSON/XML response in JAX-RS (Jersey) on Tomcat?

Your @Produces annotation is ignored because uncaught exceptions are processed by the jax-rs runtime using a predefined (default) ExceptionMapper If you want to customize the returned message in case of a specific exception you can create your own ExceptionMapper to handle it. In your case you need one to handle the NotFoundException exception and query … Read more

Listing all deployed rest endpoints (spring-boot, jersey)

Probably the best way to do this, is to use an ApplicationEventListener. From there you can listen for the “application finished initializing” event, and get the ResourceModel from the ApplicationEvent. The ResourceModel will have all the initialized Resources. Then you can traverse the Resource as others have mentioned. Below is an implementation. Some of the … 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>

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