2 Integrating WebLogic Server REST Services with Helidon
Figure 2-1 REST Services Integration with Helidon
The main difference in the usage of JAX-RS between Helidon and WebLogic Server is the
version of the supported Jakarta specification. While WebLogic Server supports
Jakarta EE 8, Helidon supports JAX-RS or the new Jakarta RESTful Web Services from
Jakarta EE 9.1. The most notable difference between these two versions of Jakarta EE
is the change in the package name, where javax
is replaced with
jakarta
.
While imports from the jakarta
namespace needs to be
used in Helidon 3.x, for WebLogic Server and Helidon 2.x, javax
should be used for the same JAX-RS code.
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
This chapter includes the following topics:
- Prerequisites
To integrate WebLogic Server with Helidon for REST services, it is assumed that you have already deployed WebLogic Server and Helidon in a Kubernetes cluster with the WebLogic Kubernetes Operator (Operator). - Using the JAX-RS Server
The JAX-RS resource is a simple bean with annotated methods representing routes and HTTP methods under a specific path. - Using the JAX-RS Client
JAX-RS provides a convenient client API for calling the RESTful resources. The client enables you to prepare and execute the RESTful request call with a simple builder pattern API.
Prerequisites
To deploy WebLogic Server, ensure that you have:
- A good understanding about the Operator. See WebLogic Kubernetes Operator.
- Installed and configured the Operator. See Model in Image.
To download the WebLogic Server Java clients with Jakarta packages, see Downloading the WebLogic Server Java Clients with Jakarta Package Names.
Parent topic: Integrating WebLogic Server REST Services with Helidon
Using the JAX-RS Server
JAX-RS Example Resource
@Path("/greet") (1)
public class GreetResource {
@Path("/hello")
@GET (2)
@Produces(MediaType.TEXT_PLAIN) (3)
public Response getHello() {
return Response.ok("Hello World!") (4)
.build();
}
}
A brief description of the above example:
(1) Path of the resource.
(2) HTTP method.
(3) Expected response content type.
(4) Returns the text payload with status 200.
JAX-RS is a very powerful tool where you can register your message body writers, readers, filters, or exception mappers. In both Helidon and WebLogic Server, Eclipse Jersey is used as the JAX-RS implementation. See Jersey User Guide.
For information about creating and deploying the JAX-RS RESTful resources in Helidon, see JAX-RS applications.
For information about developing and deploying the JAX-RS resources on WebLogic Server, see Developing RESTful Web Services.
Parent topic: Integrating WebLogic Server REST Services with Helidon
Using the JAX-RS Client
JAX-RS provides a convenient client API for calling the RESTful resources. The client enables you to prepare and execute the RESTful request call with a simple builder pattern API.
JAX-RS Client Example
Client client = ClientBuilder.newClient();
String res = client
.target("http://localhost:8080") (1)
.path("/greet") (2)
.request("text/plain") (3)
.get(String.class); (4) (5)
A brief description of the above example:
(1) Creates a new WebTarget with the default root URL.
(2) Prepares the request to a particular context path.
(3) Sets the expected response content type.
(4) Executes the GET request and blocks until the response is received.
(5) Parameter sets the expected response payload type; available body readers are used for parsing to the correct response payload type.
You can also register your own message body writers, readers, filters, or exception mappers.
For information about creating JAX-RS clients in Helidon, see Jakarta REST (JAX-RS) Client.
For information about developing and deploying JAX-RS clients on WebLogic Server, see Developing RESTful Web Services.
Parent topic: Integrating WebLogic Server REST Services with Helidon