Title: Distributed Programming in Java
1Distributed Programming in Java
2Properties of Web Services
- Web services assume that services are
loosely-coupled - they have minimal dependencies and
- they are typically defined, developed, and
deployed by different companies. - This assumption leads to a world view that
everything is a service and helps to realize
the vision of service-oriented architectures in
which software applications are created by
combining multiple services.
3Web Services Architecture
- Two aspects internal and external
- Internal how do we connect a Web service to a
company's information systems - External how do we connect a client with a Web
service
4(No Transcript)
5Internal view
- Web services are viewed as wrappers of existing
information systems. We need a middleware layer
that can connect Web services to a company's
existing middleware platform.
6(No Transcript)
7External View
- Web services assume the existence of a
third-party directory service that is used for
service discovery. Once such a service is in
place, then the external architecture looks like
this
8(No Transcript)
9- Since it would be difficult to scale this
approach (assuming the existence of a third-party
manager) for other middleware characteristics
(such as support for transactions), it is assumed
that in the future, individual Web services will
each provide these managers (in some fashion) and
that these individual managers will coordinate in
a peer-to-peer fashion to achieve the desired
effects.
10(No Transcript)
11UDDI
- Universal Description, Discovery a mechanism for
registering and discovering Web services. - From simple yellow pages directory to a framework
for brokering collaboration between Web services
12How to find Web Services
- Static discovery programmer manually find and
then hardwire it into the application. - Human intelligence and
- public registries
- Dynamic discovery the application itself at
runtime finds a required Web service selected on
the basis of some criteria, eg. price,
availability, or efficiency. - private registries where the semantics and
validity of entries are guaranteed by trusted
organizations.
13Descriptions UDDI
- A hierarchy of five levels
- publisherAssertion
(describes relations between businesses
eg one is a subsidiary of another) - businessEntity
(describes a concrete business
contact info and UDDI key) - businessService
(describes a Web service with an
description, UDDI key, and key references) - bindingTemplate
(describes how to invoke a Web service with
an address and a reference to tModel) - tModel
(technical details for invoking a Web
service, reference to WSDL description)
14Business Entity for Recipe Server (1/2)
15Business Entity for Recipe Server (2/2)
16tModel for Recipe Server
17Discovery UDDI
18Summary
- SOAP a transport neutral protocol for XML data
- interchange (but focusing on HTTP)
- WSDL description of Web service interfaces
- UDDI registries and discovery of Web services
19Essential Online Resources
- SOAP http//www.w3.org/TR/soap/
- WSDL http//www.w3.org/2002/
- UDDI http//www.uddi.org
- XML-RPC http//www.xmlrpc.com/
- The Web Service Interoperability
http//www.ws-i.org/
20Architecture
- Structure(s) of a system, comprising
- components (core blocks)
- externally visible properties of these components
(constraints) - their relationships (connectors)
- Architectural style is a specialization of
component and connector types with a set of
constraints on how they can be used
21Interaction of Java and WS
- WS architecture has its root in component-based
architecture, and supports different
communication styles messages, call-return - Java platform embodies object-oriented
architecture with call-return communication - Need to convert ...
- between Javas call-return style to the dominant
message-based communication style of WS - between rich (objects) and flat data structures
22Architecture Adapter (Take 1)
- Architecture adapter as a component that mediates
between two architectures
23Architecture Adapter (Take 1)
- Architecture A Component implements functionality
in style A, eg OO, call-return - Architecture B Component implements functionality
in style B, eg message, flat - Architecture Adapter mediates between style A and
style B, which means that is must offer a natural
interface to both styles - Needs to convert component architecture, ie
communication style and data style
24Architecture Adapter (Take 2)
- Often the Architecture Adapter is split into two
halves, which communicate with one another using
their own architectural style
25Architecture Adapters in WS
- WS frameworks such as Axis allow you to be fully
WS-agnostic to access WS from Java use method
calls via architecture adapters
26Customer Database
- Core classes of a customer database
Adhere to JavaBeansconventions
27XML to Java Data Mapping
- Basic mapping defined by JAX-RPC spec
- Mapping of primitive types
- Complex types that follow the JavaBeans
convention (Bean Serializer) - Arrays and some Collections
- Exceptions
- Key consideration is the interoperability between
SOAP implementations !
28Mapping of Primitive Types
- Primitive typesdefined instandard SOAPencoding
29Complex Types
- Axis can serialize and deserialize any classes
that follow the JavaBeans convention ... - ... without requiring you to write any code !
- Simple properties
- setAddress and getAddress
- Indexed properties (arrays of values)
- Customer
- Business Object Pattern PM
30Bean Serializers
- To configure a bean mapping, add a ltbeanMappinggt
tag to the WSDD - Maps a Java bean to an XML QName
ltbeanMapping qname"nslocal" xmlnsns"someNamesp
ace" languageSpecificType"javamy.java.SomeEnt
ity"/gt
31BeanService
32Order (simple)
public class Order private String
customerName private String shippingAddress p
ublic String getCustomerName() return
customerName public void setCustomerName(Stri
ng name) customerName name public
String getShippingAddress() return
shippingAddress public void
setShippingAddress(String address)
shippingAddress address // ...
33Arrays and Collections
- Some Java collections (Vector, Hashtable, ...)
have serializers, but interoperability between
SOAP implementations is not guaranteed - eg .NET does not support Hashtables
- Most reliable way is to use Arrays
public CustomerImpl getCustomers() public void
setCustomers(CustomerImpl customers)
34Order (indexed)
// ... private String itemCodes private
int quantities public String getItemCodes()
return itemCodes public void
setItemCodes(String items)
itemCodes items public int
getQuantities() return quantities public
void setQuantities(int quants) quantities
quants
35BeanService
public class BeanService public String
processOrder(Order order) String sep
System.getProperty("line.separator")
String response "Hi, " order.getCustomerName()
response sep "You have ordered
these items" sep String items
order.getItemCodes() int quantities
order.getQuantities() for (int i 0 i
lt items.length i) response
sep quantitiesi " of item "
itemsi return response
36WSDD for BeanService
- Add data for the WS architecture that does not
exist in the Java platform - Namespace (urnBeanService)
- Serializers (beanMapping to nsorder)
ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/axis/wsdd/pro
viders/java"gt ltservice name"OrderProcessor"
provider"javaRPC"gt ltparameter
name"className" value"samples.userguide.example5
.BeanService"/gt ltparameter
name"allowedMethods" value"processOrder"/gt
ltbeanMapping qname"nsOrder"
xmlnsns"urnBeanService" languageSpecificType"j
avasamples.userguide.example5.Order"/gt
lt/servicegt lt/deploymentgt
37Exceptions
- java.rmi.Exceptions are mapped to SOAP Faults
(recap request, response, fault) - Fault code contains class name of fault
- Other exceptions treated differently
- Mapped to wsdlfault in WSDL of the method
- Need to follow JavaBeans convention (need to have
accessors for all fields of the exception and a
constructor with all fields as its arguments)
38Using Axis Step by Step
- Provide a Java interface or class that describes
the service interface - Create WSDL using Java2WSDL tool
- Create bindings through WSDL2Java tool
- Implement the service interface
- Deploy the service
- Implement clients using generated stubs
39Provide Java Interface
- Define the functionality you want to expose as a
web service using an interface
package dpj.ws.steps public interface
OrderProcessor public void processOrder(Order
order)
40Create WSDL from Java
- Create the WSDL (OrderProcessor.wsdl) from the
Java interface defined earlier - -o name of output file
- -l location of web service
- -n target namespace of the WSDL document
- -p mapping of name space to packages
java org.apache.axis.wsdl.Java2WSDL -o
"dpj/ws/steps/OrderProcessor.wsdl" -l
"http//localhost8080/axis/services/OrderProcesso
r" -n "urnSteps" -p"dpj.ws.steps"
"urnSteps" dpj.ws.steps.OrderProcessor
41Create WSDL from Java
- Conversion to WSDL will also generate XML types
(using XML Schema) for all non-primitive types
references in the interface - Supports bean classes, enumeration classes,
arrays, and holder classes (inout)
ltcomplexType name"Order"gt ltsequencegt ltelement
name"customerName" nillable"true"
type"soapencstring"/gt ltelement
name"itemCodes" nillable"true"
type"implArrayOf_soapenc_string"/gt ltelement
name"quantities" nillable"true"
type"implArrayOf_xsd_int"/gt ltelement
name"shippingAddress" nillable"true"
type"soapencstring"/gt lt/sequencegt lt/complexType
gt
42Create Bindings from WSDL
- Earlier we had handcraft SOAP messages to invoke
a web service (too low-level) - Help is on its way with WSDL2Java you can
convert a WSDL file into Java stubs
43Create Bindings from WSDL
- Create a client-side architecture adapter using
WSDL2Java - -o name of output file
- -N mapping of name space to target package
- Adapter classes created
- public interface OrderProcessorService
- public class OrderProcessorServiceLocator
java org.apache.axis.wsdl.WSDL2Java -o .
\ -NurnSteps dpj.ws.steps.client
dpj/ws/steps/OrderProcessor.wsdl
44Implement Service and Clients
- Implement the service by implementing the
OrderProcessing interface - Implement the client
public class OrderProcessorImpl implements
OrderProcessor
OrderProcessorService service new
OrderProcessorServiceLocator() OrderProcessor
port service.getOrderProcessor() Order order
... // construct the order port.processOrder(or
der)
45Tips
- Read the Axis User Guide
- If you can deploy it, you can undeploy it!
46If You Can Deploy It, ...
- Deploying is the act of making a web service
available to the Axis engine - Send to Axis engine with AdminClient
ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/a
xis/wsdd/providers/java"gt ltservice
name"MyService" provider"javaRPC"gt
ltparameter name"scope" value"Application"/gt
ltparameter name"className" value"samples.usergui
de.example3.MyService"/gt ltparameter
name"allowedMethods" value""/gt
lt/servicegt lt/deploymentgt
gt java org.apache.axis.client.AdminClient -p 9090
deploy.wsddltAdmingtDone processinglt/Admingt
47... You Can Undeploy It!
- A service removed from the Axis engine by
undeploying it (eg to install a new one) - As an aside, you can get a list of installed
services from the AdminClient
ltundeployment xmlns"http//xml.apache.org/axis/ws
dd/"gt ltservice name"MyService"/gt lt/undeploymentgt
gt java org.apache.axis.client.AdminClient -p 9900
list ... ltns1service name"MyService"
provider"javaRPC"gt ltns1parameter
name"allowedMethods" value""/gt
ltns1parameter name"className"
value"samples.userguide.example3.MyService"/gt
lt/ns1servicegt
48Deployment Step by Step
- Assuming that you have started your Axis engine
with the SimpleAxisServer ... - Deploy your service with the AdminClient
- After using the service, undeploy
gt cd workspace/Axis gt java org.apache.axis.transpo
rt.http.SimpleAxisServer -p 9090
gt java org.apache.axis.client.AdminClient -p 9090
deploy.wsddltAdmingtDone processinglt/Admingt
gt java org.apache.axis.client.AdminClient -p 9090
undeploy.wsddltAdmingtDone processinglt/Admingt
49- http//developer.apple.com/documentation/WebObject
s/Web_Services/Web_Services/chapter_4_section_7.ht
ml