Web Services and J2EE
Dan Harkey
Agenda
9Introduction to Web Services
9Web Services and EJB
1
Introduction
9Next step in distributed computing evolution
9Web Services are
self-describing
lightweight
inter-galactic components
Evolution
9Remote Procedure Calls (RPCs)
9Distributed Component Architectures
CORBA, DCOM
RMI & EJB
9XML-RPC, SOAP
9Web Services
2
Web Services and Distributed
Objects …
9 Both attempt to provide distributed computing solutions
over a network
Software components executing in different
processes on different systems
9 Both provide mechanisms for locating components
Naming or directory service of some type
Web services model provides a service registry
9 Both provide encoding methods or function invocations
between participants
Web Services and Distributed
Objects … (cont.)
9 Provide mechanisms for suitably marshalling parameters
passed as arguments in function calls or method
invocations
9 Provide rules detailing on-the-wire bits and bytes
9 Provide mechanisms for determining if faults have
occurred during a method call or function invocation
9 Provide introspection capabilities
3
What Web Services aren’t…
9Web services are not object oriented
No object reference
No encapsulated data
Data has to be always passed or pointed to
No Polymorphism
What is a Web Service
9Set of endpoints operating on XML messages
9Endpoint is defined by set of
Operations
Messages (arguments, results)
4
Web Services Roles
9 Service provider publishes information about the
service to a service registry.
9 Service registry maintains a catalog of deployed
(published) services and makes this catalog available to
new service providers and service requestors
9 Service Requester finds the service by using a lookup
against the service registry, and then binds to the
service provider. The provider and requestor can then
interact
Web Services Roles
5
Web Service Provider Tasks
9Create or obtain WSDL document describing
web service
9Implement service
9Deploy service
9Publish WSDL defining concrete service
Includes binding and addressing information
for service endpoints
Web Services Requester Tasks
9Obtain WSDL description of service
9Create artifacts to use service
9Send messages to endpoints/receive responses
6
Web Service Invocation
Web Services Architecture
7
Web Services Building Blocks
BPEL
BPML
Basic Building Blocks
9 Simple Object Access Protocol (SOAP)
XML based messaging framework
• Application-to-application protocol.
• Provides serialization formats and RPC-style mapping
9 Universal Description, Discovery and Integration
(UDDI)
A repository for discovering and registering Web Service
descriptions
9 Web Services Definition Language (WSDL)
XML application designed to describe all information
needed to interact with a service
• messages, operations and protocol mappings
8
Building Blocks
9 Transport protocols
HTTP, FTP, SMTP, Message Queues etc.
9 Flow languages
Describe the ordering of interactions between services.
• Client based programming to control business
processes (no centralized server).
• Examples:
Business Process Modeling Language (BPML)
Business Process Execution Language (BPEL)
Building Blocks (SOAP)
9XML based messaging framework designed to
act as application-to-application protocol
9Provides serialization formats for basic data
types
9Standard way of doing XML-RPC
9Does not mandate the transport protocol
Only HTTP binding is defines as standard
9
SOAP Functionality
Contents of a SOAP Message
9A SOAP Envelope that describes the message
and tells how the message should be processed
9Encoding rules to describe how application-
defined data types are encoded
9Elements that describe the desired remote
procedure calls and responses
10
SOAP Message
SOAP Envelope
11
SOAP Request/Response
Building blocks (WSDL)
9XML application designed to describe messages,
operations and protocol mappings of a Web
Service
12
WSDL
The Components of WSDL
13
WSDL Basic Service Description
WSDL
9 Message
Abstract definition of the data in the form of a message
presented either as an entire document or in the form of
arguments to be mapped to a method invocation
9 Types
Defines data types to be used in the messages
Typically in the form of XML Schemas, although WSDL
allows other mechanisms
Elements or the data structures that will be contained in a
message.
9 Operation
Abstract definition of the operation for a message
Naming a method, message queue, or business process
that will accept and process the message
14
WSDL (contd.)
9 Port Type
Represents a set of operations that are implemented by some
service provider residing at some location.
Define the possible operations for any number of service
providers who provide a common service.
Similar to an abstract interface.
Can be mapped to multiple transports through different
bindings.
9 Binding
Defines how an operation is bound to a protocol.
Combination of a protocol and data format for a port type
defines how the port type is mapped on to a particular
transport
Any protocol can be used to bind messages; however, SOAP,
HTTP GET/POST and MIME message binding formats are
defined in the spec.
WSDL (Contd.)
9 Port
A combination of a binding and a network address,
that provides the target address of the service
communication. The ports define the actual network
end-point that associates a binding with a protocol
specific address.
9 Service
This is a collection of related endpoints
encompassing the service definitions in the file;
services map the binding to the port (in short, a
service is a collection of ports).
15
Building blocks (UDDI)
9A repository for discovering and registering the
Web Service descriptions
9UDDI data categories
White Pages – address, contact, and known
identifiers
Yellow Pages – industrial categorizations
based on standard taxonomies
Green Pages – technical information about
services that are exposed by the business
UDDI
9 UDDI data structures
Business Entity
Business Service
Specification Pointers
Service Types
16
UDDI Structures and their
Elements
UDDI-WSDL mapping
17
EJB 2.1 Architecture
9Main addition is incorporation of Web Services
into the architecture
Make EJB components easy to use as
implementations for Web Services
Implementing a Web Service in EJB
9Stateless Session Bean is service endpoint
9Define web service endpoint interface
Maps to WSDL definition
JAX-RPC interface
9Implement business methods in bean class
9Invocations on service endpoint are delegate to
stateless session bean instance
JAX-RPC runtime handles mapping
18
Web Service
Endpoint Interface Example
public interface StockQuoteProvider
extends java.rmi.Remote
{
public float getLastTradePrice(String tickerSymbol)
throws java.rmi.RemoteException;
...
}
Web Service Endpoint Interface
9Follows rules for JAX-RPC interfaces
Cannot pass EJB Objects as arguments or
results
JAX-RPC serialization rules for value types
9Declare in deployment descriptor for session
bean using service-endpoint element
9Transaction attributes
Web services cannot have transaction
context so Mandatory doesn’t make sense
19
Stateless Session Bean Class
public class StockQuoteProviderBean
implements javax.ejb.SessionBean
{
public float getLastTradePrice(String tickerSymbol)
{
// business logic for method...
}
//...
}
Using a Web Service from an EJB
9Sending/Receiving messages looks like RPC
9Service-ref deployment descriptor
9Look up service stub in JNDI
9Get stub/proxy for service endpoint
9Invoke methods on endpoint
9JAX-RPC runtime in container handles
invocations on service endpoint, data type
mappings, etc.
20
EJB Client Web Service
Invocation Example
public class InvestmentBean
implements javax.ejb.SessionBean
{
public void checkPortfolio(...)
{
Context ctx = new InitialContext();
StockQuoteService sqs = ctx.lookup(
“java:comp/env/service/StockQuoteService”);
StockQuoteProvider sqp =
sqs.getStockQuoteProviderPort();
float quotePrice = sqp.getLastTradePrice(...);
...
}
...
}
References
9Wireless Java Programming for Enterprise
Applications, Chapter 14, Harkey, Appajodu,
Larkin, (Wiley 2002)
9http://servlet.java.sun.com/javaone/sf2003/conf
/sessions/index.en.jsp (see ts-2255)
21