What exactly is the ResourceConfig class in Jersey 2?

Standard JAX-RS uses an Application as its configuration class. ResourceConfig extends Application. There are three main ways (in a servlet container) to configure Jersey (JAX-RS): With only web.xml With both web.xml and an Application/ResourceConfig class With only an Application/ResourceConfig class annotated with @ApplicationPath. With only web.xml It is possible to configure the application in a … Read more

POST to Jersey REST service getting error 415 Unsupported Media Type

The Jersey distribution doesn’t come with JSON/POJO support out the box. You need to add the dependencies/jars. Add all these jersey-media-json-jackson-2.17 jackson-jaxrs-json-provider-2.3.2 jackson-core-2.3.2 jackson-databind-2.3.2 jackson-annotations-2.3.2 jackson-jaxrs-base-2.3.2 jackson-module-jaxb-annotations-2.3.2 jersey-entity-filtering-2.17 With Maven, below will pull all the above in <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.17</version> </dependency> For any future readers not using Jersey 2.17 (and using jars directly instead … Read more

MULTIPART_FORM_DATA: No injection source found for a parameter of type public javax.ws.rs.core.Response

Get rid of jersey-multipart-1.18.jar. That is for Jersey 1.x. Add these two jersey-media-multipart-2.17 mimepull-1.9.3 For Maven you would use the following dependency (you don’t need to explicitly add the mimepull dependency, as this one will pull it in). <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-multipart</artifactId> <version>2.17</version> <!– Make sure the Jersey version matches the one you are currently using … Read more

Dependency injection with Jersey 2.0

You need to define an AbstractBinder and register it in your JAX-RS application. The binder specifies how the dependency injection should create your classes. public class MyApplicationBinder extends AbstractBinder { @Override protected void configure() { bind(MyService.class).to(MyService.class); } } When @Inject is detected on a parameter or field of type MyService.class it is instantiated using the … Read more

How to implement REST token-based authentication with JAX-RS and Jersey

How token-based authentication works In token-based authentication, the client exchanges hard credentials (such as username and password) for a piece of data called token. For each request, instead of sending the hard credentials, the client will send the token to the server to perform authentication and then authorization. In a few words, an authentication scheme … Read more