JAX-RS

Jersey (JAX-RS) JSON HTTP entity payload processing example

JSON (JavaScript Object Notation) is the most used structured data interchange format of the current generation. It is very common for REST clients to use it for data exchange. Several web client frameworks (e.g. AngularJS) natively handle JSON requests and responses. Jersey (JAX-RS) JSON support is very effective and easy to use. Usually, clients send and receive JSON …

Jersey (JAX-RS) JSON HTTP entity payload processing example Read More »

Jersey (JAX-RS) single file upload example

Jersey provides an easy mechanism to let clients upload files to the server. In this tutorial, we will learn a single file upload to Jersey (JAX-RS) endpoint. 1. Include Jersey media multipart dependency in Gradle File: build.gradle (snippet) ….dependencies { compile ‘org.springframework.boot:spring-boot-starter-web’, ‘org.springframework.boot:spring-boot-starter-jersey’, ‘org.glassfish.jersey.media:jersey-media-multipart:2.+’, ‘org.springframework.boot:spring-boot-starter-jdbc’, ‘org.springframework.boot:spring-boot-devtools’, ‘com.h2database:h2:1.4.+’ testCompile ‘org.springframework.boot:spring-boot-starter-test’}…. Jersey provides multipart form data support …

Jersey (JAX-RS) single file upload example Read More »

Spring Boot and Jersey (JAX-RS) static files support

In Spring Boot support for Jersey is provided by org.springframework.boot:spring-boot-starter-jersey Gradle dependency. When the static file URL pattern is matched with URLs that Jersey handles, additional configurations are required for Spring Boot to serve static resources. Note: We are using Gradle dependency management system, configuration for Maven will be similar. Add Spring Boot web starter dependency File : build.gradle (Snippet) dependencies { …

Spring Boot and Jersey (JAX-RS) static files support Read More »

Jersey (JAX-RS) @BeanParam to inject class with aggregated @*Param injections

It will reduce our code and improve readability, if we define injections of various @*Param values in a distinct class and reuse that in various resources. In Jersey (JAX-RS) we can achieve same using @BeanParam injection. Aggregate @*Param injections in one class and use @BeanParam to inject that class in Resources. Define Class for aggregating …

Jersey (JAX-RS) @BeanParam to inject class with aggregated @*Param injections Read More »

Jersey (JAX-RS) Java types to consume request parameter values guide

In Jersey (JAX-RS), to consume HTTP request parameter, cookie, header, path variable and matrix parameter string values, we have following options: Primitive types – int, char, float, long, double, byte and others. Types with constructor which accepts single String argument. Types with a static method with name valueOf or fromString which accepts single String argument. …

Jersey (JAX-RS) Java types to consume request parameter values guide Read More »

Jersey (JAX-RS) matrix URI parameters handling guide

URL with matrix URI looks like: https://www.example.com/map;lat=50;long=20;scale=32000 ;lat=50;long=20;scale=32000 represents matrix parameters. Please refer W3C article on it. Using @MatrixParam annotation we can get matrix parameters value from API URI in Jersey Resources classes. Using @MatrixParam at instance variable and method parameters File : MatrixUriResource.java package in.geekmj.resource;import java.util.HashMap;import java.util.Map;import javax.ws.rs.GET;import javax.ws.rs.MatrixParam;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;@Path(“/matrix-uri”)@Produces(MediaType.APPLICATION_JSON)public class MatrixUriResource { /* * We can inject matrix …

Jersey (JAX-RS) matrix URI parameters handling guide Read More »