View
226
Download
0
Category
Preview:
Citation preview
8/6/2019 Web Service Using JAX WS
1/59
Java Web Service
8/6/2019 Web Service Using JAX WS
2/59
Objective
What Is a Web Service? Identifying Web Service Standards
JEE Web Service APIs
Using Java API for XML based-WS API (JAX-WS) Developing a Web Service by Using the Bottom-
Up Approach
Invoking the Web Service with a Java Client
Application
Developing a Web Service by Using the Top-
Down Approach
8/6/2019 Web Service Using JAX WS
3/59
What is Service ?
A service is a behavior that is provided by a
component for use by any other component
based only on the interface contract.
A service has a network-addressable interface.
A service may be dynamically discovered and
used.
8/6/2019 Web Service Using JAX WS
4/59
8/6/2019 Web Service Using JAX WS
5/59
8/6/2019 Web Service Using JAX WS
6/59
8/6/2019 Web Service Using JAX WS
7/59
8/6/2019 Web Service Using JAX WS
8/59
Service-oriented Architecture
SOA is a design and a way of thinking about building s/w components.
8/6/2019 Web Service Using JAX WS
9/59
Benefits of SOA
Better reuse
Build new client functionality on top of existing
Business Services
Well defined interfaces
Make changes without affecting clients
Easier to maintain
Changes/Versions are not all-or-nothing
Better flexibility
8/6/2019 Web Service Using JAX WS
10/59
What is aWeb Service?
In simpler terms
Software that performs a task.
Sits on a network so other systems can talk toit (most often SOAP over HTTP).
Has a defined, published interface (viaWSDL).
Is pla
tforma
nd la
ngua
ge independent. Typically uses XML.
8/6/2019 Web Service Using JAX WS
11/59
8/6/2019 Web Service Using JAX WS
12/59
8/6/2019 Web Service Using JAX WS
13/59
Web service standards
8/6/2019 Web Service Using JAX WS
14/59
8/6/2019 Web Service Using JAX WS
15/59
Web services programming stack.
Web service stack is a collection of
standardized protocols and application
programming interfaces (APIs) that lets
individuals and applications locate and utilize
Web services.
8/6/2019 Web Service Using JAX WS
16/59
8/6/2019 Web Service Using JAX WS
17/59
Simple Object Access Protocol
SOAP is a lightweight protocol for exchange of information in a
decentralized, distributed environment.
It is an XML based protocol that consists of three parts:
1. SOAP envelope that defines a framework for describing what is in amessage
and how to process it.
2. SOAP encoding rules for expressing instances ofapplication-defined data types.
3. SOAP for representing remote procedure calls and responses.
8/6/2019 Web Service Using JAX WS
18/59
8/6/2019 Web Service Using JAX WS
19/59
8/6/2019 Web Service Using JAX WS
20/59
8/6/2019 Web Service Using JAX WS
21/59
8/6/2019 Web Service Using JAX WS
22/59
8/6/2019 Web Service Using JAX WS
23/59
SOAP Envelope the primary container
root element of the message using the XML namespace
http://schemas.xmlsoap.org/soap/envelope/ (As per SOAP 1.1spec.)
SOAP Header first immediate child element of a SOAP envelope
zero or more optional child elements mustUnderstand attribute
represents a transaction semantics entry
provide mechanisms to extend
defining high-level functionalities such as security, transactions,priority, and auditing
8/6/2019 Web Service Using JAX WS
24/59
SOAP Header
The Header element is encoded as the first immediate child element of the
SOAP Envelope XML element. All immedia
te ch
ild elements of th
e Hea
derelement are called header entries.
The encoding rules for header entries are as follows:
1. A header entry is identified by its fully qualified element name, which
consists of the namespace URI and the local name.
2. The SOAP encodingStyle attribute MAY be used to indicate the encoding style
used for the header entries.
3. The SOAP mustUnderstand attribute.
5
8/6/2019 Web Service Using JAX WS
25/59
SOAP Body SOAP envelopes child element
one or more optional SOAP body block entries
mandatory processing information or the payload intended for thereceiver
Body block can contain RPC method and its parameters
Target application (receiver) specific data
SOAP fault for reporting errors and status information
SOAP Fault error and/or status information
elements to define the error and status Faultcode (VersionMismatch, MustUnderstand, Client, Server)
Faultstring, Faultactor, Detail
8/6/2019 Web Service Using JAX WS
26/59
SOAP mustUnderstand the processing of a SOAP header block is mandatory
or optional at the target SOAP node
SOAP Attachments
An XML format and any data format (can be ASCII orbinary)
8/6/2019 Web Service Using JAX WS
27/59
Examples of SOAP Messages
SOAP Message Embedded in HTTP Request
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI"
L&T
8/6/2019 Web Service Using JAX WS
28/59
SOAP Message Embedded in HTTP Response
HTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn
34.5
8/6/2019 Web Service Using JAX WS
29/59
SOAP Communication
SOAP RPC remote procedural call-based synchronous
communication tightly coupled communication model based on
requests and responses.
SOAP Messaging
document-driven communication Using synchronous and asynchronous messaging
loosely coupled communication model based onmessage notification and the exchange of XMLdocuments
8/6/2019 Web Service Using JAX WS
30/59
8/6/2019 Web Service Using JAX WS
31/59
Web service Description Language -WSDL
Interface Definition Language (IDL) service based on XML that
defines the service interface and its implementation characteristics.WSDL document contains following (W3C spec):
Types a container for data type definitions using some type system
(suchas XSD).
Message an abstract, typed definition of the data being communicated.
Oper
ation
ana
bstra
ct description ofa
na
ction supported by th
eservice.
Port Typean abstract set of operations supported by one or more
endpoints.
Binding a concrete protocol and data format specification for a
particular port type.
Port a single endpoint defined as a combination ofa binding and anetwork address.
Service a collection of related endpoints.
8/6/2019 Web Service Using JAX WS
32/59
8/6/2019 Web Service Using JAX WS
33/59
The main structure of a WSDL document :
definition of types........
definition ofamessage....
definition ofa port.......
definition ofa binding....
8/6/2019 Web Service Using JAX WS
34/59
WSDL Ports
The element is the most importantWSDL element.
It describes a web service, the operations that can be performed, and the
messages that are involved.
WSDL Messages
The element defines the data elements ofan operation.
Eachmessage can consist of one or more parts. The parts can be compared
to the parameters ofa function call in a traditional programming language.
WSDL Types
The element defines the data types that are used by the web
service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define
data types.
WSDL Bindings
The element defines the message format and protocol details for
each port.
8/6/2019 Web Service Using JAX WS
35/59
UDDI
The Universal Description, Discovery, and Integration (UDDI) specifications
define how to publishand discover information about services in a UDDI-conforming registry.
The UDDI schema identifies the types of XML data structures that comprise an
entry in the registry for a service.
UDDI registry as a "Yellow Pages" for web services.
Web services uses UDDI for discovery and lookup services.
8/6/2019 Web Service Using JAX WS
36/59
WSDL
Web Service(J2EE, PL/SQL,
.NET,C/C++,
Legacy )
Web Service(J2EE, PL/SQL,
.NET,C/C++,
Legacy )
Web ServiceClient
(J2EE, .NET,
PL/SQL )
Web ServiceClient
(J2EE, .NET,
PL/SQL )
Points to
description
Describes
Service
Finds
Service
Invokes with
XML Messages
BasicWeb Services
SOAP
UDDI
Registry
Points toservice
8/6/2019 Web Service Using JAX WS
37/59
8/6/2019 Web Service Using JAX WS
38/59
8/6/2019 Web Service Using JAX WS
39/59
8/6/2019 Web Service Using JAX WS
40/59
8/6/2019 Web Service Using JAX WS
41/59
Building Web Services with JAX-WS
8/6/2019 Web Service Using JAX WS
42/59
What is JAX-WS
8/6/2019 Web Service Using JAX WS
43/59
JAX-WS is a technology for building web services and
clients that communicate using XML.
JAX-WS allows developers to write message-oriented as well as RPC-oriented web services.
In JAX-WS, a remote procedure call is represented
by an XML-based protocol suchas SOAP.
8/6/2019 Web Service Using JAX WS
44/59
Why JAX-WS ?
Platform independence of the Java programming
language.
JAX-WS client can access a web service that is not
running on th
e Ja
va
pla
tform,a
nd vice versa
.It provides a complete Web services stack that eases
the task of developing and deployingWeb services.
JAX-WS also includes the Java Architecture for XML
Binding (JAX
B)a
nd SOAP with
Atta
ch
ments API for Ja
va
(SAAJ).
8/6/2019 Web Service Using JAX WS
45/59
JAX-WS speeds up Web services development by
providing a library of annotations to turn plain old
Java object (POJO) classes into Web services.
It also specifies a detailed mapping from a service
defined in the Web Services Description Language
(WSDL) to the Java classes that implement that
service.
8/6/2019 Web Service Using JAX WS
46/59
JAX-WS supports two approaches
Contract first: Start withaWSDL contract, and
generate a Java class to implement the service.
Code first: Start witha Java class, and useannotations to generate bothaWSDL file and a
Java interface.
8/6/2019 Web Service Using JAX WS
47/59
8/6/2019 Web Service Using JAX WS
48/59
8/6/2019 Web Service Using JAX WS
49/59
8/6/2019 Web Service Using JAX WS
50/59
8/6/2019 Web Service Using JAX WS
51/59
8/6/2019 Web Service Using JAX WS
52/59
8/6/2019 Web Service Using JAX WS
53/59
8/6/2019 Web Service Using JAX WS
54/59
8/6/2019 Web Service Using JAX WS
55/59
Creating a Simple Web Service and Client with JAX-WS
8/6/2019 Web Service Using JAX WS
56/59
Developing a JAX-WS web service is a Java class annotated with
the javax.jws.WebService annotation.
The @WebService annotation defines the class as a webservice endpoint.
A service endpoint interface (SEI) is a Java interface that
declares the methods that a client can invoke on the service.
An SEI is not required when building a JAX-WS endpoint. The
web service implementation class implicitly defines a SEI.
8/6/2019 Web Service Using JAX WS
57/59
Use the endpoint implementation class and
The wsgen tool to generate the web service artifacts
and the stubs that connect a web service client to the
JAX-WS runtime.
8/6/2019 Web Service Using JAX WS
58/59
Basic steps for creating the web service and client:
Code the implementation class.Compile the implementation class.
Deploy the WAR file. The tie classes (whichare used to
communicate with clients) are generated by the Application
Server during deployment.
Code the client class.Use wsimportto generate and compile the stub files.
Compile the client class.
Run the client.
8/6/2019 Web Service Using JAX WS
59/59
Thank You
Recommended