Title: Neal Ford
1Building Web Services with Java
- Neal Ford
- CTO, The DSW Group, Ltd.
- Tuesday, September 10, 2002
2What This Session Will Cover
- Decrypting the alphabet soup of web services
- SOAP
- Axis
- Configuration
- Deployment of web services
- Simple
- Complex
- XML lt-gt Java data mapping
- WSDL
- UDDI
- Application integration
- Interoperability
3The Alphabet Soup
- XML
- Extensible Markup Language
- SOAP
- Simple Object Access Protocol
- WSDL
- Web Services Definition Language
- UDDI
- Universal Description Discovery and Integration
4SOAP
- Overview of SOAP
- SOAP Envelope Framework
- SOAP Envelope
- SOAP Versioning
- SOAP Headers
- SOAP Body
- SOAP Intermediaries
- Defined
- Uses
- Crossing trust domains
- Ensuring scalability
- Providing value-added services along the message
path
5SOAP
- Error Handling
- SOAP Data Encoding
- Specifying different encodings
- Data encoding rules
- SOAP protocol bindings
- HTTP/HTTPS
- SOAP with attachments
- SOAP over SMTP
6SOAP and Java
- Working with XML in Java
- XML parsing with Xerces
- XSL/XSLT transformations with Xalan
- Publishing Frameworks and Cocoon
- Apache SOAP v2
- AXIS
7Axis (Apache Extensible Interaction System
- Where to get it
- http//xml.apache.org/axis
- Axis includes
- a simple stand-alone server,
- a server which plugs into servlet engines such as
Tomcat, - extensive support for the Web Service Description
Language (WSDL) - emitter tooling that generates Java classes from
WSDL. - some sample programs
- a tool for monitoring TCP/IP packets.
- General Architecture
8Axis Components
- Axis Engine
- Handlers
- Chain
- Transports
- Deployment/configuration
- Serializers/deserializers
9Simple Web Services
- Axis handles through JWS files
- Axis
- Locates the file
- Compiles the class
- Converts SOAP calls correctly into invocations of
your Java class - Example Simple Web Service
10Custom Deployment and WSDD Files
- Web Service Deployment Descriptor
- XML document that defines deployment artifacts
- ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" - xmlnsjava"http//xml.apache.org/axis/wsdd/p
roviders/java"gt - ltservice name"MyService" provider"javaRPC"gt
- ltparameter name"className
- value"samples.userguide.example3.MyS
ervice"/gt - ltparameter name"allowedMethods" value""/gt
- lt/servicegt
- lt/deploymentgt
- Deployed (and undeployed) with the AdminClient
tool
java org.apache.axis.client.AdminClient
deploy.wsdd
11More Advanced Deployment Options
- WSDD files can specify specific details about the
web service, including handlers and chains
ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/a
xis/wsdd/providers/java"gt lt!-- define the
logging handler configuration --gt lthandler
name"track" type"javasamples.userguide.example4
.LogHandler"gt ltparameter name"filename"
value"MyService.log"/gt lt/handlergt lt!--
define the service, using the log handler we just
defined --gt ltservice name"LogTestService"
provider"javaRPC"gt ltrequestFlowgt lthandler
type"track"/gt lt/requestFlowgt ltparameter
name"className" value"samples.userguide.example4
.Service"/gt ltparameter name"allowedMethods"
value""/gt lt/servicegt lt/deploymentgt
12XML lt-gt Java Data Mapping with Axis
- Automatic serialization/deserialization for
JavaBeans
ltbeanMapping qname"nslocal" xmlnsns"someNamesp
ace" languageSpecificType"javamy.ja
va.thingy"/gt
- It is also possible to write custom
serializer/deserializers
13WSDL (Web Services Description Language)
- Primary elements of WSDL schema
- PortType
- Operation
- Message
- Binding
- Port
- Service
- Definitions
- Documentation
14Axis Support for WSDL
- Axis supports WSDL in three ways
- Auto-generation of WSDL via the ?WSDL flag
- WSDL2Java tool
- Java2WSDL tool
15WSDL2Java
- Tool that generates Java stub classes from WSDL
descriptions
java org.apache.axis.wsdl.WSDL2Java
(WSDL-file-URL)
16WSDL2Java
ltxsdcomplexType name"phone"gt ltxsdallgt ltxs
delement name"areaCode" type"xsdint"/gt ltxs
delement name"exchange" type"xsdstring"/gt
ltxsdelement name"number" type"xsdstring"/gt lt
/xsdallgt lt/xsdcomplexTypegt
public class Phone implements java.io.Serializable
public Phone() ... public int
getAreaCode() ... public void
setAreaCode(int areaCode) ... public
java.lang.String getExchange() ... public
void setExchange(java.lang.String exchange)
... public java.lang.String getNumber()
... public void setNumber(java.lang.String
number) ... public boolean equals(Object
obj) ... public int hashCode() ...
17Holders
- JAX-PRC defines both in and inout parameters
- Axis and WSDL2Java handle this by generating
holder classes - Works like Helpers in CORBA
package samples.addr.holders public final class
PhoneHolder implements javax.xml.rpc.holders.Holde
r public samples.addr.Phone value
public PhoneHolder() public
PhoneHolder(samples.addr.Phone value)
this.value value
18Java2WSDL
- Provide a Java interface or class
package samples.userguide.example6 /
Interface describing a web service to set and get
Widget prices. / public interface WidgetPrice
public void setWidgetPrice(String
widgetName, String price) public String
getWidgetPrice(String widgetName)
19Java2WSDL
- Use Java2WSDL to create a WSDL file
java org.apache.axis.wsdl.Java2WSDL -o wp.wsdl
-l"http//localhost8080/axis/services/WidgetPri
ce" -n "urnExample6" -p"samples.userguide.exam
ple6" "urnExample6" samples.userguide.example6
.WidgetPrice
- Where
- -o indicates the name of the output WSDL file
- -l indicates the location of the service
- -n is the target namespace of the WSDL file
- -p indicates a mapping from the package to a
- namespace. There may be multiple mappings.
- The class specified contains the interface of the
webservice.
20Java2WSDL
- Create bindings using WSDL2Java
java org.apache.axis.wsdl.WSDL2Java -o . -d
Session -s -S true -NurnExample6
samples.userguide.example6 wp.wsdl
21Java2WSDL
- Generated files (continued)
22UDDI (Universal Description Discovery and
Integration)
- UDDI (logical) registries
- Business (businessEntity)
- Reference types (tModel)
- Business entity
- White pages
- Yellow pages
- Green pages
- Technical models
- UDDI and Java
23Retrofitting Existing Applications
- Handling web services requirements
- Statelessness
- Granularity
- Existing J2EE applications
- Expose select functionality via web services
- Web projects
- Code must be written in web service calls to
handle web service work - Can use either JWS deployment or custom
deployment - EJB
- Web services (accessed via Axis in the servlet
layer) call stateless session beans to perform
work - Session beans perform required work
24Transaction Processing
- If you already have EJBs
- Handled via normal transaction semantics via
session and entity beans - If you have only servlets
- Handled by code written in the web service
methods exposed from the application - Two-phase commit is difficult across web service
invocations - Impending transaction standards
- TIP (Transaction Internet Protocol)
- Simple 2-phase commit protocol over TCP/IP
- XAML (XML Transaction Authority Markup Language)
- Promising concept but still no specification
25Interoperability
- Cross language/framework/platform
- Other Java web services
- The .NET framework
- Other languages/frameworks
- Enforcing interoperability
- SOAPBuilders
- A very active Yahoo list of SOAP developers
- Detailed discussions of interoperability issues
- The Interoperability Lab
- http//www.xmethods.net/ilab
- Includes resources such as the SOAP validator
test suite, standard ways to test web services
26Tool Support
- Example Borlands JBuilder Web Services Preview
Kit - Integrates Axis into JBuilder
- Wizards for
- Creating SOAP Server
- Importing WSDL
- Exporting a class as a web service
- Application Servers
- BEA WebLogic
- IBM Websphere
- IONA XMLBus
27Axis Alternatives
- GLUE
- Commercial product from Mind Electric, addresses
the same space as Axis - Contains numerous features to make developing web
services very easy - Customizable serialization/deserialization via
decorated XMLSchema files - Custom XML parser (ElectricXML)
- Java lt-gt XML persistence engine
- Built in servlet engine
- WASP
- http//www.idoox.com
- SOAP RMI
- http//www.extreme.indiana.edu/soap
28Web Services Reliability
- Peter Deutschs Eight Fallacies of Distributed
Computing - The network is reliable
- Latency is zero
- Bandwidth is infinite
- The network is secure
- Topology doesn't change
- There is one administrator
- Transport cost is zero
- The network is homogeneous
29The Future
- Web services will be the defining paradigm for
distributed computing in the near term - It is important that all web services
interoperate successfully - Web services and Java
- Full support from the open source and commercial
communities - Built on top of an existing proven infrastructure
(J2EE) - Very high scalability
- Multiple vendor support
- Cross platform
- Tools are making it easier and easier to publish
web services from Java applications, both J2EE
and otherwise
30Questions?To download sampleshttp//www.thedsw
group.com/conferences
- Neal Ford
- CTO
- The DSW Group, Ltd.
- nford_at_thedswgroup.com