Assignment 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ASSIGNMENT 1

CO4353
Distributed Systems

NAME : G.R.L CHANDRASEKERA


INDEX NO : 16 / ENG / 019
REGISTRATION NO : EN 82648
Developing RESTful API with JAX-RS

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.

Generating STUB using SOAP


Simple Object Access Protocol is referred to as SOAP. An API for interacting with a web
service can be created using the SOAP protocol. It employs an XML-based protocol for HTTP
web service access. Additionally, SOAP uses the WSDL service definition for addressing
specifications. Since XML can be used as a markup language by any programming language,
SOAP web services also used XML for data exchange. In order to handle XML over HTTP
and create a standard that could be used by all applications, SOAP was developed.
When consider about generate a STUB using SOAP, can be followed these general steps.
 Identify the WSDL file of the web service you want to connect to. The WSDL file
describes the operations and data types used by the web service.
 Create the STUB using a tool like the SOAPUI or Apache CXF. These programs can
produce client code in a number of different programming languages, including Java,
C#, and Python.
 Launch the tool, then start a new project. Give the STUB's target programming
language and the location of the WSDL file.
 Based on the data in the WSDL file, the tool will produce the STUB code. Classes and
methods that can be used to call the web service will be included in the STUB code.
 To connect to the web service, use the STUB code in the client program. To make
requests to the web service and receive responses, instantiate the appropriate STUB
class and use its methods.
 Customize the STUB code if necessary. Need to add additional code to handle errors,
authenticate with the web service, or parse the response data.
 Test the STUB code to ensure that it is functioning correctly. Use the tool to send test
requests to the web service and verify that the responses are as expected.
 Once STUB code has been generated, it can be used in the client application to quickly
connect to and communicate with the web service.

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

You might also like