1 / 57

Organizational Communications and Distributed Object Technologies

Organizational Communications and Distributed Object Technologies. Lecture 7: Axis2. Apache Axis2 (1). Since 2004 (a new Apache Axis). A core engine for web services. Compares with Microsoft Indigo. Runs under any J2EE server.

mingan
Download Presentation

Organizational Communications and Distributed Object Technologies

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. Organizational Communications and Distributed Object Technologies Lecture 7: Axis2 Master of Information System Management

  2. Apache Axis2 (1) • Since 2004 (a new Apache Axis). • A core engine for web services. • Compares with Microsoft Indigo. • Runs under any J2EE server. • Will include WS-Reliable Messaging (Sandesha2) WS-Coordination, WS-AtomicTransaction, WS-BusinessActivity (Kandula2), WS-Security (Rampart), WS-Addressing (out of the box). Master of Information System Management

  3. Apache Axis2 (2) • Synchronous and Asynchronous web services. • MEP (Message Exchange Patterns). • Transport Independent core (SMTP, FTP, HTTP, MOM, etc.). • WSDL 1.0 and 2.0. • WSDL2Java and Java2WSDL. • Supports queries for WSDL (using ?wsdl) schema (using ?xsd) and policies (using ?policy). • Service Archive wizard for Eclipse. • Code generation wizard for Eclipse. Master of Information System Management

  4. Installation • Main web site: http://ws.apache.org/axis2/ • Use any J2EE web container. • Here, we will use Tomcat. Master of Information System Management

  5. Web Container Directory apache-tomcat-6.0.10 conf bin lib webapps common logs work axis2 Master of Information System Management

  6. webapps Axis2 Directory Structure (1) axis2 axis2.war This is a relatively fixed area to work in. axis2-web WEB-INF classes conf lib modules services web.xml • This directory structure is created by running the ant build script provided with Axis2. • The entire structure is compressed as a java archive and written to the file axis2.war. • The axis2.war file is copied into Tomcat’s webapp directory. • The file axis2.war is expanded under the directory named axis2. • Delete the axis2 directory before changing the war. In that way the war will be expanded again into a new axis2 directory. • Normally, you leave this directory structure in place. Add and update new web services within this existing directory structure. Master of Information System Management

  7. Axis2 Directory Structure (2) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml Axis2 administration pages. Use admin to temporarily add services or engage or or disengage modules. The configuration description found in conf/axis2.xml is not changed so these changes are temporary. Default username is admin. Default password is axis2. Master of Information System Management

  8. Axis2 Directory Structure (3) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml Classes needed by Axis2 itself. Master of Information System Management

  9. Axis2 Directory Structure (4) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml axis2.xml is an important file Defines how received messages are handled. Defines transport senders and receivers. Determines which modules are active. Defines order of phases and how handlers are to be executed within each phase. Master of Information System Management

  10. Axis2 Directory Structure (5) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml .jar (Java archive) files supporting Axis2 activities Master of Information System Management

  11. Axis2 Directory Structure (6) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml .mar (module archive) files are used to extend axis2 - adding handlers to the message stream. Master of Information System Management

  12. Axis2 Directory Structure (7) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml Actual classes for the providing of business services. .arr (axis archive) files reside here. Master of Information System Management

  13. Axis2 Directory Structure (8) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml MyCoolService META-INF Package path to .class Exploded directory format services.xml Master of Information System Management

  14. Axis2 Directory Structure (9) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml MyCoolService META-INF Package path to .class Defines the service name. Defines scope,e.g., “application”. Associates MEPs with receivers. Path to service classes. services.xml Master of Information System Management

  15. Axis2 Directory Structure (10) webapps axis2 axis2-web WEB-INF classes conf lib modules services web.xml Apache Axis2 is a J2EE web application. The axis2 servlet is referred to in this file. Master of Information System Management

  16. Message Life Cycle Master of Information System Management

  17. Axis2 Components Master of Information System Management

  18. SOAP Processing (1) Handlers run within phases. Both pipes have default phases and have user phase extensibility. Transport may be HTTP or JMS, etc. Out pipe In pipe Master of Information System Management

  19. SOAP Processing (2) The handlers can be registered in global, service, or operation scopes and the final handler chain is calculated combining the handlers from all the scopes.Usually, the handlers operate on the SOAP headers. The receiver or sender may be on the client or the server. Master of Information System Management

  20. Processing Model User Application Client API Handlers Transport sender network Service Handlers Handlers Transport listener • Each phase is a collection of handlers. • We can control which handler goes into which phase and the order • of execution within phases. • Handlers are defined in “modules”. E.g., Rampart is a • WS-Security module. WS-Adressing is found within • webapps/axis2/WEB-INF/modules/addressing-1.1.1.mar Master of Information System Management

  21. Default Processing Model User Application Client API Transport sender network Service Message Receiver Dispatcher selects application Transport listener • Dispatcher finds the service and operation described in the SOAP message. • - Services are placed behind Tomcat in WEB-INF/services. • - Modules are placed behind Tomcat in WEB-INF/modules Master of Information System Management

  22. Incoming Message Phases • Transport Phase - The handlers are in the phase meant to process transport specific information such as validating incoming message by looking at various transport headers, add data into message context etc. • Pre-Dispatch Phase- The main functionality of the handlers in this phase is to populate message context in order to do the dispatching. As an example, processing of addressing headers of the SOAP message, if any, happen in this phase. Addressing handlers extract information and put them in to the message context. • Dispatch Phase - The Dispatchers run in this phase and tries to find the correct service and operation this particular message is destined to. The post condition of the dispatch phase (any phase can contain a post condition) checks whether a service and an operation was found by the dispatchers. If not the execution will halt and throws out a "service not found error". • User Defined Phases - Users are allowed to engage their custom handlers here. • Message Validation Phase - Once the user level execution has taken place this phase validates whether SOAP Message Processing has taken place correctly. • Message Processing Phase - The Business logic of the SOAP message is executed here. A Message Receiver is registered with each Operation. This Message receiver (associated to the particular operation) will be executed as the last Handler of this phase. Master of Information System Management

  23. Outgoing Message Phases • Message Initialize Phase - First phase of the Out Pipe. Serves as the placeholder for the custom handlers • User Phases - This executes handlers in user defined phases • Transports Phase - Execute any transport handlers taken from the associated transport configuration. The last handler would be a transport sender which would send the SOAP message to the target endpoint. Master of Information System Management

  24. Blocking and Non-Blocking Clients • When the client sends a message, the application may wait to receive a response before moving on. • Or, it may simply send a message and move on (after, perhaps, specifying a callback action to be completed when the response is received.) Master of Information System Management

  25. R/W The XML Through Objects • WSDL is used to generate client side stub code. • The Eclipse code generation wizard permits two types of data binding: ADB Axis2 Data Binding XMLBeans Data binding • JiBX is new, not part of axis2, but may also be used. Master of Information System Management

  26. R/W The XML Through Objects ADB Axis2 Data Binding Generates a main stub with many inner classes. Not a full schema compiler. Easy and best for simple calls. XMLBeans data binding Generates many classes. A full schema compiler. Harder but more versatile. XML data binding is the process of mapping objects to XML. Both JAXB and XMLBeans read XSDL and generate Java classes. JiBX and Castor XML are other examples. Master of Information System Management

  27. Example From The Axis2 User Guide • The WSDL document of a service. • Client code using ADB. • Client code using XMLBeans. Master of Information System Management

  28. WSDL <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://apache.org/axis2/Axis2UserGuide" xmlns:intf="http://apache.org/axis2/Axis2UserGuide" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://apache.org/axis2/Axis2UserGuide"> Master of Information System Management

  29. WSDL makes use of XSDL. <wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://apache.org/axis2/Axis2UserGuide" xmlns="http://www.w3.org/2001/XMLSchema"> <!-- ELEMENTS --> <element name="DoInOnlyRequest"> <complexType> <sequence> <element name="messageString" type="xsd:string"/> </sequence> </complexType> </element> Namespaces will be used. XSDL standard type. Master of Information System Management

  30. <element name="TwoWayOneParameterEchoRequest"> <complexType> <sequence> <element name="echoString" type="xsd:string"/> </sequence> </complexType> </element> <element name="TwoWayOneParameterEchoResponse"> <complexType> <sequence> <element name="echoString" type="xsd:string"/> </sequence> </complexType> </element> Request and response elements are defined. Master of Information System Management

  31. <element name="NoParametersRequest"> <complexType/> </element> <element name="NoParametersResponse"> <complexType/> </element> <element name="MultipleParametersAddItemRequest"> <complexType> <sequence> <element name="itemId" type="xsd:int"/> <element name="itemName" type="xsd:string"/> <element name="price" type="xsd:float"/> <element name="description" type="xsd:string"/> </sequence> </complexType> </element> A request with several parts. Master of Information System Management

  32. A response with two parts. <element name="MultipleParametersAddItemResponse"> <complexType> <sequence> <element name="itemId" type="xsd:int"/> <element name="successfulAdd" type="xsd:boolean"/> </sequence> </complexType> </element> </schema> </wsdl:types> Master of Information System Management

  33. Messages are defined as for input or output and are made up of elements previously defined. <!-- MESSAGES --> <wsdl:message name="DoInOnlyRequestMessage"> <wsdl:part name="input" element="impl:DoInOnlyRequest"/> </wsdl:message> <wsdl:message name= "TwoWayOneParameterEchoRequestMessage"> <wsdl:part name="input" element="impl:TwoWayOneParameterEchoRequest"/> </wsdl:message> <wsdl:message name= "TwoWayOneParameterEchoResponseMessage"> <wsdl:part name="output" element="impl:TwoWayOneParameterEchoResponse"/> </wsdl:message> Master of Information System Management

  34. <wsdl:message name="NoParametersRequestMessage"> <wsdl:part name="input" element="impl:NoParametersRequest"/> </wsdl:message> <wsdl:message name="NoParametersResponseMessage"> <wsdl:part name="output" element="impl:NoParametersResponse"/> </wsdl:message> <wsdl:message name="MultipleParametersAddItemRequestMessage"> <wsdl:part name="input" element="impl:MultipleParametersAddItemRequest"/> </wsdl:message> <wsdl:message name="MultipleParametersAddItemResponseMessage"> <wsdl:part name="output" element="impl:MultipleParametersAddItemResponse"/> </wsdl:message> Master of Information System Management

  35. An interface is a collection of operations with inputs and outputs. <!-- Port type (interface) --> <wsdl:portType name="Axis2UserGuidePortType"> <wsdl:operation name="DoInOnly" parameterOrder="input"> <wsdl:input name="DoInOnlyRequestMessage" message="impl:DoInOnlyRequestMessage"/> </wsdl:operation> <wsdl:operation name= "TwoWayOneParameterEcho" parameterOrder="input"> <wsdl:input name="TwoWayOneParameterEchoRequestMessage" message="impl:TwoWayOneParameterEchoRequestMessage"/> <wsdl:output name="TwoWayOneParameterEchoResponseMessage" message="impl:TwoWayOneParameterEchoResponseMessage"/> </wsdl:operation> Master of Information System Management

  36. <wsdl:operation name="NoParameters" parameterOrder="input"> <wsdl:input name="NoParametersRequestMessage" message="impl:NoParametersRequestMessage"/> <wsdl:output name="NoParametersResponseMessage" message="impl:NoParametersResponseMessage"/> </wsdl:operation> <wsdl:operation name="MultipleParametersAddItem" parameterOrder="input"> <wsdl:input name="MultipleParametersAddItemRequestMessage" message="impl:MultipleParametersAddItemRequestMessage"/> <wsdl:output name="MultipleParametersAddItemResponseMessage" message="impl:MultipleParametersAddItemResponseMessage"/> </wsdl:operation> </wsdl:portType> Master of Information System Management

  37. The SOAP messages may be constructed in several ways. Here we make our selections. Style may be rpc or document. Use may be literal or encoded. Document/Literal includes no type information within the SOAP (literal) and the content of <!-- BINDING (bind operations) --> <wsdl:binding name="Axis2UserGuideSoapBinding" type="impl:Axis2UserGuidePortType"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="DoInOnly"> <wsdlsoap:operation soapAction="DoInOnly"/> <wsdl:input> <wsdlsoap:body use="literal"/> </wsdl:input> </wsdl:operation> the SOAP body may be validated (document). Master of Information System Management

  38. <wsdl:operation name="TwoWayOneParameterEcho"> <wsdlsoap:operation soapAction="TwoWayOneParameterEcho"/> <wsdl:input> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="NoParameters"> <wsdlsoap:operation soapAction="NoParameters"/> <wsdl:input> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> Master of Information System Management

  39. <wsdl:operation name="MultipleParametersAddItem"> <wsdlsoap:operation soapAction="MultipleParametersAddItem"/> <wsdl:input> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> Master of Information System Management

  40. <!-- SERVICE --> <wsdl:service name="Axis2UserGuideService"> <wsdl:port binding="impl:Axis2UserGuideSoapBinding" name="Axis2UserGuide"> <wsdlsoap:address location= "http://localhost:8080/axis2/services/Axis2UserGuide"/> </wsdl:port> </wsdl:service> </wsdl:definitions> The service location. Master of Information System Management

  41. Client Using ADB package org.apache.axis2.axis2userguide; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.DoInOnlyRequest; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.TwoWayOneParameterEchoRequest; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.NoParametersRequest; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.MultipleParametersAddItemRequest; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.TwoWayOneParameterEchoResponse; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.NoParametersResponse; import org.apache.axis2.axis2userguide.Axis2UserGuideServiceStub.MultipleParametersAddItemResponse; The request and response messages appear as inner classes of the generated stub. Master of Information System Management

  42. public class Client{ public static void main(java.lang.String args[]){ try{ Axis2UserGuideServiceStub stub = new Axis2UserGuideServiceStub ("http://localhost:8080/axis2/services/Axis2UserGuideService"); doInOnly(stub); twoWayOneParameterEcho(stub); noParameters(stub); multipleParameters(stub); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Master of Information System Management

  43. /* do in only */ public static void doInOnly(Axis2UserGuideServiceStub stub){ try{ DoInOnlyRequest req = new DoInOnlyRequest(); req.setMessageString("An in only request"); stub.DoInOnly(req); System.out.println("done"); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } This request class was imported as an inner class of the stub. Here we populate the request. DoInOnly is a method of the stub class. Master of Information System Management

  44. /* two way call/receive */ public static void twoWayOneParameterEcho(Axis2UserGuideServiceStub stub){ try{ TwoWayOneParameterEchoRequest req = new TwoWayOneParameterEchoRequest(); req.setEchoString("echo! ... echo!"); TwoWayOneParameterEchoResponse res = stub.TwoWayOneParameterEcho(req); System.out.println(res.getEchoString()); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Note the pattern: Build a request and pass it to the appropriate method of the stub class. A response message may be returned. Master of Information System Management

  45. /* No parameters */ public static void noParameters(Axis2UserGuideServiceStub stub){ try{ NoParametersRequest req = new NoParametersRequest(); System.out.println(stub.NoParameters(req)); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Master of Information System Management

  46. /* multiple parameters */ public static void multipleParameters(Axis2UserGuideServiceStub stub){ try{ MultipleParametersAddItemRequest req = new MultipleParametersAddItemRequest(); req.setPrice((float)1.99); req.setItemId((int)23872983); req.setDescription("Must have for cooking"); req.setItemName("flour"); MultipleParametersAddItemResponse res = stub.MultipleParametersAddItem(req); System.out.println(res.getSuccessfulAdd()); System.out.println(res.getItemId()); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } } Same pattern. Two values returned. Master of Information System Management

  47. Client Using XMLBeans The SOAP on the wire is the same. This is approach is more document oriented. package org.apache.axis2.axis2userguide; public class Client{ public static void main(java.lang.String args[]){ try{ Axis2UserGuideServiceStub stub = new Axis2UserGuideServiceStub ("http://localhost:8080/axis2/services/Axis2UserGuideService"); doInOnly(stub); twoWayOneParameterEcho(stub); noParameters(stub); multipleParameters(stub); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Master of Information System Management

  48. /* fire and forget */ public static void doInOnly(Axis2UserGuideServiceStub stub){ try{ DoInOnlyRequestDocument req = DoInOnlyRequestDocument.Factory.newInstance(); DoInOnlyRequestDocument.DoInOnlyRequest data = req.addNewDoInOnlyRequest(); data.setMessageString("fire and forget it!"); stub.DoInOnly(req); System.out.println("done"); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } The request document is got from a factory. It’s populated with data. The stub has a DoInOnly method taking a DoInOnlyRequestDocument. Master of Information System Management

  49. /* two way call/receive */ public static void twoWayOneParameterEcho(Axis2UserGuideServiceStub stub){ try{ TwoWayOneParameterEchoRequestDocument req = TwoWayOneParameterEchoRequestDocument.Factory.newInstance(); TwoWayOneParameterEchoRequestDocument.TwoWayOneParameterEchoRequest data = req.addNewTwoWayOneParameterEchoRequest(); data.setEchoString("echo! ... echo!"); TwoWayOneParameterEchoResponseDocument res = stub.TwoWayOneParameterEcho(req); System.out.println(res.getTwoWayOneParameterEchoResponse().getEchoString()); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Same pattern but the response document is got from the call. Master of Information System Management

  50. /* No parameters */ public static void noParameters(Axis2UserGuideServiceStub stub){ try{ NoParametersRequestDocument req = NoParametersRequestDocument.Factory.newInstance(); NoParametersRequestDocument.NoParametersRequest data = req.addNewNoParametersRequest(); System.out.println(stub.NoParameters(req)); } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } } Master of Information System Management

More Related