Web Services - Chariot Solutions
Download
Report
Transcript Web Services - Chariot Solutions
Web Services:
Architecture and Development
Aaron Mulder
Chariot Solutions LLC
Agenda: Web Services Microcosm
• About web services
• Web services vs. other integration
techniques
• When to use web services
• J2EE web services features
• Vendor proprietary web services features
• Web services code example
Copyright © 2003 Chariot Solutions, LLC
November 2003
About Aaron Mulder
• Chief Technical Officer of Chariot Solutions
• Author (Professional EJB, WebLogic
Server 7 Handbook)
• Presenter (JavaOne 2001-2003, Java
Users Groups, BEA Users Groups)
• Member of JSR-88 Expert Group (J2EE
Application Deployment)
• Contributor to open-source projects
(Geronimo, JBoss, PostgreSQL, OpenEJB)
Copyright © 2003 Chariot Solutions, LLC
November 2003
About Chariot Solutions
• Information Technology provider focused
on automating business processes
• Specializes in J2EE architecture,
development, and systems integration
• Team of leading Java architects on staff
• Proven track record with companies such
as ExxonMobil, Rosenbluth International,
UGI Utilities, and the state of New Jersey
Copyright © 2003 Chariot Solutions, LLC
November 2003
About
Web Services
Web Services
• What are web services?
– Portable, XML-based RPC format
– Service description & location formats
– Connectivity for heterogeneous, distributed,
or unknown systems
– Human-readable
• What aren't web services?
– Transport
– API
– Silver Bullet
Copyright © 2003 Chariot Solutions, LLC
November 2003
Web Services Specifications
• SOAP 1.1 (May 2000) & 1.2 (June 2003)
– Message format
• WSDL 1.1 (March 2001) & 1.2/2.0 (Working Draft)
– Service description format
• UDDI 3.0 (July 2002) & 3.01 (October 2003)
– Service registry
• HTTP, HTTPS, various other transports
• JAXR, JAX-RPC, various other Java APIs
Copyright © 2003 Chariot Solutions, LLC
November 2003
SOAP Example
---- Request: ---<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:getVersion xmlns:ns1="http://soapinterop.org/">
</ns1:getVersion>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
---- Response: ---<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getVersionResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getVersionReturn
xsi:type="xsd:string">
Apache Axis version: 1.1 Built on Apr 04, 2003 (01:30:37 PST)
</getVersionReturn>
</getVersionResponse>
</soapenv:Body>
</soapenv:Envelope>
Copyright © 2003 Chariot Solutions, LLC
November 2003
WSDL Example
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://falcon:8080/axis/services/Version" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://falcon:8080/axis/services/Version"
xmlns:intf="http://falcon:8080/axis/services/Version" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="getVersionResponse">
<wsdl:part name="getVersionReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="getVersionRequest">
</wsdl:message>
<wsdl:portType name="Version">
<wsdl:operation name="getVersion">
<wsdl:input message="intf:getVersionRequest" name="getVersionRequest"/>
<wsdl:output message="intf:getVersionResponse" name="getVersionResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="VersionSoapBinding" type="intf:Version">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getVersion">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getVersionRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://falcon:8080/axis/services/Version"
use="encoded"/>
</wsdl:input>
<wsdl:output name="getVersionResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://falcon:8080/axis/services/Version"
use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="VersionService">
<wsdl:port binding="intf:VersionSoapBinding" name="Version">
<wsdlsoap:address location="http://falcon:8080/axis/services/Version"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Copyright © 2003 Chariot Solutions, LLC
November 2003
The Dynamic Vision
Your code needs something that can “foo”
It finds 3 sites offering “foo” in UDDI
It picks one, and gets its WSDL definition
It constructs some code to call that
service, calls it, and gets the response.
• The service bills you later, or whatever
•
•
•
•
And this is useful for...?
– It's “a matter of trust”
Copyright © 2003 Chariot Solutions, LLC
November 2003
The Dynamic Case
•
•
•
•
Ford Motor Company needs a bolt
All their suppliers are allowed in UDDI
Ford defines the interfaces
The suppliers choose when and how to
implement those, and register in UDDI
• When Ford needs a bolt, they look up bolt
providers in UDDI
• New suppliers and non-suppliers are no
problem
Copyright © 2003 Chariot Solutions, LLC
November 2003
The Static Vision
• Internal services are available as web
services, or...
• Internal services can be wrapped in a thin
web services layer
• Other internal clients, regardless of
language or platform, can invoke those
services
• Integration is “automatic” -- no
intermediaries (middleware)
Copyright © 2003 Chariot Solutions, LLC
November 2003
The Static Case
• One project group deploys some
functionality as web services
• Another group wants to take advantage of
those common services
• They point their development tools to the
WSDL for the services, and the tools
generate a client for that language
• With no real human effort, some code has
just written some code to invoke some
other code, and off you go
Copyright © 2003 Chariot Solutions, LLC
November 2003
The Pitfalls
“Server side” supporting unknown clients
Clients won't necessarily use API “wisely”
Decentralized (but maybe that's good)
XML is very open-ended – syntax varies
If there are interoperability problems,
whose problem is it? No one is
responsible for the integration itself.
• Interface is essentially stateless
•
•
•
•
•
Copyright © 2003 Chariot Solutions, LLC
November 2003
Web Services vs RMI
RMI
•
•
•
•
•
Binary
Mature
Java only
Static-ish clients
Excellent
compatibility
• Synchronous
Copyright © 2003 Chariot Solutions, LLC
•
•
•
•
•
•
Web Services
Text
In progress
Multi-language
Dynamic clients
Vendor, feature,
interop headaches
Sync/Async-ish
November 2003
Web Services vs JMS
•
•
•
•
•
•
JMS
Binary or Text
Mature
Java layer only
Static clients
Not much
interoperability
Asynchronous
Copyright © 2003 Chariot Solutions, LLC
•
•
•
•
•
•
Web Services
Text
In progress
Multi-language
Dynamic clients
Vendor, feature,
interop headaches
Sync/Async-ish
November 2003
Web Services vs CORBA
•
•
•
•
•
•
CORBA
Binary
Mature
Multi-language
Dynamic clients
Vendor, feature,
interop headaches
Sync/Async
Copyright © 2003 Chariot Solutions, LLC
•
•
•
•
•
•
Web Services
Text
In progress
Multi-language
Dynamic clients
Vendor, feature,
interop headaches
Sync/Async-ish
November 2003
When to use Web Services
•
•
•
•
•
•
Cross-language clients (Java to .Net)
Unknown clients
Coarse/infrequent requests
Dynamic lookups or invocation
Tools support
Committed to a server platform (or a 3rd
party Web Services implementation)
Copyright © 2003 Chariot Solutions, LLC
November 2003
Why to avoid Web Services
• Performance
• No standard security (integrity,
confidentiality, authentication)
– WS-Security (all 3), SAML (authentication),
SOAP Digital Signatures (integrity), ...
• No standard reliable delivery
– WS-Reliability, WS Reliable Messaging, WSAcknowledgement
• Interoperability problems (WS-I)
• No control over client (for clustering, etc.)
Copyright © 2003 Chariot Solutions, LLC
November 2003
Implementation Options
for Web Services
J2EE Web Services Features
• None yet!
• Servlets often used for custom/vendor
implementations
• J2EE 1.4
– Expose Servlet or EJB methods as Web
Services, configured in deployment descriptor
– Use web services with mapping in deployent
descriptor
– Supports WS-I Basic Profile for interoperability
– Voting going on now; Expected FCS 11/24
Copyright © 2003 Chariot Solutions, LLC
November 2003
J2EE WS Server Example
webservices.xml for an EJB:
<webservices>
<web-services-description>
<webservice-description-name>
StockQuoteService
</webservice-description-name>
<port-component>
<port-component-name>StockQuoteProvider</port-componentname>
<service-endpoint-interface>
com.acme.ws.StockQuoteProvider
</service-endpoint-interface>
<service-impl-bean>
<ejb-link>StockQuoteManager</ejb-link>
</service-impl-bean>
…
Copyright © 2003 Chariot Solutions, LLC
November 2003
J2EE WS Client Example
ejb-jar.xml for an EJB:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Portfolio</ejb-name>
<ejb-class>com.acme.ejb.PortfolioBean</ejb-class>
...
<service-ref>
<description>Cool stock quote service</description>
<service-ref-name>service/StockQuoteService</service-ref-name>
<service-interface>com.acme.ws.StockQuoteProvider</service-interface>
</service-ref>
Also need webservicesclient.xml to resolve
Copyright © 2003 Chariot Solutions, LLC
November 2003
Vendor Web Services Features
• First pass typically involved mapping
specific servlets and using vendor tools
• Current generation has moved to
deployment descriptor formats
• Typically support SOAP handlers of some
sort, potentially custom data type
serialization
• Typically includes tools to generate WSDL
and client code, or does it automatically
Copyright © 2003 Chariot Solutions, LLC
November 2003
WebLogic 7 WS Server Example
web-services.xml for an EJB
<web-services>
<web-service name="StockBean"
targetNamespace="java:mypackage.name"
uri="/web-services/StockQuoteProvider">
<components>
<stateless-ejb name="StockBean">
<ejb-link path="stock-ejbs.jar#StockQuoteManager" />
</stateless-ejb>
</components>
<operations>
<operation method="getQuote"
component="StockBean" />
</operations>
</web-service>
</web-services>
Copyright © 2003 Chariot Solutions, LLC
November 2003
WebLogic 7 WS Client Example
Generate client code with an Ant task
<clientgen
wsdl="http://localhost:7001/web-services/StockQuoteProvider?WSDL"
serviceName="StockBean"
packageName="com.acme.ws.client"
clientJar="stock-ws-client.jar"
/>
Then invoke the client with JAX-RPC like
normal
Copyright © 2003 Chariot Solutions, LLC
November 2003
Summary of Web Services
• Similar to CORBA and “plain” XML, but
easier to use
• Tool support is growing
• Interoperability is an issue
• Lacking security, management, reliability
• J2EE features are not here yet, while
vendor features vary and are proprietary
• Web Services interfaces available from:
Amazon.com, Google, Salesforce.com...
Copyright © 2003 Chariot Solutions, LLC
November 2003
Implementing
Web Services Today
Decision Points
•
•
•
•
J2EE features aren't available (almost!)
Vendor features are properietary
Third-party implementations are available
Apache AXIS
– http://ws.apache.org/axis/
– Runs as a servlet in any J2EE application
– Exposes Java classes, EJBs, etc.
– Generates and uses JAX-RPC clients
– Also used under the covers elsewhere
Copyright © 2003 Chariot Solutions, LLC
November 2003
Deploying AXIS
• AXIS 1.1 distribution includes a WAR
• We need to customize it to include security,
and perhaps change URL mapping
• Then it can be included directly in an EAR
and deployed in any app server
• We can also copy the libs and servlet
configuration into an existing WAR
Copyright © 2003 Chariot Solutions, LLC
November 2003
AXIS web.xml Customization
<security-constraint>
<web-resource-collection>
<web-resource-name>Axis</web-resource-name>
<url-pattern>/services/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>WebServiceUser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Axis</realm-name>
</login-config>
<security-role>
<role-name>WebServiceUser</role-name>
</security-role>
Copyright © 2003 Chariot Solutions, LLC
November 2003
EJB as Web Service with AXIS
Create a StockProvider.wsdd file:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="StockProvider" provider="java:EJB">
<parameter name="className"
value="com.acme.ws.StockQuoteManager" />
<parameter name="beanJndiName" value="StockQuoteManager" />
<parameter name="homeInterfaceName"
value="com.acme.ws.StockQuoteManagerHome" />
<parameter name="remoteInterfaceName"
value="com.acme.ws.StockQuoteManager" />
<parameter name="jndiContextClass"
value="org.jnp.interfaces.NamingContextFactory"/>
<parameter name="jndiURL" value="jnp://localhost:1099"/>
<parameter name="allowedMethods" value="*"/>
</service>
</deployment>
Copyright © 2003 Chariot Solutions, LLC
November 2003
Deploying the Web Service
• Use the AXIS admin tool
– Add AXIS JARs and XML parser to the
CLASSPATH
– run org.apache.axis.client.AdminClient
with the WSDD file as an argument
– Use “-u username -w password” for a
server with BASIC authentication
java -cp ... org.apache.axis.client.AdminClient -u ... -w ... StockProvider.wsdd
Copyright © 2003 Chariot Solutions, LLC
November 2003
Running the Web Service
• View the AXIS portal with a URL like
http://localhost:8080/axis/index.html
• Access the web service with a URL like
http://localhost:8080/axis/services/StockProvider
• Access the WSDL with a URL like
http://localhost:8080/axis/services/StockProvider?WSDL
• If the EJB requires authentication, the Web
Service does too
Copyright © 2003 Chariot Solutions, LLC
November 2003
Generating a Client
• Use the AXIS WSDL2Java tool
– Add AXIS JARs and XML parser to the
CLASSPATH
– run org.apache.axis.wsdl.WSDL2Java
with the WSDL URL as an argument
– Use “-U username -P password” for a
server with BASIC authentication
java -cp ... org.apache.axis.wsdl.WSDL2Java -U ... -P ...
http://localhost:8080/axis/services/StockProvider?WSDL
Copyright © 2003 Chariot Solutions, LLC
November 2003
Using the Client
• The generated code includes a Service, a
ServiceLocator, and a Port, which we use
like this:
StockProviderService service = new StockProviderServiceLocator();
StockProvider port = service.getStockProvider();
port.getQuote(“SUNW”); // this executes the Web Service call
• The same process can be used to generate
clients for and invoke non-AXIS web
services
Copyright © 2003 Chariot Solutions, LLC
November 2003
Apache AXIS Summary
• With AXIS, we can deploy J2EE web
services today, independent of the
application server
• AXIS can easily expose stateless session
beans as web services
• AXIS can generate code to invoke web
services running in AXIS or elsewhere
• AXIS supports handlers and a
MessageContext for more advanced
functionality
Copyright © 2003 Chariot Solutions, LLC
November 2003
Deploying Web Services
• Development/deployment technology is
here today (DDs, Ant tasks, tools, etc.)
• We're currently on our own for security,
reliability, management, and other aspects
• Best to use a 3rd party implementation like
AXIS until J2EE & the app servers catch up
• Need interoperability testing with expected
client platforms
• Other options like JMS are out there
Copyright © 2003 Chariot Solutions, LLC
November 2003
Questions?
http://www.chariotsolutions.com/presentations.html