Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Apache SOAP and the Java API for XML Messaging (JAXM) Notes from the Axis User’s Guide and the books “Java Web Services” by Deitel and “Distributed Systems.

Similar presentations


Presentation on theme: "1 Apache SOAP and the Java API for XML Messaging (JAXM) Notes from the Axis User’s Guide and the books “Java Web Services” by Deitel and “Distributed Systems."— Presentation transcript:

1 1 Apache SOAP and the Java API for XML Messaging (JAXM) Notes from the Axis User’s Guide and the books “Java Web Services” by Deitel and “Distributed Systems Concepts and Design” by Coulouris

2 2 Middleware layers Applications Middleware layers Request reply protocol External data representation Operating System RMI, RPC and events

3 3 Remote and local method invocations invocation remote invocation remote local invocation A B C D E F

4 4 A remote object and its remote interface interface remote m1 m2 m3 m4 m5 m6 Data implementation remoteobject { of methods

5 5 Invocation semantics Fault tolerance measures Invocation semantics Retransmit request message Duplicate filtering Re-execute procedure or retransmit reply No Yes Not applicable No Yes Not applicable Re-execute procedure Retransmit replyAt-most-once At-least-once Maybe

6 6 The role of proxy and skeleton in remote method invocation object A object B skeleton Request proxy for B Reply Communication Remote Remote reference Communication module reference module module for B’s class & dispatcher remote client server

7 7 What is SOAP? XML-based communication protocol XML-based encoding format Supports inter-application communication Cross platform Cross Language

8 8 What is Axis? Apache Extensible Integration System Axis began as IBM’s SOAP4J A Framework for constructing SOAP clients and servers Written in Java

9 9 Who competes with Axis? CapeConnect from CapeClear GLUE Standard from MindElectric Orbix E2A XMLBus 5.2 From IONA WASP Server for Java 4.0 from Systinet

10 10 Axis Architecture Client Transport Listener Provider Java Class Message Handlers

11 11 Axis WSDL Support The Web Service Description Language is a machine readable description of a web service Given a WSDL document generate communication stubs (WSDL2Java) Given a Java based web services generate WSDL (Java2WSDL)

12 12 WSDL An Interface Definition Language (IDL) Java RMI uses Java Remote Interfaces An IDL is needed when languages differ Other example IDL’s Corba IDL (Object-oriented syntax) OSF’s DCE (C like syntax) DCOM IDL based on OSF’s DCE and used by Microsoft’s DCOM Sun XDR (An IDL for RPC)

13 13 CORBA IDL example // In file Person.idl struct Person { string name; string place; long year; } ; interface PersonList { readonly attribute string listname; void addPerson(in Person p) ; void getPerson(in string name, out Person p); long number(); };

14 14 File interface in Sun XDR (Originally External Data Representation but now an IDL) const MAX = 1000; typedef int FileIdentifier; typedef int FilePointer; typedef int Length; struct Data { int length; char buffer[MAX]; }; struct writeargs { FileIdentifier f; FilePointer position; Data data; }; struct readargs { FileIdentifier f; FilePointer position; Length length; }; program FILEREADWRITE { version VERSION { void WRITE(writeargs)=1; // procedure Data READ(readargs)=2; // numbers }=2; // version number } = 9999; // program number // numbers passed in request message // rpcgen is the interface compiler

15 15 WSDL Given a Description of a service (WSDL document) Axis uses wsdl2java to create the client code Given a Java service, Axis uses java2wsdl to generate a description (WSDL document) wsdl2java is an interface compiler

16 16 Example Client import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; public class Client { public static void main(String [] args) { try { if(args.length != 2) { System.out.println("usage:java Client BigInt BigInt"); System.exit(-1); }

17 17 Service service = new Service(); Call call = (Call) service.createCall(); // hold data about the service call.setTargetEndpointAddress( new java.net.URL("http://localhost:8080/axis/servlet/AxisServlet") ); call.setOperationName( new QName("BigCalculatorService", "add") ); call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter( "arg2", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING ); // This code does not look like normal // application code!

18 18 String ret = (String) call.invoke( new Object[] { args[0],args[1] } ); System.out.println("The BigCalculator Service computed : " + ret); } catch (Exception e) { System.err.println(e.toString()); }

19 19 On The Server // copy compiled code to the axis/WEB-INF/classes directory import java.math.*; public class BigCalculator { public String add(String i1, String i2) { BigInteger x = new BigInteger(i1); BigInteger y = new BigInteger(i2); return new String(x.add(y).toString()); } public String subtract(String i1, String i2) { BigInteger x = new BigInteger(i1); BigInteger y = new BigInteger(i2); return new String(x.subtract(y).toString()); } //This code does not look //like normal server side Java!

20 20 public static void main(String args[]) { BigCalculator bc = new BigCalculator(); String a = bc.add("9999999999999","1"); System.out.println(a); } STEPS : javac BigCalculator.java Copy BigCalculator.class to D:\jwsdp-1.2\webapps\axis\WEB-INF\classes Startup Tomcat adminclient deploy.wsdd java org.apache.axis.client.AdminClient deploy.wsdd Processing file deploy.wsdd Done processing

21 21 Web Service Deployment <!-- tell axis about this deployment with java org.apache.axis.client.AdminClient deploy.wsdd --> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

22 22 java Client 1 999999999999999999999999999999999 The BigCalculator Service computed : 10000000000000000000000000000000 But it works.

23 23 SOAP To Server POST /axis/servlet/AxisServlet HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.1 Host: 127.0.0.1 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 520 <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">

24 24 <ns1:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="BigCalculatorService"> 1 999999999999999999999999999999999999999999

25 25 SOAP Back To Client HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Date: Mon, 27 Oct 2003 22:48:01 GMT Server: Apache-Coyote/1.1 Connection: close <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">

26 26 <ns1:addResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="BigCalculatorService"> <ns1:addReturn xsi:type="xsd:string"> 1000000000000000000000000000000000000000000

27 27 Use WSDL2Java From the WSDL document we can generate client side code The WSDL document describes the method names and variable types WSDL2Java is very much like rmic in Java RMI It allows application programmers to think about applications rather than distributed systems

28 28 Code Generation using WSDL java org.apache.axis.wsdl.WSDL2Java bigcalc.wsdl localhost └───axis └───services └───BigCalculatorService BigCalculator.java BigCalculatorService.java BigCalculatorServiceLocator.java BigCalculatorServiceSoapBindingStub.java

29 29 BigCalcClient.java import localhost.axis.services.BigCalculatorService.*; public class BigCalcClient { public static void main(String args[]) throws Exception { BigCalculatorService bs = new BigCalculatorServiceLocator(); BigCalculator bc = bs.getBigCalculatorService(); String a = new String("1"); String b = new String("9999999999999999"); String c = bc.add(a,b); System.out.println(c); } java BigCalcClient 10000000000000000 // This code looks like // application code

30 30 But We Are Still Working With Strings Create a server class that works with BigIntegers and not Strings Place it behind Axis under Tomcat Generate the WSDL The client uses the WSDL to generate the client side code Write the client code

31 31 import java.math.*; // Server Code // Working with BigIntegers public class BigCalculatorBigInt { public BigInteger add(BigInteger i1, BigInteger i2) { return i1.add(i2); } public BigInteger subtract(BigInteger i1, BigInteger i2) { return i1.subtract(i2); }

32 32 public static void main(String args[]) { BigCalculatorBigInt bc = new BigCalculatorBigInt(); BigInteger a = bc.add( new BigInteger("9999999999999"), new BigInteger("1")); System.out.println(a); }

33 33 Write the Client import localhost.axis.services.BigCalculatorBigIntegerService.*; import java.math.*; public class BigCalcClient { public static void main(String args[]) throws Exception { BigCalculatorBigIntService bs = new BigCalculatorBigIntServiceLocator(); BigCalculatorBigInt bc = bs.getBigCalculatorBigIntegerService();

34 34 BigInteger a = new BigInteger("1"); BigInteger b = new BigInteger("9999999999999999"); BigInteger c = bc.add(a,b); System.out.println(c); } // Looks even better!

35 35 SOAP To Server POST /axis/services/BigCalculatorBigIntegerService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.1 Host: 127.0.0.1 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 487

36 36 <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"> <ns1:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://DefaultNamespace"> 1 9999999999999999 There are 44 simple types available in the XMLShema namespace Integer is defined as an arbitrarily long integer

37 37 SOAP To Client HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Date: Tue, 28 Oct 2003 00:04:51 GMT Server: Apache-Coyote/1.1 Connection: close <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"> <ns1:addResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://DefaultNamespace"> 10000000000000000

38 38 Events and Notifications Examples of the local event model -- a keystroke causes an interrupt handler to execute storing a key character in the keyboard buffer -- a mouse click causes an interrupt handler to call a registered listener to handle the mouse event

39 39 Distributed Event Based Systems Suppose the whiteboard server is willing to make calls to all registered clients when the drawing is changed by any one client Clients may subscribe to this service (register interest) The whiteboard server publishes the events that it will make available to clients This is the publish-subscribe paradigm

40 40 Two Characteristics of Distributed Event Based Systems (1) Heterogeneous -- event generators publish the types of events they offer -- other objects subscribe and provide callable methods -- components that were not designed to work together may interoperate

41 41 Two Characteristics of Distributed Event Based Systems (2) Asynchronous -- Publishers and subscribers are decoupled -- notifications of events are sent asynchronously to all subscribers

42 42 Dealing room system

43 43 Architecture for distributed event notification subscriberobserverobject of interest Event service object of interest observer subscriber 3. 1. 2. notification Next Topic ….JAXM and Asynchronous Messaging….


Download ppt "1 Apache SOAP and the Java API for XML Messaging (JAXM) Notes from the Axis User’s Guide and the books “Java Web Services” by Deitel and “Distributed Systems."

Similar presentations


Ads by Google