
b49d0ceef9a111efec2e65164e434ad0.ppt
- Количество слайдов: 39
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 • J 2 EE 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, Web. Logic Server 7 Handbook) • Presenter (Java. One 2001 -2003, Java Users Groups, BEA Users Groups) • Member of JSR-88 Expert Group (J 2 EE Application Deployment) • Contributor to open-source projects (Geronimo, JBoss, Postgre. SQL, Open. EJB) Copyright © 2003 Chariot Solutions, LLC November 2003
About Chariot Solutions • Information Technology provider focused on automating business processes • Specializes in J 2 EE architecture, development, and systems integration • Team of leading Java architects on staff • Proven track record with companies such as Exxon. Mobil, 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. w 3. org/2001/XMLSchema" xmlns: SOAP-ENV="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <SOAP-ENV: Body> <ns 1: get. Version xmlns: ns 1="http: //soapinterop. org/"> </ns 1: get. Version> </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. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <get. Version. Response soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <get. Version. Return xsi: type="xsd: string"> Apache Axis version: 1. 1 Built on Apr 04, 2003 (01: 30: 37 PST) </get. Version. Return> </get. Version. Response> </soapenv: Body> </soapenv: Envelope> Copyright © 2003 Chariot Solutions, LLC November 2003
WSDL Example <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="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. w 3. org/2001/XMLSchema"> <wsdl: message name="get. Version. Response"> <wsdl: part name="get. Version. Return" type="xsd: string"/> </wsdl: message> <wsdl: message name="get. Version. Request"> </wsdl: message> <wsdl: port. Type name="Version"> <wsdl: operation name="get. Version"> <wsdl: input message="intf: get. Version. Request" name="get. Version. Request"/> <wsdl: output message="intf: get. Version. Response" name="get. Version. Response"/> </wsdl: operation> </wsdl: port. Type> <wsdl: binding name="Version. Soap. Binding" type="intf: Version"> <wsdlsoap: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> <wsdl: operation name="get. Version"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="get. Version. Request"> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //falcon: 8080/axis/services/Version" use="encoded"/> </wsdl: input> <wsdl: output name="get. Version. Response"> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //falcon: 8080/axis/services/Version" use="encoded"/> </wsdl: output> </wsdl: operation> </wsdl: binding> <wsdl: service name="Version. Service"> <wsdl: port binding="intf: Version. Soap. Binding" 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 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 3 rd 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
J 2 EE Web Services Features • None yet! • Servlets often used for custom/vendor implementations • J 2 EE 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
J 2 EE WS Server Example webservices. xml for an EJB: <webservices> <web-services-description> <webservice-description-name> Stock. Quote. Service </webservice-description-name> <port-component-name>Stock. Quote. Provider</port-componentname> <service-endpoint-interface> com. acme. ws. Stock. Quote. Provider </service-endpoint-interface> <service-impl-bean> <ejb-link>Stock. Quote. Manager</ejb-link> </service-impl-bean> … Copyright © 2003 Chariot Solutions, LLC November 2003
J 2 EE WS Client Example ejb-jar. xml for an EJB: <ejb-jar> <enterprise-beans> <session> <ejb-name>Portfolio</ejb-name> <ejb-class>com. acme. ejb. Portfolio. Bean</ejb-class>. . . <service-ref> <description>Cool stock quote service</description> <service-ref-name>service/Stock. Quote. Service</service-ref-name> <service-interface>com. acme. ws. Stock. Quote. Provider</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
Web. Logic 7 WS Server Example web-services. xml for an EJB <web-services> <web-service name="Stock. Bean" target. Namespace="java: mypackage. name" uri="/web-services/Stock. Quote. Provider"> <components> <stateless-ejb name="Stock. Bean"> <ejb-link path="stock-ejbs. jar#Stock. Quote. Manager" /> </stateless-ejb> </components> <operation method="get. Quote" component="Stock. Bean" /> </operations> </web-services> Copyright © 2003 Chariot Solutions, LLC November 2003
Web. Logic 7 WS Client Example Generate client code with an Ant task <clientgen wsdl="http: //localhost: 7001/web-services/Stock. Quote. Provider? WSDL" service. Name="Stock. Bean" package. Name="com. acme. ws. client" client. Jar="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 • J 2 EE 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 • • J 2 EE 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 J 2 EE 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>Web. Service. User</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>Axis</realm-name> </login-config> <security-role> <role-name>Web. Service. User</role-name> </security-role> Copyright © 2003 Chariot Solutions, LLC November 2003
EJB as Web Service with AXIS Create a Stock. Provider. wsdd file: <deployment xmlns="http: //xml. apache. org/axis/wsdd/" xmlns: java="http: //xml. apache. org/axis/wsdd/providers/java"> <service name="Stock. Provider" provider="java: EJB"> <parameter name="class. Name" value="com. acme. ws. Stock. Quote. Manager" /> <parameter name="bean. Jndi. Name" value="Stock. Quote. Manager" /> <parameter name="home. Interface. Name" value="com. acme. ws. Stock. Quote. Manager. Home" /> <parameter name="remote. Interface. Name" value="com. acme. ws. Stock. Quote. Manager" /> <parameter name="jndi. Context. Class" value="org. jnp. interfaces. Naming. Context. Factory"/> <parameter name="jndi. URL" value="jnp: //localhost: 1099"/> <parameter name="allowed. Methods" 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. Admin. Client with the WSDD file as an argument – Use “-u username -w password” for a server with BASIC authentication java -cp. . . org. apache. axis. client. Admin. Client -u. . . -w. . . Stock. Provider. 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/Stock. Provider • Access the WSDL with a URL like http: //localhost: 8080/axis/services/Stock. Provider? WSDL • If the EJB requires authentication, the Web Service does too Copyright © 2003 Chariot Solutions, LLC November 2003
Generating a Client • Use the AXIS WSDL 2 Java tool – Add AXIS JARs and XML parser to the CLASSPATH – run org. apache. axis. wsdl. WSDL 2 Java with the WSDL URL as an argument – Use “-U username -P password” for a server with BASIC authentication java -cp. . . org. apache. axis. wsdl. WSDL 2 Java -U. . . -P. . . http: //localhost: 8080/axis/services/Stock. Provider? WSDL Copyright © 2003 Chariot Solutions, LLC November 2003
Using the Client • The generated code includes a Service, a Service. Locator, and a Port, which we use like this: Stock. Provider. Service service = new Stock. Provider. Service. Locator(); Stock. Provider port = service. get. Stock. Provider(); port. get. Quote(“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 J 2 EE 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 Message. Context 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 3 rd party implementation like AXIS until J 2 EE & 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
b49d0ceef9a111efec2e65164e434ad0.ppt