Home » Tag Archives: JAX-RS

Tag Archives: JAX-RS

JAX-RS Tutorial with Jersey for RESTful Web Services

java-interview-questions-answers

In today’s world data plays a very important role. With so many applications using various types of data for different operations, the most important aspect is communication between applications. Data sharing becomes easy between application when they can communicate. It’s like an application running in Asia is providing data to an application running in Europe or vice versa. How is ...

Read More »

Run away from ‘null’ checks feast: doing PATCH properly with JSON Patch

Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are struggling with. To put things into perspective, we are going to talk about web APIs, where the REST(ful) principles adhere to HTTP protocol and heavily exploit the semantics of HTTP methods and (usually but not necessarily) use ...

Read More »

Handle custom exception types in JAX-RS

java-interview-questions-answers

JAX-RS supports handling custom exceptions — thrown in either EJBs or CID beans — to custom HTTP responses. Assuming we have an “exceptional” EJB: @Stateless public class Hello { public String greeting() { if (new Random().nextBoolean()) throw new GreetingException("Could not greet"); return "hello"; } } @ApplicationException public class GreetingException extends RuntimeException { public GreetingException(String message) { super(message); } } The EJB is used in ...

Read More »

Using JAX-RS exceptions for status codes

java-interview-questions-answers

One way to send specific HTTP (error) status codes from a JAX-RS resource is to use the javax.ws.rs.core.Response class with its Builder Pattern-like API. If you want to specify the return type according to the response body, you can still do so and send a different status on errors by throwing a WebApplicationException. @Path("test") public class TestResource { @GET public ...

Read More »

Jersey client dependencies for JAX-RS 2.1

java-interview-questions-answers

Jersey is the reference implementation of JAX-RS 2.1. The following Jersey dependencies are required in order to run a JAX-RS 2.1 client with JSON-P and JSON-B mapping outside of an enterprise container. Jersey client version 2.6 implements the JAX-RS 2.1 API. Following dependencies add the client runtime to a project: <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.26</version> </dependency> ...

Read More »

Better late than never: SSE, or Server-Sent Events, are now in JAX-RS

java-interview-questions-answers

Server-Sent Events (or just SSE) is quite useful protocol which allows the servers to push data to the clients over HTTP. This is something our web browsers support for ages but, surprisingly, neglected by JAX-RS specification for quite a long time. Although Jersey had an extension available for SSE media type, the API has never been formalized and as such, ...

Read More »

What are JAX-RS Annotations? (Part 3)

java-interview-questions-answers

Overview of JAX-RS Annotations (Part 3) This is a three-part series looking at the annotation that is used to implement REST endpoints. In part two of JAX-RS annotations you learnt about: The @Path Annotation and @PathParam The @QueryParamter Annotation The @Produces Annotation The @Consumes Annotation In this part, you will learn more about JAX-RS annotations. Are you ready? let’s get started. ...

Read More »

What are JAX-RS Annotations? (Part 2)

java-interview-questions-answers

Overview of JAX-RS Annotations (Part 2) This is a three-part series looking at the annotation that is used to implement REST endpoints. In part one of JAX-RS annotations you learnt about: The @ApplicationPath Annotation The @Path Annotation The @GET HTTP Method Annotation The @POST HTTP Method Annotation The @PUT HTTP Method Annotation The @DELETE HTTP Method Annotation The @OPTIONS HTTP Method Annotation ...

Read More »

What are JAX-RS Annotations?

java-interview-questions-answers

Overview of JAX-RS (Part 1) The JAX-RS API forms an important part of the Java EE platforms commitment to provide standards-driven technology. The ubiquitous nature of the internet and that recent increasing interest in the microservice architecture has put more focus on small scalable autonomous services and their interoperability. The principal methodology used to allow microservice to communicate with each other and the ‘outside ...

Read More »