SlideShare una empresa de Scribd logo
1 de 62
Descargar para leer sin conexión
© People Strategists www.peoplestrategists.com Slide 1 of 62
Overview Web Service
© People Strategists www.peoplestrategists.com Slide 2 of 62
In this session, you will learn to:
Identify SOA
Identify to Web services
Identify JAXB
Identify RESTful
Objectives
© People Strategists www.peoplestrategists.com Slide 3 of 62
SOA is a software architecture, which is essentially a collection of
services communicating with each other.
The SOA concept is implemented by using Web services.
The following figure shows a basic SOA.
SOA architecture is based on the following building blocks:
The service provider:These componentsprovideaccess to the interface of
the software componentsthat performs a defined set of operations.
The service consumer:A service consumer can be a Web application,a
desktop-based application,or another Web service.
The service broker:It is used for locatingthe service provider and the
service that is required by a service consumer.
Introducing SOA
Service Provider Service Consumer
Service Response
Service Request
© People Strategists www.peoplestrategists.com Slide 4 of 62
The following figure displays the building blocks of SOA.
The various benefits of implementing SOA are:
It offers services across platforms.
It offers locationindependence.
It offers dynamic search and binding of services.
It is loosely coupled.
It provides flexibilityto organizationsto build applicationswithout
replacing the existing application.
Introducing SOA (Contd.)
Service Consumer
Registry
Find Register
Bind and Invoke Service Provider
© People Strategists www.peoplestrategists.com Slide 5 of 62
Identifying Web Services
What is Web
Service?
© People Strategists www.peoplestrategists.com Slide 6 of 62
Identifying Web Services (Contd.)
© People Strategists www.peoplestrategists.com Slide 7 of 62
Web services evolved from previous technologies that served the same
purpose such as RPC, ORPC (DCOM, CORBA and JAVA RMI).
Web Services were intended to solve three main problems:
Interoperability:
 Earlier distributed systems suffered from interoperability issues because each
vendor implemented its own on-wire format for distributed object messaging.
 Development of DCOM apps strictly bound to Windows Operating system.
 Development of RMI bound to Java programming language.
Firewalltraversal:
 Collaboration across corporations was an issue because distributed systems such
as CORBA and DCOM used non-standard ports.
 Web Services use HTTP as a transport protocol and most of the firewalls allow
access though port 80 (HTTP), leading to easier and dynamic collaboration.
Complexity:
 Most of the above-mentioned technologies such as RMI, COM, and CORBA
involve a whole learning curve.
 New technologies and languages have to be learnt to implement these services.
History of Web Services
© People Strategists www.peoplestrategists.com Slide 8 of 62
Identifying Web Services (Contd.)
Let us learn more
about Web
services
© People Strategists www.peoplestrategists.com Slide 9 of 62
A Web service is a collection of open protocols and standards used for
exchanging data between applications or systems.
Software applications written in various programming languages and
running on various platforms can use Web services to exchange data
over computer networks (Internet).
The following figure depicts the uses of Web services.
Identifying Web Services (Contd.)
Java
PHP
C#
Java
C#
PHP
© People Strategists www.peoplestrategists.com Slide 10 of 62
Identifying the Benefits of Web Services
Why I need Web
Services?
© People Strategists www.peoplestrategists.com Slide 11 of 62
The benefits of using Web services are:
Web services allowsyou to expose the functionalityof your existing code
over the network. Once it is exposed on the network, other application can
use the functionalityof yourprogram.
Web services allow variousapplicationsto talk to each other and share data
and services among themselves. For example, .NET applicationcan
communicateto JavaWeb services and vice versa.
Web services use standardized industry standardprotocol for the
communication.Thisstandardizationof protocolstack gives the business
many advantagessuch as a wide range of choices, reductionin the cost due
to competition,and increase in the quality.
Web services use SOAP over HTTP protocol,so you can use your existing
low-cost internet for implementing web services.
Identifying the Benefits of Web Services (Contd.)
© People Strategists www.peoplestrategists.com Slide 12 of 62
The characteristics of the Web services are:
Web services use XML to exchange messages between the service provider
and the service consumer. Using XML eliminatesany networking, operating
system, or platform binding.
Web services consumers are not tied to that Web service directly. The web
service interface can change over time without compromising the client's
abilityto interact with the service.
Web services can be synchronousor asynchronous.In synchronous
invocations,the client blocks and waits for the service to complete its
operationbefore continuing.Asynchronousclientsretrieve their result at a
laterpoint in time.
Web services allow clientsto invoke procedures, functions, and methods on
remote objects using an XML-based protocol.Remote procedures expose
input and output parameters that a web service must support.
Web services support the transparentexchange of documentsto facilitate
business integration.
Identifying the Characteristics of Web Services:
© People Strategists www.peoplestrategists.com Slide 13 of 62
Web service architecture can be viewed using the either of the way:
The first is to examine the individual rolesof each Web service actor.
The second is to examine the emerging web service protocol stack.
Web Service Roles:
Majorroles within the web service architecture are:
 Service Provider: This is the provider of the web service. The service provider
implements the service and makes it available on the Internet.
 Service Requestor: This is any consumer of the web service. The requestor
utilizes an existing web service by opening a network connection and sending an
XML request.
 Service Registry: This is a logically centralized directory of services. The registry
provides a central place where developers can publish new services or find
existing ones. It therefore serves as a centralized clearing house for companies
and their services.
Identifying Web Services Architecture
© People Strategists www.peoplestrategists.com Slide 14 of 62
Web Service Protocol Stack layer:
Service Transport:This layer is responsible for transporting messages
between applications.Currently, this layer includes Hyper Text Transport
Protocol (HTTP), Simple MailTransfer Protocol (SMTP), File Transfer Protocol
(FTP), and newer protocolssuch as Blocks Extensible Exchange Protocol
(BEEP).
XML Messaging: This layer is responsible for encoding messages in a
common XML format so that messages can be understood at either end.
Currently, this layer includes XML-RPC and SOAP.
Service Description:This layer is responsible for describing the public
interface to a specific web service. Currently, service description is handled
via the Web Service Description Language (WSDL).
Service Discovery: This layeris responsible for centralizingservices into a
common registry and providingeasy publish/findfunctionality.Currently,
service discovery is handledvia Universal Description, Discovery, and
Integration(UDDI).
Identifying Web Services Architecture (Contd.)
© People Strategists www.peoplestrategists.com Slide 15 of 62
The core platform of Web services is XML + HTTP. However, all standard
Web services work using the following components:
Identifying Web Services Component
XML-
RPC
SOAP WSDL
UDDI
© People Strategists www.peoplestrategists.com Slide 16 of 62
XML-RPC:
is a simple protocolthat uses XML messages to perform RPCs.
Requests are encoded in XML and sent via HTTP POST.
XML responses are embedded in the body of the HTTP response.
Is platform-independent.
Allows diverse applicationsto communicate.
is the easiest way to get started with web services.
Identifying Web Services Component (Contd.)
© People Strategists www.peoplestrategists.com Slide 17 of 62
SOAP:
Is an XML-based protocolfor exchanging information between computers.
Is a format for sending messages.
Is designed to communicate via Internet.
Is platform and language independent.
Is simple and extensible.
Will be developed as a W3C standard.
The following figure shows data exchange by using SOAP.
Identifying Web Services Component (Contd.)
© People Strategists www.peoplestrategists.com Slide 18 of 62
A SOAP messageconsists of the following elements:
The SOAP envelope element: Is the root element of a SOAP message. It
containsthe header and the <SOAP:BODY> element of the SOAP message.
The SOAP header element: Is an optionalpart that gives extra information
to the server and is the first descendent element of the SOAP envelope
element.
The SOAP body element: Is the compulsory part that containsthe data of
the message.
The SOAP fault element: Is used to ascertain if there is a fault in the SOAP
message and displayserrors. This element describes the following four
elements:
 <faultcode>
 <faultstring>
 <faultactor>
 <detail>
Identifying Web Services Component (Contd.)
© People Strategists www.peoplestrategists.com Slide 19 of 62
UDDI:
Standsfor Universal Description, Discovery, and Integration.
Is an XML-based standardfor describing, publishing,and finding Web
services.
Is a specificationfor a distributed registry of Web services.
Is platform independent,open framework.
Can communicate via SOAP, CORBA, and Java RMI Protocol.
Uses WSDL to describe interfaces to Web services.
UDDI is seen with SOAP and WSDL as one of the three foundation standards
of Web services.
Identifying Web Services Component (Contd.)
© People Strategists www.peoplestrategists.com Slide 20 of 62
WSDL:
Standsfor Web Services Description Language developedjointlyby
Microsoft and IBM.
Is an XML-based languagefor describing Web services and how to access
them.
Is an XML based protocolfor informationexchange in decentralized and
distributedenvironments.
Describes how to access a Web service and what operationsit will perform.
Is a language for describing how to interface with XML-based services.
Is an integral part of UDDI, an XML-based worldwide business registry.
Is the language that UDDI uses.
Identifying Web Services Component (Contd.)
© People Strategists www.peoplestrategists.com Slide 21 of 62
Exploring Web Services
How Does a Web
Service Work?
© People Strategists www.peoplestrategists.com Slide 22 of 62
Web service enables communication among various applications by
using open standards such as HTML, XML, WSDL, and SOAP. A Web
service takes the help of:
XML to tag the data
SOAP to transfer a message
WSDL to describe the availabilityof service
You can build a Java-basedWeb service on Solaris that is accessible from
your Visual Basic program that runs on Windows.
You can also use C# to build new Web services on Windows that can be
invoked from your Web application that is based on JavaServer Pages
(JSP) and runs on Linux.
Exploring Web Services (Contd.)
© People Strategists www.peoplestrategists.com Slide 23 of 62
Web services can be understand using the following example:
Exploring Web Services (Contd.)
A buyer (which might be a simple client) is ordering
goods from a seller service.
The buyer finds the seller service by searching the
UDDI directory.
The seller service is a Web Service whose interface is
defined using Web Services Description Language
(WSDL).
The buyer is invoking the order method on the seller
service using Simple Object Access Protocol (SOAP)
and the WSDL definition for the seller service.
The buyer knows what to expect in the SOAP reply
message because this is defined in the WSDL
definition for the seller service.
© People Strategists www.peoplestrategists.com Slide 24 of 62
A Web services are of the following types:
Identifying the Types of Web Services
Web
Services
BIG
Services
REST
services
© People Strategists www.peoplestrategists.com Slide 25 of 62
BIG Web services are based on SOAP standardand often contain a WSDL
to describe the interface that the web service offers.
BIG Web services includes architecture to address complex non-
functional requirements like transactions, security, addressing, trust,
coordination, and also handles asynchronous processing and invocation.
The SOAP messageformat and the WSDL interface definition language
have gained widespread adoption in traditional enterprises.
Contract details may include messages, operations, bindings, and the
location of the web service.
SOAP based Web Services is a great solution when you need,
Asynchronousprocessing
Reliability
Stateful operations
Identifying BIG Web Services
© People Strategists www.peoplestrategists.com Slide 26 of 62
REST Web services are based on an architectural style called
REST – RepresentationalState Transfer.
REST is neither a standard nor a protocol.
REST is also known as RESTful Web services. For example, client-server
architecture (client-server is neither a standardnor a protocol).
REST Web services are fast because there is no strict specification like
SOAP. It consumes less bandwidth and resource.
Identifying REST Web Services
© People Strategists www.peoplestrategists.com Slide 27 of 62
Identifying Differences Between SOAP and REST Web Services
What is the
difference between
BIG and REST Web
services
© People Strategists www.peoplestrategists.com Slide 28 of 62
The following table depicts the differences between SOAP and REST Web
services:
SOAP REST
SOAP is a protocol. REST is an architectural style.
SOAP can't use REST because it is a
protocol.
REST can use SOAP web services because it
is a concept and can use any protocol like
HTTP, SOAP.
SOAP uses services interfaces to expose
the business logic.
REST uses URI to expose business logic.
SOAP defines standards to be strictly
followed.
REST does not define too much standards
like SOAP.
SOAP requires more bandwidth and
resource than REST.
REST requires less bandwidth and resource
than SOAP.
SOAP defines its own security. RESTful web services inherits security
measures from the underlying transport.
SOAP permits XML data format only. REST permits different data format such as
Plain text, HTML, XML, JSON etc.
Identifying Differences Between SOAP and REST Web Services (Contd)
© People Strategists www.peoplestrategists.com Slide 29 of 62
JAXB stands for Java architecture for XML binding.
It is used to convert XML to java object and java object to XML.
JAXB defines an API for reading and writing Java objects to and from XML
documents.
It provides mechanism to marshal (write) Java objects into XML and
unmarshal (read) XML into object.
Simply, you can say it is used to convert Java object into xml and
vice-versa, as shown in the following figure.
Introducing to JAXB
© People Strategists www.peoplestrategists.com Slide 30 of 62
The following points depicts the feature of the JAXB:
Annotation support: JAXB 2.0 provides support to annotationso less coding
is required to develop JAXB application.The
javax.xml.bind.annotation package provides classes and
interfaces for JAXB 2.0.
Support for all W3C XML Schema features: it supports all the W3C schema
unlike JAXB 1.0.
Additional Validation Capabilities:it provides additional validationsupport
by JAXP 1.3 validationAPI.
Small Runtime Library: it required small runtime librarythat JAXB 1.0.
Reduction of generated schema-derived classes:it reduces a lot of
generated schema-derived classes.
Identifying the Features of JAXB
© People Strategists www.peoplestrategists.com Slide 31 of 62
The following figure depicts the architecture of JAXB.
JAXB Architecture
© People Strategists www.peoplestrategists.com Slide 32 of 62
Unmarshalling:
Unmarshallingprovides a client applicationthe abilityto convert XML data
into JAXB-derived Javaobjects.
Marshalling:
Marshallingprovidesa client application theabilityto convert a
JAXB-derived Javaobject tree into XML data.
Client applicationsare not required to validatethe Javacontent tree before
marshalling.
Validation:
Validationisthe process of verifying that an XML document meets all the
constraintsexpressed in the schema.
JAXB 2.0 only allowsvalidation atunmarshal and marshal time.
Identifying Key Terms used in JAXB
© People Strategists www.peoplestrategists.com Slide 33 of 62
A JAXB implementation consists of the following architectural
components:
Schema compiler:Binds a source schema to a set of schema-derived
program elements. The binding is described by an XML-based binding
language.
Schema generator: Mapsa set of existing program elements to a derived
schema. The mapping is described by program annotations.
Binding runtime framework:Provides unmarshalling(reading) and
marshalling(writing) operationsfor accessing, manipulating,and validating
XML contentusing either schema-derived or existing program elements.
JAXB Architecture (Contd.)
© People Strategists www.peoplestrategists.com Slide 34 of 62
The following figure depicts the JAXB binding process.
Identifying JAXB Binding Process
© People Strategists www.peoplestrategists.com Slide 35 of 62
The general steps in the JAXB data binding process are:
1. Generate classes:An XML schema is used as input to the JAXB binding
compiler to generate JAXB classes based on that schema.
2. Compile classes:All of the generated classes, source files, and application
code must be compiled.
3. Unmarshal:XML documentswritten according to the constraintsin the
source schema are unmarshalledby the JAXB binding framework. Note that
JAXB also supports unmarshallingXML datafrom sources other than files
and documents, such as DOM nodes, string buffers, SAX sources, and so
forth.
4. Generate content tree: The unmarshallingprocess generates a content tree
of data objects instantiated fromthe generatedJAXB classes; this content
tree represents the structure and content of the source XML documents.
Identifying JAXB Binding Process
© People Strategists www.peoplestrategists.com Slide 36 of 62
5. Validate (optional): The unmarshallingprocess involvesvalidationof the
source XML documents before generating the content tree. Note that if you
modify the content tree in Step 6, you can also use the JAXB Validate
operationto validatethe changes before marshalling the content back to
an XML document.
6. Processcontent: The client applicationcan modify the XML data
represented by the Java contenttree by using interfaces generated by the
bindingcompiler.
7. Marshal:The processed content tree is marshalledout to one or more XML
output documents. The contentmay be validated beforemarshalling.
Identifying JAXB Binding Process (Contd.)
© People Strategists www.peoplestrategists.com Slide 37 of 62
JAXB supports the grouping of generated classes in Java packages. A
package consists of the following:
A Java class name that is derived from the XML element name or specified
by a bindingcustomization.
An ObjectFactory class, which is a factory that is used to return
instances of a boundJava class.
Identifying Java Representation of XML Schema
© People Strategists www.peoplestrategists.com Slide 38 of 62
Simple Type Definitions:
A schema componentusing a simple type definitiontypicallybindsto a Java
property. Because there are different kinds of schema components, the
following Javaproperty attributes(common to the schema components)
include:
 Base type
 Collection type, if any
 Predicate
The rest of the Javaproperty attributesare specified in the schema
component using the simple type definition.
Binding XML Schemas
© People Strategists www.peoplestrategists.com Slide 39 of 62
Schema-to-Java Mapping:
The Javalanguage provides a richer set of datatypes than the XML schema.
The following table provides a mapping of XML data types to Javadata types
in JAXB.
Identifying Default Data Type Binding
XML Schema Type Java Data Type
xsd:string java.lang.String
xsd:integer java.math.BigInteger
xsd:int int
xsd.long long
xsd:short short
xsd:decimal java.math.BigDecimal
xsd:float float
xsd:double double
xsd:boolean boolean
xsd:byte byte
xsd:QName javax.xml.namespace.QName
xsd:dateTime javax.xml.datatype.XMLGregorianCalendar
© People Strategists www.peoplestrategists.com Slide 40 of 62
Java-to-Schema Mapping:
The following table shows the default mapping of Javaclasses to XML
data types.
Identifying Default Data Type Binding
Java Class XML Data Type
java.lang.String xs:string
java.math.BigInteger xs:integer
java.math.BigDecimal xs:decimal
java.util.Calendar xs:dateTime
java.util.Date xs:dateTime
javax.xml.namespace.QName xs:QName
java.net.URI xs:string
javax.xml.datatype.XMLGregorianCalendar xs:anySimpleType
javax.xml.datatype.Duration xs:duration
java.lang.Object xs:anyType
java.lang.String xs:string
java.math.BigInteger xs:integer
© People Strategists www.peoplestrategists.com Slide 41 of 62
The JAXBContext class provides the client's entry point to the JAXBAPI.
It provides an abstraction for managing the XML/Javabinding
information necessary to implement the JAXB binding framework
operations, such as: unmarshal, marshaland validate.
A client application normally obtains new instances of this class using the
following approaches:
JAXBContext.newInstance( "com.acme.foo:com.acme.bar" )
 The JAXBContext instance is initialized from a list of colon separated Java package
names. Each java package contains JAXB mapped classes, schema-derived classes
and/or user annotated classes.
JAXBContext.newInstance( com.acme.foo.Foo.class )
 The JAXBContext instance is intialized with class(es) passed as parameter(s) and
classes that are statically reachable from these class(es).
Identifying the JAXBContext Class
© People Strategists www.peoplestrategists.com Slide 42 of 62
The Marshaller class provides the client application the ability to
convert a Javacontent tree back into XML data.
There is no difference between marshalling a content tree that is
created manually using the factory methods and marshalling a content
tree that is the result an unmarshal operation.
Clients can marshal a java content tree back to XML data to a
java.io.OutputStream or a java.io.Writer.
The following code snippet illustrates how to Java objects into XML files:
Identifying the Marshaller Class
File file = new File("D:employee.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(employee, file);
jaxbMarshaller.marshal(employee, System.out);
© People Strategists www.peoplestrategists.com Slide 43 of 62
The Unmarshaller class provides the client application the ability to
convert XML data into a tree of Java content objects.
The unmarshal method allows for any global XML element declared in
the schema to be unmarshalled as the root of an instance document.
The following code snippet illustrates how to un-marshal XML files into
Javaobjects:
Identifying the Unmarshaller Class
File file = new File("d:employee.xml");
JAXBContext jaxbContext =
JAXBContext.newInstance(Employee.class);
Unmarshaller jaxbUnmarshaller =
jaxbContext.createUnmarshaller();
Employee employee = (Employee)
jaxbUnmarshaller.unmarshal(file);
© People Strategists www.peoplestrategists.com Slide 44 of 62
Problem Statement:
Consider a scenario where you need create Java applicationthat stores
employee information in xml file. For this, you decide to use JAXB that
provides mechanism to marshal (write) javaobjects into XML.
Activity: Converting Java Object into XML
Lets create Java
project using Eclipse
to solve this problem
© People Strategists www.peoplestrategists.com Slide 45 of 62
Problem Statement:
Consider a scenario where you need create Java application that read data
from XML file and store it in Javaobject. For this, you decide to use JAXB
that provides mechanism to unmarshal (read) XML into java objects.
Activity: Converting XML to Java Object
Lets solve this
problem using the
same, MarshalDemo,
project.
© People Strategists www.peoplestrategists.com Slide 46 of 62
Web services based on REST Architecture are known as RESTful web
services.
RESTful Web services use HTTP methods to implement the concept of
REST architecture.
A RESTful Web service usually defines a URI, Uniform Resource Identifier
a service, provides resource representation such as JSON and set of HTTP
Methods.
RESTful Web services can be written in any programming language and
executed in any platform.
RESTful Web services can use SOAP Web services as the implementation.
RESTful Web service permits different data format such as Plain Text,
HTML, XML and JSON.
Identifying Restful Web Services
© People Strategists www.peoplestrategists.com Slide 47 of 62
The following principles encourage RESTful applications to be simple,
lightweight, and fast:
Resourceidentification through URI: A RESTful web service exposes a set of
resources that identify the targets of the interactionwith its clients.
Resources are identifiedby URIs, which provide a globaladdressing space
for resource and service discovery.
Uniforminterface:Resources are manipulatedusing a fixed set of four
create, read, update, delete operations:PUT, GET, POST, and DELETE.
Self-descriptive messages:Resources are decoupledfrom their
representationso that their content can be accessed in a variety of formats,
such as HTML, XML, plaintext, PDF, JPEG, JSON, and others.
Stateful interactions through hyperlinks:Every interactionwith a resource
is stateless; that is, request messages are self-contained.Stateful
interactionsare based on the concept of explicitstate transfer.
Identifying Restful Web Services (Contd.)
© People Strategists www.peoplestrategists.com Slide 48 of 62
The following figure depicts the RESTful Web service architecture:
RESTful Web Service Architecture
© People Strategists www.peoplestrategists.com Slide 49 of 62
Following well known HTTP methods are commonly used in REST based
architecture.
GET: The HTTP GET method is used to retrieve (or read) a representationof
a resource.
POST: The POST verb is most-often utilized for creation of new resources. In
particular, it's used to create subordinateresources. That is, subordinateto
some other (e.g. parent) resource.
PUT: It is most-often utilized for updatecapabilities,PUT-ing to a known
resource URI with the request body containingthe newly-updated
representationof the original resource. However, PUT can also be used to
create a resource in the case where the resource ID is chosen by the client
instead of by the server.
DELETE: It is used to remove a resource identifiedby a URI.
Using HTTP Methods for RESTful Services
© People Strategists www.peoplestrategists.com Slide 50 of 62
Following table states the examples of common use of HTTP Verbs.
Using HTTP Methods for RESTful Services (Contd.)
S.N. HTTP Method, URI and Operation
1
GET
http://localhost:8080/UserManagement/rest/UserService/users
Get list of users(Read Only)
2
GET
http://localhost:8080/UserManagement/rest/UserService/users/1
Get User of Id 1 (Read Only)
3
PUT
http://localhost:8080/UserManagement/rest/UserService/users/2
InsertUser with Id 2 (Idempotent)
4
POST
http://localhost:8080/UserManagement/rest/UserService/users/2
Update User with Id 2 (N/A)
5
DELETE
http://localhost:8080/UserManagement/rest/UserService/users/1
Delete User with Id 1 (Idempotent)
6
OPTIONS
http://localhost:8080/UserManagement/rest/UserService/users
List the supported operationsin web service (Read Only)
7
HEAD
http://localhost:8080/UserManagement/rest/UserService/users
Returnsonly HTTP Header, no Body.(Read Only)
© People Strategists www.peoplestrategists.com Slide 51 of 62
JAX-RSis a Java programming language API designed to make it easy to
develop applications that use the REST architecture.
The JAX-RSAPI uses Javaprogramming language annotations to simplify
the development of RESTful web services.
Developers decorate Java programming language class files with JAX-RS
annotations to define resources and the actions that can be performed
on those resources.
JAX-RSannotations are runtime annotations; therefore, runtime
reflection will generate the helper classes and artifacts for the resource.
Introducing JAX-RS
© People Strategists www.peoplestrategists.com Slide 52 of 62
The most important annotations in JAX-RSare listed in the following
table.
Introducing JAX-RS (Contd.0
Annotation Description
@PATH(your_path) Sets the path to base URL + /your_path. The base URL is based on your
application name, the servlet and the URL pattern from
the web.xml configuration file.
@POST Indicates that the following method will answer to an HTTP POST
request.
@GET Indicates that the following method will answer to an HTTP GET request.
@PUT Indicates that the following method will answer to an HTTP PUT request.
@DELETE Indicates that the following method will answer to an HTTP DELETE
request.
@Produces(MediaType.TEXT_PLAIN[,
more-types])
@Produces defines which MIME type is delivered by a method
annotated with @GET. In the example text ("text/plain") is produced.
Other examples would be "application/xml" or "application/json".
@Consumes(type[, more-types]) @Consumes defines which MIME type is consumed by this method.
@PathParam Used to inject values from the URL into a method parameter.
© People Strategists www.peoplestrategists.com Slide 53 of 62
Jersey is the reference implementation for the JSR 311 specification.
The Jersey implementation provides a library to implement Restful Web
services in a Java servlet container.
On the server side Jersey provides a servlet implementationwhich scans
predefined classes to identify RESTful resources.
In web.xmlconfiguration file servlet is register for the Web application.
The Jersey implementation also provides a client library to communicate
with a RESTful Web service.
Jersey distribution zip file can be downloaded from the following
location:
https://jersey.java.net/download.html
or
http://www.javatpoint.com/webservicepages/download/jerseyjars.zip
Introducing Jersey
© People Strategists www.peoplestrategists.com Slide 54 of 62
Activity: Creating First RESTful Web Service
Lets see how to
create first RESTful
Web service
© People Strategists www.peoplestrategists.com Slide 55 of 62
Activity: Accessing First RESTful Web Service From Client
Lets see how to
Access first RESTful
Web service from
client
© People Strategists www.peoplestrategists.com Slide 56 of 62
The following exampleillustrates how to use @PathParam annotation:
Using JAX-RS Multiple @PathParam Annotation
package mypack.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/hello")
public class HelloService{
@GET
@Path("{year}/{month}/{day}")
public Response getDate(
@PathParam("year") int year,
@PathParam("month") int month,
@PathParam("day") int day) {
String date = year + "/" + month + "/" +
day;
return Response.status(200)
.entity("getDate is called,
year/month/day : " + date)
.build();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-
class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-
name>
<param-value> mypack.rest </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
<a href="rest/hello/2014/12/05">Click Here</a>
HelloService.java Web.xml
Index.html
© People Strategists www.peoplestrategists.com Slide 57 of 62
The following exampleillustrates how to use @FormParam and @POST
annotation:
Using JAX-RS @FormParam and @POST Annotation
package mypack.rest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
@Path("/product")
public class ProductService{
@POST
@Path("/add")
public Response addUser(
@FormParam("id") int id,
@FormParam("name") String name,
@FormParam("price") float price)
{
return Response.status(200)
.entity(" Product added
successfuly!<br> Id: "+id+"<br> Name: " +
name+"<br> Price: "+price)
.build();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-
class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-
name>
<param-value> mypack.rest </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
HelloService.java Web.xml
© People Strategists www.peoplestrategists.com Slide 58 of 62
Using JAX-RS @FormParam and @POST Annotation (Contd.)
<html>
<head>
<title>
Index page
</title>
</head>
<body>
<form action="rest/product/add"
method="post">
Enter Id:<input type="text"
name="id"/><br/><br/>
Enter Name:<input type="text"
name="name"/><br/><br/>
Enter Price:<input type="text"
name="price"/><br/><br/>
<input type="submit" value="Add Product"/>
</body>
</html>
Index.html
Input
Output
© People Strategists www.peoplestrategists.com Slide 59 of 62
SOA is a software architecture, which is essentially a collection of
services communicating with each other.
Web Service is a service that:
Is availableover the Internet or private networks
Uses a standardized XML messaging system
Is not tied to any one operating system or programming language
Web services evolved from previous technologies that served the same
purpose such as RPC, ORPC (DCOM, CORBA and JAVA RMI).
Web Services were intended to solve three main problems:
Interoperability
Firewall traversal
Complexity
A Web service is a collection of open protocols and standards used for
exchanging data between applications or systems.
Summary
© People Strategists www.peoplestrategists.com Slide 60 of 62
XML-RPC:
is a simple protocolthat uses XML messages to perform RPCs.
Requests are encoded in XML and sent via HTTP POST.
SOAP:
Is an XML-based protocolfor exchanging information between computers.
Is a format for sending messages.
UDDI:
Standsfor Universal Description, Discovery, and Integration.
Is an XML-based standardfor describing, publishing,and finding web
services.
WSDL:
Standsfor Web Services Description Language developedjointlyby
Microsoft and IBM.
Summary (Contd.)
© People Strategists www.peoplestrategists.com Slide 61 of 62
BIG Web services are based on SOAP standardand often contain a WSDL
to describe the interface that the web service offers.
REST Web services are based on an architectural style called
REST – RepresentationalState Transfer.
JAXB stands for Java architecture for XML binding.
JAXB defines an API for reading and writing Javaobjects to and from XML
documents.
Unmarshalling provides a client application the ability to convert XML
data into JAXB-derived Javaobjects.
Marshalling provides a client application the ability to convert a
JAXB-derived Java object tree into XML data.
Validation is the process of verifying that an XML document meets all the
constraints expressed in the schema.
Summary (Contd.)
© People Strategists www.peoplestrategists.com Slide 62 of 62
The JAXBContext class provides the client's entry point to the JAXB API.
The Marshaller class provides the client application the ability to
convert a Java content tree back into XML data.
The Unmarshaller class provides the client application the ability to
convert XML data into a tree of Java content objects.
Web services based on REST Architecture are known as RESTful web
services.
RESTful Web services use HTTP methods to implement the concept of
REST architecture.
JAX-RSis a Java programming language API designed to make it easy to
develop applications that use the REST architecture.
The JAX-RSAPI uses Javaprogramming language annotations to simplify
the development of RESTful web services.
Jersey is the reference implementation for the JSR 311 specification.
Summary (Contd.)

Más contenido relacionado

La actualidad más candente (20)

Top web development tools
Top web development toolsTop web development tools
Top web development tools
 
Web services and SOA
Web services and SOAWeb services and SOA
Web services and SOA
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
 
hosting.ppt
hosting.ppthosting.ppt
hosting.ppt
 
Lecture 7: Server side programming
Lecture 7: Server side programmingLecture 7: Server side programming
Lecture 7: Server side programming
 
Web programming PHP BCA 313
Web programming PHP BCA 313Web programming PHP BCA 313
Web programming PHP BCA 313
 
Serverless Web Apps using API Gateway, Lambda and DynamoDB
Serverless Web Apps using API Gateway, Lambda and DynamoDBServerless Web Apps using API Gateway, Lambda and DynamoDB
Serverless Web Apps using API Gateway, Lambda and DynamoDB
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
C# REST API
C# REST APIC# REST API
C# REST API
 
Database connectivity in asp.net
Database connectivity in asp.netDatabase connectivity in asp.net
Database connectivity in asp.net
 
Server Side VS Client Side
Server Side VS Client SideServer Side VS Client Side
Server Side VS Client Side
 
Basics of the Web Platform
Basics of the Web PlatformBasics of the Web Platform
Basics of the Web Platform
 
Apache web service
Apache web serviceApache web service
Apache web service
 
Webservices
WebservicesWebservices
Webservices
 
Soap and restful webservice
Soap and restful webserviceSoap and restful webservice
Soap and restful webservice
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
Dynamic Web
Dynamic WebDynamic Web
Dynamic Web
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Web Services ppt
Web Services pptWeb Services ppt
Web Services ppt
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 

Destacado

Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSKatrien Verbert
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA psrpatnaik
 
Utsav Mahendra : Managing People for Service Advantage
Utsav Mahendra : Managing People  for Service Advantage  Utsav Mahendra : Managing People  for Service Advantage
Utsav Mahendra : Managing People for Service Advantage Utsav Mahendra
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 
Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Dmytro Chyzhykov
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web ServicesAngelin R
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentationguest0df6b0
 
Testing web services
Testing web servicesTesting web services
Testing web servicesTaras Lytvyn
 

Destacado (16)

Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RS
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Web services
Web servicesWeb services
Web services
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA
 
Utsav Mahendra : Managing People for Service Advantage
Utsav Mahendra : Managing People  for Service Advantage  Utsav Mahendra : Managing People  for Service Advantage
Utsav Mahendra : Managing People for Service Advantage
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 
Web servers
Web serversWeb servers
Web servers
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentation
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Testing web services
Testing web servicesTesting web services
Testing web services
 

Similar a Overview of web services

WebService-Java
WebService-JavaWebService-Java
WebService-Javahalwal
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architectureYisal Khan
 
Service Oriented Architecture Updated Luqman
Service Oriented Architecture Updated  LuqmanService Oriented Architecture Updated  Luqman
Service Oriented Architecture Updated Luqmanguesteb791b
 
Web Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NETWeb Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NETPonraj
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaJignesh Aakoliya
 
Cloud computing 20 service modelling
Cloud computing 20 service modellingCloud computing 20 service modelling
Cloud computing 20 service modellingVaibhav Khanna
 
Advantage of WCF Over Web Services
Advantage of WCF Over Web ServicesAdvantage of WCF Over Web Services
Advantage of WCF Over Web ServicesSiva Tharun Kola
 
Web programming
Web programmingWeb programming
Web programmingsowfi
 
Sreerag what is a web service
Sreerag   what is a web serviceSreerag   what is a web service
Sreerag what is a web serviceSreerag Gopinath
 
Web services concepts, protocols and development
Web services concepts, protocols and developmentWeb services concepts, protocols and development
Web services concepts, protocols and developmentishmecse13
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologiesssuser3a47cb
 
Introduction to webservices
Introduction to webservicesIntroduction to webservices
Introduction to webservicesGagandeep Singh
 
Anatomy Of A Web Service
Anatomy Of A Web ServiceAnatomy Of A Web Service
Anatomy Of A Web Servicekchavd01
 

Similar a Overview of web services (20)

Web services
Web servicesWeb services
Web services
 
Java web services
Java web servicesJava web services
Java web services
 
Web services
Web servicesWeb services
Web services
 
WebService-Java
WebService-JavaWebService-Java
WebService-Java
 
Service view
Service viewService view
Service view
 
Cc unit 2 updated
Cc unit 2 updatedCc unit 2 updated
Cc unit 2 updated
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 
Service Oriented Architecture Updated Luqman
Service Oriented Architecture Updated  LuqmanService Oriented Architecture Updated  Luqman
Service Oriented Architecture Updated Luqman
 
Web Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NETWeb Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NET
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company india
 
Cloud computing 20 service modelling
Cloud computing 20 service modellingCloud computing 20 service modelling
Cloud computing 20 service modelling
 
Web Programming
Web ProgrammingWeb Programming
Web Programming
 
Advantage of WCF Over Web Services
Advantage of WCF Over Web ServicesAdvantage of WCF Over Web Services
Advantage of WCF Over Web Services
 
Web programming
Web programmingWeb programming
Web programming
 
Sreerag what is a web service
Sreerag   what is a web serviceSreerag   what is a web service
Sreerag what is a web service
 
Web services concepts, protocols and development
Web services concepts, protocols and developmentWeb services concepts, protocols and development
Web services concepts, protocols and development
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologies
 
Introduction to webservices
Introduction to webservicesIntroduction to webservices
Introduction to webservices
 
Anatomy Of A Web Service
Anatomy Of A Web ServiceAnatomy Of A Web Service
Anatomy Of A Web Service
 
SOA & WCF
SOA & WCFSOA & WCF
SOA & WCF
 

Más de People Strategists (20)

MongoDB Session 3
MongoDB Session 3MongoDB Session 3
MongoDB Session 3
 
MongoDB Session 2
MongoDB Session 2MongoDB Session 2
MongoDB Session 2
 
MongoDB Session 1
MongoDB Session 1MongoDB Session 1
MongoDB Session 1
 
Android - Day 1
Android - Day 1Android - Day 1
Android - Day 1
 
Android - Day 2
Android - Day 2Android - Day 2
Android - Day 2
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
 
Hibernate II
Hibernate IIHibernate II
Hibernate II
 
Hibernate III
Hibernate IIIHibernate III
Hibernate III
 
Hibernate I
Hibernate IHibernate I
Hibernate I
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
Agile Dev. II
Agile Dev. IIAgile Dev. II
Agile Dev. II
 
Agile Dev. I
Agile Dev. IAgile Dev. I
Agile Dev. I
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Overview of web services

  • 1. © People Strategists www.peoplestrategists.com Slide 1 of 62 Overview Web Service
  • 2. © People Strategists www.peoplestrategists.com Slide 2 of 62 In this session, you will learn to: Identify SOA Identify to Web services Identify JAXB Identify RESTful Objectives
  • 3. © People Strategists www.peoplestrategists.com Slide 3 of 62 SOA is a software architecture, which is essentially a collection of services communicating with each other. The SOA concept is implemented by using Web services. The following figure shows a basic SOA. SOA architecture is based on the following building blocks: The service provider:These componentsprovideaccess to the interface of the software componentsthat performs a defined set of operations. The service consumer:A service consumer can be a Web application,a desktop-based application,or another Web service. The service broker:It is used for locatingthe service provider and the service that is required by a service consumer. Introducing SOA Service Provider Service Consumer Service Response Service Request
  • 4. © People Strategists www.peoplestrategists.com Slide 4 of 62 The following figure displays the building blocks of SOA. The various benefits of implementing SOA are: It offers services across platforms. It offers locationindependence. It offers dynamic search and binding of services. It is loosely coupled. It provides flexibilityto organizationsto build applicationswithout replacing the existing application. Introducing SOA (Contd.) Service Consumer Registry Find Register Bind and Invoke Service Provider
  • 5. © People Strategists www.peoplestrategists.com Slide 5 of 62 Identifying Web Services What is Web Service?
  • 6. © People Strategists www.peoplestrategists.com Slide 6 of 62 Identifying Web Services (Contd.)
  • 7. © People Strategists www.peoplestrategists.com Slide 7 of 62 Web services evolved from previous technologies that served the same purpose such as RPC, ORPC (DCOM, CORBA and JAVA RMI). Web Services were intended to solve three main problems: Interoperability:  Earlier distributed systems suffered from interoperability issues because each vendor implemented its own on-wire format for distributed object messaging.  Development of DCOM apps strictly bound to Windows Operating system.  Development of RMI bound to Java programming language. Firewalltraversal:  Collaboration across corporations was an issue because distributed systems such as CORBA and DCOM used non-standard ports.  Web Services use HTTP as a transport protocol and most of the firewalls allow access though port 80 (HTTP), leading to easier and dynamic collaboration. Complexity:  Most of the above-mentioned technologies such as RMI, COM, and CORBA involve a whole learning curve.  New technologies and languages have to be learnt to implement these services. History of Web Services
  • 8. © People Strategists www.peoplestrategists.com Slide 8 of 62 Identifying Web Services (Contd.) Let us learn more about Web services
  • 9. © People Strategists www.peoplestrategists.com Slide 9 of 62 A Web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use Web services to exchange data over computer networks (Internet). The following figure depicts the uses of Web services. Identifying Web Services (Contd.) Java PHP C# Java C# PHP
  • 10. © People Strategists www.peoplestrategists.com Slide 10 of 62 Identifying the Benefits of Web Services Why I need Web Services?
  • 11. © People Strategists www.peoplestrategists.com Slide 11 of 62 The benefits of using Web services are: Web services allowsyou to expose the functionalityof your existing code over the network. Once it is exposed on the network, other application can use the functionalityof yourprogram. Web services allow variousapplicationsto talk to each other and share data and services among themselves. For example, .NET applicationcan communicateto JavaWeb services and vice versa. Web services use standardized industry standardprotocol for the communication.Thisstandardizationof protocolstack gives the business many advantagessuch as a wide range of choices, reductionin the cost due to competition,and increase in the quality. Web services use SOAP over HTTP protocol,so you can use your existing low-cost internet for implementing web services. Identifying the Benefits of Web Services (Contd.)
  • 12. © People Strategists www.peoplestrategists.com Slide 12 of 62 The characteristics of the Web services are: Web services use XML to exchange messages between the service provider and the service consumer. Using XML eliminatesany networking, operating system, or platform binding. Web services consumers are not tied to that Web service directly. The web service interface can change over time without compromising the client's abilityto interact with the service. Web services can be synchronousor asynchronous.In synchronous invocations,the client blocks and waits for the service to complete its operationbefore continuing.Asynchronousclientsretrieve their result at a laterpoint in time. Web services allow clientsto invoke procedures, functions, and methods on remote objects using an XML-based protocol.Remote procedures expose input and output parameters that a web service must support. Web services support the transparentexchange of documentsto facilitate business integration. Identifying the Characteristics of Web Services:
  • 13. © People Strategists www.peoplestrategists.com Slide 13 of 62 Web service architecture can be viewed using the either of the way: The first is to examine the individual rolesof each Web service actor. The second is to examine the emerging web service protocol stack. Web Service Roles: Majorroles within the web service architecture are:  Service Provider: This is the provider of the web service. The service provider implements the service and makes it available on the Internet.  Service Requestor: This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request.  Service Registry: This is a logically centralized directory of services. The registry provides a central place where developers can publish new services or find existing ones. It therefore serves as a centralized clearing house for companies and their services. Identifying Web Services Architecture
  • 14. © People Strategists www.peoplestrategists.com Slide 14 of 62 Web Service Protocol Stack layer: Service Transport:This layer is responsible for transporting messages between applications.Currently, this layer includes Hyper Text Transport Protocol (HTTP), Simple MailTransfer Protocol (SMTP), File Transfer Protocol (FTP), and newer protocolssuch as Blocks Extensible Exchange Protocol (BEEP). XML Messaging: This layer is responsible for encoding messages in a common XML format so that messages can be understood at either end. Currently, this layer includes XML-RPC and SOAP. Service Description:This layer is responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). Service Discovery: This layeris responsible for centralizingservices into a common registry and providingeasy publish/findfunctionality.Currently, service discovery is handledvia Universal Description, Discovery, and Integration(UDDI). Identifying Web Services Architecture (Contd.)
  • 15. © People Strategists www.peoplestrategists.com Slide 15 of 62 The core platform of Web services is XML + HTTP. However, all standard Web services work using the following components: Identifying Web Services Component XML- RPC SOAP WSDL UDDI
  • 16. © People Strategists www.peoplestrategists.com Slide 16 of 62 XML-RPC: is a simple protocolthat uses XML messages to perform RPCs. Requests are encoded in XML and sent via HTTP POST. XML responses are embedded in the body of the HTTP response. Is platform-independent. Allows diverse applicationsto communicate. is the easiest way to get started with web services. Identifying Web Services Component (Contd.)
  • 17. © People Strategists www.peoplestrategists.com Slide 17 of 62 SOAP: Is an XML-based protocolfor exchanging information between computers. Is a format for sending messages. Is designed to communicate via Internet. Is platform and language independent. Is simple and extensible. Will be developed as a W3C standard. The following figure shows data exchange by using SOAP. Identifying Web Services Component (Contd.)
  • 18. © People Strategists www.peoplestrategists.com Slide 18 of 62 A SOAP messageconsists of the following elements: The SOAP envelope element: Is the root element of a SOAP message. It containsthe header and the <SOAP:BODY> element of the SOAP message. The SOAP header element: Is an optionalpart that gives extra information to the server and is the first descendent element of the SOAP envelope element. The SOAP body element: Is the compulsory part that containsthe data of the message. The SOAP fault element: Is used to ascertain if there is a fault in the SOAP message and displayserrors. This element describes the following four elements:  <faultcode>  <faultstring>  <faultactor>  <detail> Identifying Web Services Component (Contd.)
  • 19. © People Strategists www.peoplestrategists.com Slide 19 of 62 UDDI: Standsfor Universal Description, Discovery, and Integration. Is an XML-based standardfor describing, publishing,and finding Web services. Is a specificationfor a distributed registry of Web services. Is platform independent,open framework. Can communicate via SOAP, CORBA, and Java RMI Protocol. Uses WSDL to describe interfaces to Web services. UDDI is seen with SOAP and WSDL as one of the three foundation standards of Web services. Identifying Web Services Component (Contd.)
  • 20. © People Strategists www.peoplestrategists.com Slide 20 of 62 WSDL: Standsfor Web Services Description Language developedjointlyby Microsoft and IBM. Is an XML-based languagefor describing Web services and how to access them. Is an XML based protocolfor informationexchange in decentralized and distributedenvironments. Describes how to access a Web service and what operationsit will perform. Is a language for describing how to interface with XML-based services. Is an integral part of UDDI, an XML-based worldwide business registry. Is the language that UDDI uses. Identifying Web Services Component (Contd.)
  • 21. © People Strategists www.peoplestrategists.com Slide 21 of 62 Exploring Web Services How Does a Web Service Work?
  • 22. © People Strategists www.peoplestrategists.com Slide 22 of 62 Web service enables communication among various applications by using open standards such as HTML, XML, WSDL, and SOAP. A Web service takes the help of: XML to tag the data SOAP to transfer a message WSDL to describe the availabilityof service You can build a Java-basedWeb service on Solaris that is accessible from your Visual Basic program that runs on Windows. You can also use C# to build new Web services on Windows that can be invoked from your Web application that is based on JavaServer Pages (JSP) and runs on Linux. Exploring Web Services (Contd.)
  • 23. © People Strategists www.peoplestrategists.com Slide 23 of 62 Web services can be understand using the following example: Exploring Web Services (Contd.) A buyer (which might be a simple client) is ordering goods from a seller service. The buyer finds the seller service by searching the UDDI directory. The seller service is a Web Service whose interface is defined using Web Services Description Language (WSDL). The buyer is invoking the order method on the seller service using Simple Object Access Protocol (SOAP) and the WSDL definition for the seller service. The buyer knows what to expect in the SOAP reply message because this is defined in the WSDL definition for the seller service.
  • 24. © People Strategists www.peoplestrategists.com Slide 24 of 62 A Web services are of the following types: Identifying the Types of Web Services Web Services BIG Services REST services
  • 25. © People Strategists www.peoplestrategists.com Slide 25 of 62 BIG Web services are based on SOAP standardand often contain a WSDL to describe the interface that the web service offers. BIG Web services includes architecture to address complex non- functional requirements like transactions, security, addressing, trust, coordination, and also handles asynchronous processing and invocation. The SOAP messageformat and the WSDL interface definition language have gained widespread adoption in traditional enterprises. Contract details may include messages, operations, bindings, and the location of the web service. SOAP based Web Services is a great solution when you need, Asynchronousprocessing Reliability Stateful operations Identifying BIG Web Services
  • 26. © People Strategists www.peoplestrategists.com Slide 26 of 62 REST Web services are based on an architectural style called REST – RepresentationalState Transfer. REST is neither a standard nor a protocol. REST is also known as RESTful Web services. For example, client-server architecture (client-server is neither a standardnor a protocol). REST Web services are fast because there is no strict specification like SOAP. It consumes less bandwidth and resource. Identifying REST Web Services
  • 27. © People Strategists www.peoplestrategists.com Slide 27 of 62 Identifying Differences Between SOAP and REST Web Services What is the difference between BIG and REST Web services
  • 28. © People Strategists www.peoplestrategists.com Slide 28 of 62 The following table depicts the differences between SOAP and REST Web services: SOAP REST SOAP is a protocol. REST is an architectural style. SOAP can't use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP. SOAP uses services interfaces to expose the business logic. REST uses URI to expose business logic. SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP. SOAP requires more bandwidth and resource than REST. REST requires less bandwidth and resource than SOAP. SOAP defines its own security. RESTful web services inherits security measures from the underlying transport. SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc. Identifying Differences Between SOAP and REST Web Services (Contd)
  • 29. © People Strategists www.peoplestrategists.com Slide 29 of 62 JAXB stands for Java architecture for XML binding. It is used to convert XML to java object and java object to XML. JAXB defines an API for reading and writing Java objects to and from XML documents. It provides mechanism to marshal (write) Java objects into XML and unmarshal (read) XML into object. Simply, you can say it is used to convert Java object into xml and vice-versa, as shown in the following figure. Introducing to JAXB
  • 30. © People Strategists www.peoplestrategists.com Slide 30 of 62 The following points depicts the feature of the JAXB: Annotation support: JAXB 2.0 provides support to annotationso less coding is required to develop JAXB application.The javax.xml.bind.annotation package provides classes and interfaces for JAXB 2.0. Support for all W3C XML Schema features: it supports all the W3C schema unlike JAXB 1.0. Additional Validation Capabilities:it provides additional validationsupport by JAXP 1.3 validationAPI. Small Runtime Library: it required small runtime librarythat JAXB 1.0. Reduction of generated schema-derived classes:it reduces a lot of generated schema-derived classes. Identifying the Features of JAXB
  • 31. © People Strategists www.peoplestrategists.com Slide 31 of 62 The following figure depicts the architecture of JAXB. JAXB Architecture
  • 32. © People Strategists www.peoplestrategists.com Slide 32 of 62 Unmarshalling: Unmarshallingprovides a client applicationthe abilityto convert XML data into JAXB-derived Javaobjects. Marshalling: Marshallingprovidesa client application theabilityto convert a JAXB-derived Javaobject tree into XML data. Client applicationsare not required to validatethe Javacontent tree before marshalling. Validation: Validationisthe process of verifying that an XML document meets all the constraintsexpressed in the schema. JAXB 2.0 only allowsvalidation atunmarshal and marshal time. Identifying Key Terms used in JAXB
  • 33. © People Strategists www.peoplestrategists.com Slide 33 of 62 A JAXB implementation consists of the following architectural components: Schema compiler:Binds a source schema to a set of schema-derived program elements. The binding is described by an XML-based binding language. Schema generator: Mapsa set of existing program elements to a derived schema. The mapping is described by program annotations. Binding runtime framework:Provides unmarshalling(reading) and marshalling(writing) operationsfor accessing, manipulating,and validating XML contentusing either schema-derived or existing program elements. JAXB Architecture (Contd.)
  • 34. © People Strategists www.peoplestrategists.com Slide 34 of 62 The following figure depicts the JAXB binding process. Identifying JAXB Binding Process
  • 35. © People Strategists www.peoplestrategists.com Slide 35 of 62 The general steps in the JAXB data binding process are: 1. Generate classes:An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema. 2. Compile classes:All of the generated classes, source files, and application code must be compiled. 3. Unmarshal:XML documentswritten according to the constraintsin the source schema are unmarshalledby the JAXB binding framework. Note that JAXB also supports unmarshallingXML datafrom sources other than files and documents, such as DOM nodes, string buffers, SAX sources, and so forth. 4. Generate content tree: The unmarshallingprocess generates a content tree of data objects instantiated fromthe generatedJAXB classes; this content tree represents the structure and content of the source XML documents. Identifying JAXB Binding Process
  • 36. © People Strategists www.peoplestrategists.com Slide 36 of 62 5. Validate (optional): The unmarshallingprocess involvesvalidationof the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, you can also use the JAXB Validate operationto validatethe changes before marshalling the content back to an XML document. 6. Processcontent: The client applicationcan modify the XML data represented by the Java contenttree by using interfaces generated by the bindingcompiler. 7. Marshal:The processed content tree is marshalledout to one or more XML output documents. The contentmay be validated beforemarshalling. Identifying JAXB Binding Process (Contd.)
  • 37. © People Strategists www.peoplestrategists.com Slide 37 of 62 JAXB supports the grouping of generated classes in Java packages. A package consists of the following: A Java class name that is derived from the XML element name or specified by a bindingcustomization. An ObjectFactory class, which is a factory that is used to return instances of a boundJava class. Identifying Java Representation of XML Schema
  • 38. © People Strategists www.peoplestrategists.com Slide 38 of 62 Simple Type Definitions: A schema componentusing a simple type definitiontypicallybindsto a Java property. Because there are different kinds of schema components, the following Javaproperty attributes(common to the schema components) include:  Base type  Collection type, if any  Predicate The rest of the Javaproperty attributesare specified in the schema component using the simple type definition. Binding XML Schemas
  • 39. © People Strategists www.peoplestrategists.com Slide 39 of 62 Schema-to-Java Mapping: The Javalanguage provides a richer set of datatypes than the XML schema. The following table provides a mapping of XML data types to Javadata types in JAXB. Identifying Default Data Type Binding XML Schema Type Java Data Type xsd:string java.lang.String xsd:integer java.math.BigInteger xsd:int int xsd.long long xsd:short short xsd:decimal java.math.BigDecimal xsd:float float xsd:double double xsd:boolean boolean xsd:byte byte xsd:QName javax.xml.namespace.QName xsd:dateTime javax.xml.datatype.XMLGregorianCalendar
  • 40. © People Strategists www.peoplestrategists.com Slide 40 of 62 Java-to-Schema Mapping: The following table shows the default mapping of Javaclasses to XML data types. Identifying Default Data Type Binding Java Class XML Data Type java.lang.String xs:string java.math.BigInteger xs:integer java.math.BigDecimal xs:decimal java.util.Calendar xs:dateTime java.util.Date xs:dateTime javax.xml.namespace.QName xs:QName java.net.URI xs:string javax.xml.datatype.XMLGregorianCalendar xs:anySimpleType javax.xml.datatype.Duration xs:duration java.lang.Object xs:anyType java.lang.String xs:string java.math.BigInteger xs:integer
  • 41. © People Strategists www.peoplestrategists.com Slide 41 of 62 The JAXBContext class provides the client's entry point to the JAXBAPI. It provides an abstraction for managing the XML/Javabinding information necessary to implement the JAXB binding framework operations, such as: unmarshal, marshaland validate. A client application normally obtains new instances of this class using the following approaches: JAXBContext.newInstance( "com.acme.foo:com.acme.bar" )  The JAXBContext instance is initialized from a list of colon separated Java package names. Each java package contains JAXB mapped classes, schema-derived classes and/or user annotated classes. JAXBContext.newInstance( com.acme.foo.Foo.class )  The JAXBContext instance is intialized with class(es) passed as parameter(s) and classes that are statically reachable from these class(es). Identifying the JAXBContext Class
  • 42. © People Strategists www.peoplestrategists.com Slide 42 of 62 The Marshaller class provides the client application the ability to convert a Javacontent tree back into XML data. There is no difference between marshalling a content tree that is created manually using the factory methods and marshalling a content tree that is the result an unmarshal operation. Clients can marshal a java content tree back to XML data to a java.io.OutputStream or a java.io.Writer. The following code snippet illustrates how to Java objects into XML files: Identifying the Marshaller Class File file = new File("D:employee.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(employee, file); jaxbMarshaller.marshal(employee, System.out);
  • 43. © People Strategists www.peoplestrategists.com Slide 43 of 62 The Unmarshaller class provides the client application the ability to convert XML data into a tree of Java content objects. The unmarshal method allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document. The following code snippet illustrates how to un-marshal XML files into Javaobjects: Identifying the Unmarshaller Class File file = new File("d:employee.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Employee employee = (Employee) jaxbUnmarshaller.unmarshal(file);
  • 44. © People Strategists www.peoplestrategists.com Slide 44 of 62 Problem Statement: Consider a scenario where you need create Java applicationthat stores employee information in xml file. For this, you decide to use JAXB that provides mechanism to marshal (write) javaobjects into XML. Activity: Converting Java Object into XML Lets create Java project using Eclipse to solve this problem
  • 45. © People Strategists www.peoplestrategists.com Slide 45 of 62 Problem Statement: Consider a scenario where you need create Java application that read data from XML file and store it in Javaobject. For this, you decide to use JAXB that provides mechanism to unmarshal (read) XML into java objects. Activity: Converting XML to Java Object Lets solve this problem using the same, MarshalDemo, project.
  • 46. © People Strategists www.peoplestrategists.com Slide 46 of 62 Web services based on REST Architecture are known as RESTful web services. RESTful Web services use HTTP methods to implement the concept of REST architecture. A RESTful Web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods. RESTful Web services can be written in any programming language and executed in any platform. RESTful Web services can use SOAP Web services as the implementation. RESTful Web service permits different data format such as Plain Text, HTML, XML and JSON. Identifying Restful Web Services
  • 47. © People Strategists www.peoplestrategists.com Slide 47 of 62 The following principles encourage RESTful applications to be simple, lightweight, and fast: Resourceidentification through URI: A RESTful web service exposes a set of resources that identify the targets of the interactionwith its clients. Resources are identifiedby URIs, which provide a globaladdressing space for resource and service discovery. Uniforminterface:Resources are manipulatedusing a fixed set of four create, read, update, delete operations:PUT, GET, POST, and DELETE. Self-descriptive messages:Resources are decoupledfrom their representationso that their content can be accessed in a variety of formats, such as HTML, XML, plaintext, PDF, JPEG, JSON, and others. Stateful interactions through hyperlinks:Every interactionwith a resource is stateless; that is, request messages are self-contained.Stateful interactionsare based on the concept of explicitstate transfer. Identifying Restful Web Services (Contd.)
  • 48. © People Strategists www.peoplestrategists.com Slide 48 of 62 The following figure depicts the RESTful Web service architecture: RESTful Web Service Architecture
  • 49. © People Strategists www.peoplestrategists.com Slide 49 of 62 Following well known HTTP methods are commonly used in REST based architecture. GET: The HTTP GET method is used to retrieve (or read) a representationof a resource. POST: The POST verb is most-often utilized for creation of new resources. In particular, it's used to create subordinateresources. That is, subordinateto some other (e.g. parent) resource. PUT: It is most-often utilized for updatecapabilities,PUT-ing to a known resource URI with the request body containingthe newly-updated representationof the original resource. However, PUT can also be used to create a resource in the case where the resource ID is chosen by the client instead of by the server. DELETE: It is used to remove a resource identifiedby a URI. Using HTTP Methods for RESTful Services
  • 50. © People Strategists www.peoplestrategists.com Slide 50 of 62 Following table states the examples of common use of HTTP Verbs. Using HTTP Methods for RESTful Services (Contd.) S.N. HTTP Method, URI and Operation 1 GET http://localhost:8080/UserManagement/rest/UserService/users Get list of users(Read Only) 2 GET http://localhost:8080/UserManagement/rest/UserService/users/1 Get User of Id 1 (Read Only) 3 PUT http://localhost:8080/UserManagement/rest/UserService/users/2 InsertUser with Id 2 (Idempotent) 4 POST http://localhost:8080/UserManagement/rest/UserService/users/2 Update User with Id 2 (N/A) 5 DELETE http://localhost:8080/UserManagement/rest/UserService/users/1 Delete User with Id 1 (Idempotent) 6 OPTIONS http://localhost:8080/UserManagement/rest/UserService/users List the supported operationsin web service (Read Only) 7 HEAD http://localhost:8080/UserManagement/rest/UserService/users Returnsonly HTTP Header, no Body.(Read Only)
  • 51. © People Strategists www.peoplestrategists.com Slide 51 of 62 JAX-RSis a Java programming language API designed to make it easy to develop applications that use the REST architecture. The JAX-RSAPI uses Javaprogramming language annotations to simplify the development of RESTful web services. Developers decorate Java programming language class files with JAX-RS annotations to define resources and the actions that can be performed on those resources. JAX-RSannotations are runtime annotations; therefore, runtime reflection will generate the helper classes and artifacts for the resource. Introducing JAX-RS
  • 52. © People Strategists www.peoplestrategists.com Slide 52 of 62 The most important annotations in JAX-RSare listed in the following table. Introducing JAX-RS (Contd.0 Annotation Description @PATH(your_path) Sets the path to base URL + /your_path. The base URL is based on your application name, the servlet and the URL pattern from the web.xml configuration file. @POST Indicates that the following method will answer to an HTTP POST request. @GET Indicates that the following method will answer to an HTTP GET request. @PUT Indicates that the following method will answer to an HTTP PUT request. @DELETE Indicates that the following method will answer to an HTTP DELETE request. @Produces(MediaType.TEXT_PLAIN[, more-types]) @Produces defines which MIME type is delivered by a method annotated with @GET. In the example text ("text/plain") is produced. Other examples would be "application/xml" or "application/json". @Consumes(type[, more-types]) @Consumes defines which MIME type is consumed by this method. @PathParam Used to inject values from the URL into a method parameter.
  • 53. © People Strategists www.peoplestrategists.com Slide 53 of 62 Jersey is the reference implementation for the JSR 311 specification. The Jersey implementation provides a library to implement Restful Web services in a Java servlet container. On the server side Jersey provides a servlet implementationwhich scans predefined classes to identify RESTful resources. In web.xmlconfiguration file servlet is register for the Web application. The Jersey implementation also provides a client library to communicate with a RESTful Web service. Jersey distribution zip file can be downloaded from the following location: https://jersey.java.net/download.html or http://www.javatpoint.com/webservicepages/download/jerseyjars.zip Introducing Jersey
  • 54. © People Strategists www.peoplestrategists.com Slide 54 of 62 Activity: Creating First RESTful Web Service Lets see how to create first RESTful Web service
  • 55. © People Strategists www.peoplestrategists.com Slide 55 of 62 Activity: Accessing First RESTful Web Service From Client Lets see how to Access first RESTful Web service from client
  • 56. © People Strategists www.peoplestrategists.com Slide 56 of 62 The following exampleillustrates how to use @PathParam annotation: Using JAX-RS Multiple @PathParam Annotation package mypack.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; @Path("/hello") public class HelloService{ @GET @Path("{year}/{month}/{day}") public Response getDate( @PathParam("year") int year, @PathParam("month") int month, @PathParam("day") int day) { String date = year + "/" + month + "/" + day; return Response.status(200) .entity("getDate is called, year/month/day : " + date) .build(); } } <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet- class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param- name> <param-value> mypack.rest </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> <a href="rest/hello/2014/12/05">Click Here</a> HelloService.java Web.xml Index.html
  • 57. © People Strategists www.peoplestrategists.com Slide 57 of 62 The following exampleillustrates how to use @FormParam and @POST annotation: Using JAX-RS @FormParam and @POST Annotation package mypack.rest; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.Response; @Path("/product") public class ProductService{ @POST @Path("/add") public Response addUser( @FormParam("id") int id, @FormParam("name") String name, @FormParam("price") float price) { return Response.status(200) .entity(" Product added successfuly!<br> Id: "+id+"<br> Name: " + name+"<br> Price: "+price) .build(); } } <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet- class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param- name> <param-value> mypack.rest </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> HelloService.java Web.xml
  • 58. © People Strategists www.peoplestrategists.com Slide 58 of 62 Using JAX-RS @FormParam and @POST Annotation (Contd.) <html> <head> <title> Index page </title> </head> <body> <form action="rest/product/add" method="post"> Enter Id:<input type="text" name="id"/><br/><br/> Enter Name:<input type="text" name="name"/><br/><br/> Enter Price:<input type="text" name="price"/><br/><br/> <input type="submit" value="Add Product"/> </body> </html> Index.html Input Output
  • 59. © People Strategists www.peoplestrategists.com Slide 59 of 62 SOA is a software architecture, which is essentially a collection of services communicating with each other. Web Service is a service that: Is availableover the Internet or private networks Uses a standardized XML messaging system Is not tied to any one operating system or programming language Web services evolved from previous technologies that served the same purpose such as RPC, ORPC (DCOM, CORBA and JAVA RMI). Web Services were intended to solve three main problems: Interoperability Firewall traversal Complexity A Web service is a collection of open protocols and standards used for exchanging data between applications or systems. Summary
  • 60. © People Strategists www.peoplestrategists.com Slide 60 of 62 XML-RPC: is a simple protocolthat uses XML messages to perform RPCs. Requests are encoded in XML and sent via HTTP POST. SOAP: Is an XML-based protocolfor exchanging information between computers. Is a format for sending messages. UDDI: Standsfor Universal Description, Discovery, and Integration. Is an XML-based standardfor describing, publishing,and finding web services. WSDL: Standsfor Web Services Description Language developedjointlyby Microsoft and IBM. Summary (Contd.)
  • 61. © People Strategists www.peoplestrategists.com Slide 61 of 62 BIG Web services are based on SOAP standardand often contain a WSDL to describe the interface that the web service offers. REST Web services are based on an architectural style called REST – RepresentationalState Transfer. JAXB stands for Java architecture for XML binding. JAXB defines an API for reading and writing Javaobjects to and from XML documents. Unmarshalling provides a client application the ability to convert XML data into JAXB-derived Javaobjects. Marshalling provides a client application the ability to convert a JAXB-derived Java object tree into XML data. Validation is the process of verifying that an XML document meets all the constraints expressed in the schema. Summary (Contd.)
  • 62. © People Strategists www.peoplestrategists.com Slide 62 of 62 The JAXBContext class provides the client's entry point to the JAXB API. The Marshaller class provides the client application the ability to convert a Java content tree back into XML data. The Unmarshaller class provides the client application the ability to convert XML data into a tree of Java content objects. Web services based on REST Architecture are known as RESTful web services. RESTful Web services use HTTP methods to implement the concept of REST architecture. JAX-RSis a Java programming language API designed to make it easy to develop applications that use the REST architecture. The JAX-RSAPI uses Javaprogramming language annotations to simplify the development of RESTful web services. Jersey is the reference implementation for the JSR 311 specification. Summary (Contd.)