1 / 30

Building Web Services with Java

Building Web Services with Java. Neal Ford CTO, The DSW Group, Ltd. Tuesday, September 10, 2002. What This Session Will Cover:. Decrypting the alphabet soup of web services SOAP Axis Configuration Deployment of web services Simple Complex XML <-> Java data mapping WSDL UDDI

coyne
Download Presentation

Building Web Services with Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building Web Services with Java Neal Ford CTO, The DSW Group, Ltd. Tuesday, September 10, 2002

  2. What This Session Will Cover: • Decrypting the alphabet soup of web services • SOAP • Axis • Configuration • Deployment of web services • Simple • Complex • XML <-> Java data mapping • WSDL • UDDI • Application integration • Interoperability

  3. The Alphabet Soup • XML • Extensible Markup Language • SOAP • Simple Object Access Protocol • WSDL • Web Services Definition Language • UDDI • Universal Description Discovery and Integration

  4. SOAP • 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

  5. SOAP • Error Handling • SOAP Data Encoding • Specifying different encodings • Data encoding rules • SOAP protocol bindings • HTTP/HTTPS • SOAP with attachments • SOAP over SMTP

  6. SOAP and Java • Working with XML in Java • XML parsing with Xerces • XSL/XSLT transformations with Xalan • Publishing Frameworks and Cocoon • Apache SOAP v2 • AXIS

  7. Axis (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

  8. Axis Components • Axis Engine • Handlers • Chain • Transports • Deployment/configuration • Serializers/deserializers

  9. Simple 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

  10. Custom Deployment and WSDD Files • Web Service Deployment Descriptor • XML document that defines deployment artifacts <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  <service name="MyService" provider="java:RPC">   <parameter name="className“ value="samples.userguide.example3.MyService"/>   <parameter name="allowedMethods" value="*"/>  </service> </deployment> • Deployed (and undeployed) with the AdminClient tool java org.apache.axis.client.AdminClient deploy.wsdd

  11. More Advanced Deployment Options • WSDD files can specify specific details about the web service, including handlers and chains <deployment xmlns="http://xml.apache.org/axis/wsdd/"             xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">   <!-- define the logging handler configuration -->  <handler name="track" type="java:samples.userguide.example4.LogHandler">   <parameter name="filename" value="MyService.log"/>  </handler>  <!-- define the service, using the log handler we just defined -->  <service name="LogTestService" provider="java:RPC">   <requestFlow>    <handler type="track"/>   </requestFlow>   <parameter name="className" value="samples.userguide.example4.Service"/>   <parameter name="allowedMethods" value="*"/>  </service> </deployment>

  12. XML <-> Java Data Mapping with Axis • Automatic serialization/deserialization for JavaBeans <beanMapping qname="ns:local" xmlns:ns="someNamespace"              languageSpecificType="java:my.java.thingy"/> • It is also possible to write custom serializer/deserializers

  13. WSDL (Web Services Description Language) • Primary elements of WSDL schema • PortType • Operation • Message • Binding • Port • Service • Definitions • Documentation

  14. Axis Support for WSDL • Axis supports WSDL in three ways • Auto-generation of WSDL via the “?WSDL“ flag • WSDL2Java tool • Java2WSDL tool

  15. WSDL2Java • Tool that generates Java stub classes from WSDL descriptions java org.apache.axis.wsdl.WSDL2Java (WSDL-file-URL)

  16. WSDL2Java • Given: <xsd:complexType name="phone">   <xsd:all>     <xsd:element name="areaCode" type="xsd:int"/>     <xsd:element name="exchange" type="xsd:string"/>     <xsd:element name="number" type="xsd:string"/>   </xsd:all> </xsd:complexType> • WSDL2Java generates: 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() {...} }

  17. Holders • 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.Holder { public samples.addr.Phone value; public PhoneHolder(){ } public PhoneHolder(samples.addr.Phone value) { this.value = value; } }

  18. Java2WSDL • 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); }

  19. Java2WSDL • Use Java2WSDL to create a WSDL file java org.apache.axis.wsdl.Java2WSDL -o wp.wsdl  -l"http://localhost:8080/axis/services/WidgetPrice" -n  "urn:Example6" -p"samples.userguide.example6" "urn:Example6"  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.

  20. Java2WSDL • Create bindings using WSDL2Java java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -S true  -Nurn:Example6 samples.userguide.example6 wp.wsdl • Generated files

  21. Java2WSDL • Generated files (continued)

  22. UDDI (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

  23. Retrofitting 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

  24. Transaction Processing • If you already have EJB’s • 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

  25. Interoperability • 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

  26. Tool Support • Example: Borland’s 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

  27. Axis 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 <-> XML persistence engine • Built in servlet engine • WASP • http://www.idoox.com • SOAP RMI • http://www.extreme.indiana.edu/soap

  28. Web Services Reliability • Peter Deutsch’s 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

  29. The 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

  30. Questions?To download samples:http://www.thedswgroup.com/conferences Neal Ford CTO The DSW Group, Ltd. nford@thedswgroup.com

More Related