Assignment 1
Assignment 1
Assignment 1
CO4353
Distributed Systems
Web services are services that are accessible via programmatic means via the internet. They
are referred to as online APIs that are programmable. RESTful web services are a type of
contemporary, lightweight web service that make extensive use of the concepts behind HTTP.
Building web services in Java often involves creating a RESTful API using JAX-RS. The Java
programming language API known as JAX-RS offers support for producing and utilizing
RESTful web services.
When thinking about how to create a RESTful API using JAX-RS, Basic steps can be
considered for that.
A new java project is created in preferred IDE.
Add the JAX-RS dependencies to the project. The most common implementation is
Jersey, so can add the following dependency to the pom.xml file if Maven is being used:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.0.3</version>
</dependency>
Establish the resources: A RESTful endpoint is represented by a Java class called a
resource. To specify the endpoint URL, annotate the resource class with the @Path
annotation. The URI path, which is relative to the base URI, is matched using the @Path
annotation. On the resource class or method, it can be specified.
Classify the resource types. A Java class called a resource class manages HTTP requests
and responses. Every method in the class needs to have a JAX-RS annotation, like
@GET, @POST, @PUT, or @DELETE.
On the corresponding resource path, the @POST annotated method will handle
HTTP POST requests.
The @PUT annotated method will handle the HTTP PUT requests on the
matching resource path.
The HTTP GET requests on the corresponding resource path will be handled by
the @GET annotated method.
The @DELETE annotated method will handle the HTTP DELETE requests on
the matching resource path.
Handle request parameters and body: To handle query parameters, path parameters, and
1
form data, JAX-RS annotations like @QueryParam, @PathParam, and @FormParam
can be used.
Return response: To specify the kind of response the resource method produces, use
JAX-RS annotations like @Produces.
Test your API: Use a tool like Postman or curl to test your API and make sure it works as
expected.
2
The Java API for XML Web Services technology can be used to generate a SOAP stub in
Java. The general steps to take are listed below:
To create the Java classes that represent the SOAP web service, use the wsimport
tool. The Java Development Kit (JDK) comes with this tool, which can be used
from the command line. For instance:
Figure 1
Based on the WSDL file located at the specified URL, Java classes will be created
in the current directory.
Make a Java client that calls the SOAP web service using the generated classes. The
operations specified by the web service should be called by this client using a
service object that it should create as a proxy for the web service.
Illustrative code showing how to build a client for a SOAP web service:
Figure 2
In this illustration, the WSDL file's service definition is referred to as SomeService, and the
interface SomeService.class specifies the service's methods. This interface's port instance can
be used to call the methods. In this instance, using the "parameter" parameter when calling the
someMethod method.
3