AK 3 web services using apache axis

1,606 views
1,474 views

Published on

Web Services using Apache Axis by Atul Kahate Sir

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,606
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
48
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

AK 3 web services using apache axis

  1. 1. Web Services Using Apache Axis Atul Kahate [email_address]
  2. 2. Background
  3. 3. Web Evolution Web Services using Apache Axis | Atul Kahate XML Programmability Connectivity HTML Presentation TCP/IP Technology Innovation FTP, E-mail, Gopher Web Pages Browse the Web Program the Web Web Services
  4. 4. Distributed Programming Web Services using Apache Axis | Atul Kahate Remote Procedure Call (RPC) Program A calls Program B remotely (different process, possibly different computer) Remote Objects Method M1 of Object A calls method M2 of Object B remotely (different process, possibly different computer)
  5. 5. Middleware <ul><li>Software that allows clients and servers to communicate with each other remotely </li></ul><ul><li>Provides a programming model above the basic building blocks of processes and message passing (i.e. above RPC/remote objects) </li></ul><ul><li>See Figure </li></ul>Web Services using Apache Axis | Atul Kahate
  6. 6. Middleware Layers Web Services using Apache Axis | Atul Kahate Applications Remote objects, RMI, and Events Request-Response protocol External data representation Operating system Middleware layers
  7. 7. Middleware Features <ul><li>Provides </li></ul><ul><ul><li>Location transparency (e.g. events are handled remotely) </li></ul></ul><ul><ul><li>Independence from communication protocol details (e.g. TCP or UDP) </li></ul></ul><ul><ul><li>Operating systems (e.g. CR-LF) </li></ul></ul><ul><ul><li>Computer hardware (e.g. Byte ordering) </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  8. 8. Interfaces <ul><li>In order to control the possible interactions between modules, an explicit interface is defined for each module </li></ul><ul><li>Interface of a module = Procedures + Variables that can be accessed from other modules </li></ul><ul><ul><li>Everything else is hidden inside </li></ul></ul><ul><ul><li>Implementation can change, but not interface </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  9. 9. Web Service - Details
  10. 10. Web Services Versus HTTP Web Services using Apache Axis | Atul Kahate Client-server programming Programs with specific function in mind HTTP based communication Generic functionality accessed using a browser Web Services Specific functionality accessed using HTTP
  11. 11. Web Server versus Web Service Web Services using Apache Axis | Atul Kahate Web Server Provides basic HTTP service Web Service Provides a service based on operations defined in its interface
  12. 12. Web Services Terminology <ul><li>Web Services expose useful functionality to Web users through a standard Web protocol. In most cases, the protocol used is SOAP . </li></ul><ul><li>Web services provide a way to describe their interfaces in enough detail to allow a user to build a client application to talk to them. This description is usually provided in an XML document called a Web Services Description Language ( WSDL ) document. </li></ul><ul><li>Web services are registered so that potential users can find them easily. This is done with Universal Discovery Description and Integration ( UDDI ). </li></ul>Web Services using Apache Axis | Atul Kahate
  13. 13. Why Web Services? <ul><li>Suppose we want to provide a service to the general public or some business partners </li></ul><ul><ul><li>They will send us two strings, which we will concatenate and send back </li></ul></ul><ul><li>Different users may be using different languages (Java and C#) </li></ul><ul><li>Their platforms may differ (Windows, Linux) </li></ul><ul><li>There may be firewalls in-between </li></ul><ul><li>We can use a Web service to deal with this </li></ul>Web Services using Apache Axis | Atul Kahate
  14. 14. How to do it? <ul><li>Suppose our URL is www.ttdev.com </li></ul><ul><li>We can create a Web service named SimpleService </li></ul><ul><li>The URL would be www.ttdev.com/SimpleService (called as the end point of the Web service) </li></ul><ul><li>A Web service can support one or more operations </li></ul><ul><ul><li>The operation can be concat , in this case </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  15. 15. Web Service Concept Web Services using Apache Axis | Atul Kahate A Web server running at http://www.ttdev.com A Web service running at the path /SimpleService An operation An operation Name: concat Name: … Full path of the Web service is http://www/ttdev.com/SimpleService
  16. 16. Assigning Namespace <ul><li>We need to assign a namespace to make our operation globally unique </li></ul><ul><li>Suppose we decide on http://www/ttdev.com/ss </li></ul><ul><li>Then, </li></ul><ul><ul><li>Local name = concat </li></ul></ul><ul><ul><li>Qualified name (QName) = http://www/ttdev.com/ss /concat </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  17. 17. Web Service Styles RPC Style Document Style
  18. 18. Our Example Web Service <ul><li>Our Web service is supposed to accept two strings (s1, s2) and return another </li></ul>Web Services using Apache Axis | Atul Kahate Operation concat Local name: concat Namespace: http://www.ttdev.com/ss Parameters: s1: string s2: string Return: string
  19. 19. RPC Style Web Services
  20. 20. Dealing with Data Types <ul><li>What do the strings mean now? Are they Java strings? </li></ul><ul><li>No – because, Web services are language neutral </li></ul><ul><li>Hence, we must be able to map these to a neutral format </li></ul><ul><ul><li>That neutral format happens to be the various data types defined by XML schema specifications </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  21. 21. Data Types Refined Web Services using Apache Axis | Atul Kahate Operation concat Local name: concat Namespace: http://www.ttdev.com/ss Parameters: s1: string in http://www.w3.org/2001/XMLSchema s2: string in http://www.w3.org/2001/XMLSchema Return: string in http://www.w3.org/2001/XMLSchema
  22. 22. “ Messages” and “Parts” <ul><li>In Web services: </li></ul><ul><ul><li>Method call = Input message </li></ul></ul><ul><ul><li>Parameter = Part </li></ul></ul><ul><ul><li>Return value = Output message </li></ul></ul><ul><li>Let us modify our operation based on these concepts </li></ul>Web Services using Apache Axis | Atul Kahate
  23. 23. Adding Messages and Parts Web Services using Apache Axis | Atul Kahate Operation concat Local name: concat Namespace: http://www.ttdev.com/ss Input message: Part 1: Name: s1 Type: string in http://www.w3.org/2001/XMLSchema Part 2: Name: s2 Type: string in http://www.w3.org/2001/XMLSchema Output message: Part 1: Name: return Type: string in http://www.w3.org/2001/XMLSchema
  24. 24. Calling Web service <ul><li>When someone calls our Web service, they can send us an XML element as the input message, such as: </li></ul>Web Services using Apache Axis | Atul Kahate <test:concat xmlns:test= http://ttdev.com/ss > <s1>abc</s1> <s2>123</s2> </test:concat>
  25. 25. Responding back from a Web service <ul><li>In response, we can send the following XML message back to the caller: </li></ul>Web Services using Apache Axis | Atul Kahate <test:output xmlns:test= http://ttdev.com/ss > abc123 </test:output>
  26. 26. What is “RPC” here? <ul><li>The QName and the names of the parts are used to create the input message </li></ul>Web Services using Apache Axis | Atul Kahate <test:concat xmlns:test= http://ttdev.com/ss > <s1>abc</s1> <s2>123</s2> </test:concat> QName Namespace prefix Parts Input message
  27. 27. Document Style Web Services
  28. 28. What is the difference? <ul><li>RPC and Document style Web services generally differ on two counts: </li></ul><ul><ul><li>In document style Web services, input parameters are not sent as different parts; but instead they are combined into a single part </li></ul></ul><ul><ul><li>There is an XML schema to validate the part </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  29. 29. Document Style Web Service Web Services using Apache Axis | Atul Kahate Operation concat Local name: concat Namespace: http://www.ttdev.com/ss Input message: Part 1: Name: concatRequest Element: Output message: Part 1: Name: concatResponse Type: string in http://www.w3.org/2001/XMLSchema <xsd:schema targetNamespace = ”http://www.ttdev.com/ss” xmlns:xsd = ”http://www.w3.org/2001/XMLSchema”> <xsd:element name = “concatRequest”> <xsd:complexType> <xsd:sequence> <xsd:element name = “s1” type = “xsd:string” /> <xsd:element name = “s2” type = “xsd:string” /> <xsd:sequence> <xsd:complexType> </xsd:element> </xsd:schema> <test:concatRequest xmlns:test=”http://www.ttdev.com/ss”> <s1>abc</s1> <s2>123</s2> </test:concatRequest> Operation details XML schema Sample message
  30. 30. Sample Return (Output) Message Web Services using Apache Axis | Atul Kahate <test:concatResponse xmlns:test = “http://www.ttdev.com/ss” xmlns:xsd = “http://www.w3.org/2001/XMLSchema” xmlns:xsi = “http://www/w3.org/2001/XMLSchema-Instance” xsi:type = “xsd:string”> abc123 </test:concatRespnose> Indicates that the return type is string, which is defined in the Schema-Instance namespace
  31. 31. Using Port types
  32. 32. Port Types <ul><li>Port Type allows us to combine several operations </li></ul><ul><ul><li>This port has nothing to do with the network ports – these are completely different concepts! </li></ul></ul><ul><li>We can consider the following: </li></ul><ul><ul><li>Port = Class </li></ul></ul><ul><ul><li>Operation = Static method within the class </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  33. 33. Using Port Types Web Services using Apache Axis | Atul Kahate Web service Port type Local name: StringUtil Namespace: http://ttdev.com/ss Operation Local name: concat Namespace: http://ttdev.com/ss … Operation Local name: separate Namespace: http://ttdev.com/ss … Schema … Port type Local name: DateUtil Namespace: http://ttdev.com/ss Operation Local name: getDifference Namespace: http://ttdev.com/ss … Operation Local name: convertFormat Namespace: http://ttdev.com/ss …
  34. 34. Binding
  35. 35. What is Binding? <ul><li>A port type may allow us to access it using various message formats/protocols; e.g. </li></ul><ul><ul><li>XML RPC/Document style as seen earlier (called as Simple Object Access Protocol or SOAP ) </li></ul></ul><ul><ul><li>Text format </li></ul></ul><ul><ul><ul><li>concat (s1 = “abc”, s2 = “123) </li></ul></ul></ul><ul><ul><li>HTTP request </li></ul></ul><ul><ul><li>Email </li></ul></ul><ul><li>Each of these is called as binding </li></ul>Web Services using Apache Axis | Atul Kahate
  36. 36. Web Services using Apache Axis | Atul Kahate Web service Schema … Port type: stringUtil concat … Binding Name: binding_1 Port type: stringUtil Format: SOAP Transport: HTTP Binding Name: binding_2 Port type: stringUtil Format: TEXT Transport: SMTP Example POST http://www.ttdev.com/ss/abc <concatRequest> <s1>abc</s1> <s2>123</s2> </concatRequest> Example FROM: user@mydomain.com TO: … concat (s1 = “abc”, s2 = “123”)
  37. 37. Which Binding should we use? <ul><li>SOAP/HTTP is most common </li></ul><ul><li>We can use it almost everywhere </li></ul><ul><li>It means that </li></ul><ul><ul><li>The underlying protocol for traffic is HTTP </li></ul></ul><ul><ul><li>The message format is a layer over HTTP, called as SOAP </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  38. 38. More on Ports <ul><li>Suppose that too many people are trying to access our Web service </li></ul><ul><li>Hence, we decide to make it available on more than one computer </li></ul><ul><li>Example </li></ul><ul><ul><li>Binding 1 on computers c1, c2, and c3 </li></ul></ul><ul><ul><li>Binding 2 on computer c3 </li></ul></ul><ul><ul><li>Hence, we have four ports (three using binding 1 and another one using binding 2) </li></ul></ul><ul><li>Meaning: Requests received by these three computers will be forwarded to a computer hiding behind for processing? NO </li></ul><ul><li>Instead, it means that some software implements the port types installed on these computers </li></ul>Web Services using Apache Axis | Atul Kahate
  39. 39. Web Services using Apache Axis | Atul Kahate Web service Schema … Port type: stringUtil concat … Binding Name: binding_1 Port type: stringUtil Format: SOAP Transport: HTTP Binding Name: binding_2 Port type: stringUtil Format: TEXT Transport: SMTP Deployed on Port 1 Deployed on Port 2 Deployed on Port 3 Port 4 C1 C2 C3
  40. 40. Adding Details to Ports <ul><li>To tell others about port details, we need to add the port specifications to our Web services interface </li></ul>Web Services using Apache Axis | Atul Kahate
  41. 41. Web Services using Apache Axis | Atul Kahate Web service Schema … Port type: stringUtil concat … Binding Name: binding_1 Port type: stringUtil Format: SOAP Transport: HTTP Binding Name: binding_2 Port type: stringUtil Format: TEXT Transport: SMTP Port Name: Port 1 Binding: Endpoint: … Port Name: Port 2 Binding: Endpoint: … Port Name: Port 3 Binding: Endpoint: … Deployed on Name: Port 4 Binding: Endpoint: …
  42. 42. Target Namespace <ul><li>Specifies the URL where our Web service resides </li></ul>Web Services using Apache Axis | Atul Kahate
  43. 43. Web Services using Apache Axis | Atul Kahate Web service Target namespace: http://ttdev.com/ss Schema … Port type: stringUtil concat … Binding Name: binding_1 Port type: stringUtil Format: SOAP Transport: HTTP Binding Name: binding_2 Port type: stringUtil Format: TEXT Transport: SMTP Port Name: Port 1 Binding: Endpoint: … Port Name: Port 2 Binding: Endpoint: … Port Name: Port 3 Binding: Endpoint: … Deployed on Name: Port 4 Binding: Endpoint: …
  44. 44. WSDL <ul><li>We have just finished describing the interface of our Web service in a language called as Web Services Description Language (WSDL) . </li></ul>Web Services using Apache Axis | Atul Kahate
  45. 45. Summary Web Services using Apache Axis | Atul Kahate Service Port PortType Operation Message Message Operation Message Message Binding Port PortType Operation Message Message Operation Message Message Binding
  46. 46. WSDL and Java Web Services using Apache Axis | Atul Kahate WSDL portType Java Interface <portType name=”BookQuote”> public interface BookQuote { <operation name=”GetBookPrice”> <input name=”isbn” message=”GetBookPriceRequest”/> <output name=”price” message=”GetBookPriceResponse”/> </operation> public float getBookPrice (String isbn); <operation name=”GetBulkBookPrice”> <input name=”request” message=”GetBulkBookPriceRequest”/> <output name=”prices” message=”GetBulkBookPriceResponse”/> </operation> public float getBulkBookPrice (String isbn, int quantity); <operation name=”GetBookISBN”> <input name=”title” message=”GetBulkBookISBNRequest”/> <output name=”isbn” message=”GetBulkBookISBNResponse”/> </operation> public String getBookISBN (String bookTitle); </portType> }
  47. 47. Overview of SOAP
  48. 48. SOAP Message Structure Web Services using Apache Axis | Atul Kahate Envelope Header Header element Header element Body Body element Body element
  49. 49. SOAP Example – Request <ul><li><env:Envelope xmlns:env=&quot;http://www.w3.org/2001/06/soap-envelope&quot;> </li></ul><ul><li><env:Body> </li></ul><ul><li><m: ValidatePostcode env:encodingStyle=&quot;http://www.w3.org/2001/06/soap-encoding&quot; </li></ul><ul><li>xmlns:m=&quot;http://www.somesite.com/Postcode&quot;> </li></ul><ul><li><Postcode>WC1A8GH</Postcode> </li></ul><ul><li><Country>UK</Country> </li></ul><ul><li></m:ValidatePostcode> </li></ul><ul><li></env:Body> </li></ul><ul><li></env:Envelope> </li></ul>Web Services using Apache Axis | Atul Kahate
  50. 50. SOAP Example – Response <ul><li><env:Envelope </li></ul><ul><li>xmlns:env=&quot;http://www.w3.org/2001/06/soap-envelope&quot; > </li></ul><ul><li><env:Body> </li></ul><ul><li><m: ValidatePostcodeResponse </li></ul><ul><li>env:encodingStyle=&quot;http://www.w3.org/2001/06/soap-encoding&quot; </li></ul><ul><li>xmlns:m=&quot;http://www.somesite.com/Postcode&quot;> </li></ul><ul><li><Valid>Yes</Valid> </li></ul><ul><li></m:ValidatePostcodeResponse> </li></ul><ul><li></env:Body> </li></ul><ul><li></env:Envelope> </li></ul>Web Services using Apache Axis | Atul Kahate
  51. 51. Web Services using Apache Axis
  52. 52. How Axis Works Web Services using Apache Axis | Atul Kahate
  53. 53. What is Apache Axis? <ul><li>AXIS is a SOAP engine </li></ul><ul><li>Allows creation and processing of SOAP messages </li></ul><ul><li>Third generation of Apache SOAP (which began at IBM as SOAP4J) </li></ul>Web Services using Apache Axis | Atul Kahate
  54. 54. Axis History <ul><li>IBM contributed an early implementation of the SOAP protocol to Apache in 1999, which became known as Apache SOAP 2.1 </li></ul><ul><li>This was based on an earlier implementation called as SOAP4J, which was a monolithic application – difficult to modify/maintain </li></ul><ul><li>Gave way to A pache E x tensible I nteraction S ystem (AXIS), instead of being called as SOAP 3.0 </li></ul>Web Services using Apache Axis | Atul Kahate
  55. 55. Installing Axis <ul><li>Download axis-bin-1_4 .zip from http://ws.apache.org/axis </li></ul><ul><li>Download JavaMail API from http://java.sun.com/products/javamail/downloads/index.html </li></ul><ul><li>Download JavaBeans Activation Framework from http://java.sun.com/products/javabeans/glasgow/jaf.html </li></ul>Web Services using Apache Axis | Atul Kahate
  56. 56. Install Tomcat <ul><li>Download Apache Tomcat from http://jakarta.apache.org </li></ul>Web Services using Apache Axis | Atul Kahate
  57. 57. Installing Apache Axis <ul><li>From the unzipped folder above, copy the axis-1_4webappsaxis sub-folder in c:tomcatwebapps and look at the directory tree shown next </li></ul>Web Services using Apache Axis | Atul Kahate
  58. 58. Web Services using Apache Axis | Atul Kahate
  59. 59. Set AXIS_HOME <ul><li>C:tomcatwebappsaxis-1_4 </li></ul>Web Services using Apache Axis | Atul Kahate
  60. 60. Set CLASSPATH [CLASSPATH should have all the jar files (and mail.jar file) from C:tomcatwebappsaxisWEB-INFlib] <ul><li>C:tomcatwebappsaxisWEB-INFlibaxis.jar;C:tomcatwebappsaxisWEB-INFlibaxis-ant.jar;C:tomcatwebappsaxisWEB-INFlibcommons-discovery-0.2.jar;C:tomcatwebappsaxisWEB-INFlibcommons-logging-1.0.4.jar;C:tomcatwebappsaxisWEB-INFlibjaxrpc.jar;C:tomcatwebappsaxisWEB-INFliblog4j-1.2.8.jar;C:tomcatwebappsaxisWEB-INFlibsaaj.jar;C:tomcatwebappsaxisWEB-INFlibwsdl4j-1.5.1.jar;C:tomcatwebappsaxisWEB-INFlibmail.jar; </li></ul>Web Services using Apache Axis | Atul Kahate
  61. 61. Test Axis Installation <ul><li>http://localhost:8080/axis/ </li></ul><ul><li>Should see the following screen </li></ul>Web Services using Apache Axis | Atul Kahate
  62. 62. Axis Screen Web Services using Apache Axis | Atul Kahate
  63. 63. Testing Axis <ul><li>Press the first tag named Validation to test the local installation's configuration. </li></ul><ul><li>This page will list the various dependencies needed for a correct installation. </li></ul><ul><li>If there are problems, it will list them and provide solutions. </li></ul><ul><li>See next slide </li></ul>Web Services using Apache Axis | Atul Kahate
  64. 64. Web Services using Apache Axis | Atul Kahate
  65. 65. Developing the First Web Service (Hello Service)
  66. 66. Step 1: Develop the Service <ul><li>C:tomcatwebappsaxisWEB-INFclassesHelloService.java </li></ul><ul><li>public class HelloService { </li></ul><ul><li>public String getHelloMessage (){ </li></ul><ul><li>return &quot;Hello World&quot;; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Web Services using Apache Axis | Atul Kahate
  67. 67. Step 2: Develop the Client <ul><li>C:tomcatwebappsaxisWEB-INFclassesHelloServiceClient.java </li></ul><ul><li>import java.net.URL; </li></ul><ul><li>import org.apache.axis.client.Service; </li></ul><ul><li>import org.apache.axis.client.Call; </li></ul><ul><li>public class HelloServiceClient { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><li>try { </li></ul><ul><li>URL url = new URL(&quot;http://localhost:8080/axis/services/HelloService&quot;); </li></ul><ul><li>Service service = new Service(); </li></ul><ul><li>Call call = (Call)service.createCall(); </li></ul><ul><li>call.setTargetEndpointAddress(url); </li></ul><ul><li>Object result = call.invoke(&quot;getHelloMessage&quot;, new Object[]{}); </li></ul><ul><li>System.out.println(result); </li></ul><ul><li>} </li></ul><ul><li>catch(Exception exception){ </li></ul><ul><li> exception.printStackTrace(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Web Services using Apache Axis | Atul Kahate
  68. 68. Step 3: Write a Web Services Deployment Descriptor <ul><li>C:tomcatwebappsaxisWEB-INFclassesdeploy-hello-web-service.wsdd </li></ul><ul><li><deployment xmlns=&quot;http://xml.apache.org/axis/wsdd/&quot; </li></ul><ul><li>xmlns:java=&quot;http://xml.apache.org/axis/wsdd/providers/java&quot;> </li></ul><ul><li><service name=&quot;HelloService&quot; provider=&quot;java:RPC&quot;> </li></ul><ul><li><parameter name=&quot;className&quot; value=&quot;HelloService&quot;/> </li></ul><ul><li><parameter name=&quot;allowedMethods&quot; value=&quot;*&quot;/> </li></ul><ul><li><requestFlow> </li></ul><ul><li><handler type=&quot;soapmonitor&quot;/> </li></ul><ul><li></requestFlow> </li></ul><ul><li><responseFlow> </li></ul><ul><li><handler type=&quot;soapmonitor&quot;/> </li></ul><ul><li></responseFlow> </li></ul><ul><li></service> </li></ul><ul><li></deployment> </li></ul>Web Services using Apache Axis | Atul Kahate
  69. 69. Step 4: Compile and Deploy <ul><li>Start Tomcat </li></ul><ul><li>Compile Web Service and client code </li></ul><ul><li>Run admin client to deploy the service </li></ul><ul><ul><li>java org.apache.axis.client.AdminClient deploy-hello-web-service.wsdd </li></ul></ul><ul><li>Run Web service client and check if it runs fine – also check SOAP Monitor </li></ul>Web Services using Apache Axis | Atul Kahate
  70. 70. Second Web Service
  71. 71. Web Service Code (Server-side) <ul><li>// C:tomcatwebappsaxisWEB-INFclassescalculatorService.java </li></ul><ul><li>public class CalculatorService { </li></ul><ul><li>public Object getCalculate(Object opr1, Object opr2,Object opr ) { </li></ul><ul><li>System.out.println (&quot;Inside CalculatorService&quot;); </li></ul><ul><li>Object result=null; </li></ul><ul><li>if (opr.toString().equals(&quot;+&quot;)) </li></ul><ul><li>result = new Integer (((Integer) opr1).intValue()+ ((Integer) opr2).intValue()); </li></ul><ul><li>else if (opr.toString().equals(&quot;-&quot;)) </li></ul><ul><li>result = new Integer (((Integer) opr1).intValue ()-((Integer) opr2).intValue()); </li></ul><ul><li>else if(opr.toString().equals(&quot;*&quot;)) </li></ul><ul><li>result = new Integer (((Integer) opr1).intValue()*((Integer) opr2).intValue()); </li></ul><ul><li>else if(opr.toString().equals(&quot;/&quot;)) </li></ul><ul><li>result = new Integer (((Integer) opr1).intValue()/((Integer) opr2).intValue()); </li></ul><ul><li>System.out.println(&quot;Completed CalculatorService&quot;); </li></ul><ul><li>return result; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Web Services using Apache Axis | Atul Kahate
  72. 72. Deploying Web Service – 1 <ul><li>Compile the Web service (i.e. the Java class) </li></ul><ul><li>Create a file named deploy.wsdd in the same folder, containing the following entries: </li></ul><ul><li><deployment xmlns=&quot;http://xml.apache.org/axis/wsdd/&quot; </li></ul><ul><li>xmlns:java=&quot;http://xml.apache.org/axis/wsdd/providers/java&quot;> </li></ul><ul><li><service name=&quot;CalculatorService&quot; provider=&quot;java:RPC&quot;> </li></ul><ul><li><parameter name=&quot;className&quot; value=&quot;CalculatorService&quot;/> </li></ul><ul><li><parameter name=&quot;allowedMethods&quot; value=&quot;*&quot;/> </li></ul><ul><li></service> </li></ul><ul><li></deployment> </li></ul>Web Services using Apache Axis | Atul Kahate
  73. 73. Deploying Web Service – 2 <ul><li>Then run the following at the command prompt in the folder C:tomcatwebappsaxisWEB-INFclasses </li></ul><ul><ul><li>java org.apache.axis.client.AdminClient deploy.wsdd </li></ul></ul><ul><li>You should get the following screen </li></ul>Web Services using Apache Axis | Atul Kahate
  74. 74. Deploying Web Service – 3 Web Services using Apache Axis | Atul Kahate
  75. 75. Click on “List” Below Web Services using Apache Axis | Atul Kahate
  76. 76. We should be able to see our Service Running Web Services using Apache Axis | Atul Kahate
  77. 77. Where are we? <ul><li>We have downloaded and set up Apache Axis successfully </li></ul><ul><li>We have written a Web Service (server-side) and have deployed it successfully </li></ul>Web Services using Apache Axis | Atul Kahate
  78. 78. Write the Web Service Client <ul><li>// C:tomcatwebappsaxisWEB-INFclasses CalculatorClient.java </li></ul><ul><li>/** </li></ul><ul><li>* CalculatorClient.java </li></ul><ul><li>*/ </li></ul><ul><li>import java.io.IOException; </li></ul><ul><li>import java.io.PrintWriter; </li></ul><ul><li>import javax.servlet.ServletConfig; </li></ul><ul><li>import javax.servlet.ServletException; </li></ul><ul><li>import javax.servlet.http.HttpServlet; </li></ul><ul><li>import javax.servlet.http.HttpServletRequest; </li></ul><ul><li>import javax.servlet.http.HttpServletResponse; </li></ul><ul><li>import javax.xml.namespace.QName; </li></ul><ul><li>import org.apache.axis.client.Call; </li></ul><ul><li>import org.apache.axis.client.Service; </li></ul><ul><li>public class CalculatorClient extends HttpServlet { </li></ul><ul><li>public void init(ServletConfig config) throws ServletException { </li></ul><ul><li>super.init(config); </li></ul><ul><li>System.out.println(&quot;CalculatorClient Initialized.&quot;) ; </li></ul><ul><li>} </li></ul><ul><li>protected void doGet(HttpServletRequest request </li></ul><ul><li>,HttpServletResponse response)throws ServletException, IOException </li></ul><ul><li>{ </li></ul><ul><li>processRequest(request, response); </li></ul><ul><li>} </li></ul><ul><li>protected void doPost(HttpServletRequest request </li></ul><ul><li>,HttpServletResponse response)throws ServletException, IOException </li></ul><ul><li>{ </li></ul><ul><li>processRequest(request, response); </li></ul><ul><li>} </li></ul><ul><li>protected void processRequest (HttpServletRequest request </li></ul><ul><li>,HttpServletResponse response)throws ServletException, IOException </li></ul><ul><li>{ </li></ul><ul><li>System.out.println(&quot;Processing Request.&quot;); </li></ul><ul><li>response.setContentType(&quot;text/html&quot;); </li></ul><ul><li>PrintWriter out = response.getWriter (); </li></ul><ul><li>String firstOper = request.getParameter(&quot;oper1&quot;); </li></ul><ul><li>String secondOper = request.getParameter(&quot;oper2&quot;); </li></ul><ul><li>String operator = request.getParameter(&quot;Oper&quot;); </li></ul><ul><li>String result = null; </li></ul><ul><li>out.println(&quot;<html>&quot;); </li></ul><ul><li>out.println(&quot;<head><title>Axis</title></head>&quot;); </li></ul><ul><li>out.println(&quot;<body bgcolor=#F0F0F0 >&quot;); </li></ul><ul><li>out.println(&quot;<center>&quot;); </li></ul><ul><li>out.println(&quot;<table BORDER='4' BORDERCOLOR='#007FFF' cellpadding=3 celspacing=3 align=center width=50% bgcolor=CCCCCC>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2 align=center><b><font size='3' face='Verdana'>Webservice-Axis Demo</font></td></tr>&quot;); </li></ul><ul><li>out.println(&quot;</table>&quot;); </li></ul><ul><li>out.println(&quot;</form>&quot;); </li></ul><ul><li>out.println(&quot;</body>&quot;); </li></ul><ul><li>out.println(&quot;</html>&quot;); </li></ul><ul><li>if(firstOper != null && secondOper != null && operator != null) </li></ul><ul><li>{ </li></ul><ul><li>try { </li></ul><ul><li>result = callAxisWebService(firstOper,secondOper,operator); </li></ul><ul><li>} catch (Exception e) { </li></ul><ul><li>e.printStackTrace(); </li></ul><ul><li>System.out.println(&quot;Exception in processing request.&quot;); </li></ul><ul><li>} </li></ul><ul><li>out.println(&quot;<html>&quot;); </li></ul><ul><li>out.println(&quot;<head><title>Axis</title></head>&quot;); </li></ul><ul><li>out.println(&quot;<body bgcolor=#F0F0F0 >&quot;); </li></ul><ul><li>out.println(&quot;<center>&quot;); </li></ul><ul><li>out.println(&quot;<form>&quot;); </li></ul><ul><li>out.println(&quot;<table BORDER='4' BORDERCOLOR='#007FFF' cellpadding=3 celspacing=3 align=center width=50% bgcolor=CCCCCC>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2 align=center><b><font size='2' face='Verdana'>Response from Calculate Webservice</font></td></tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2 align=center>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Operand 1:</td><td>&quot;+firstOper+&quot;</font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Operand 2:</td><td>&quot;+secondOper+&quot;</font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Operator:</td><td>&quot;+operator+&quot;</font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot; <tr><td><font size='2' face='Verdana'>Result:</td><td>&quot;+result+&quot;</font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;</table>&quot;); </li></ul><ul><li>out.println(&quot;</form>&quot;); </li></ul><ul><li>out.println(&quot;</body>&quot;); </li></ul><ul><li>out.println(&quot;</html>&quot;); </li></ul><ul><li>} </li></ul><ul><li>out.println(&quot;<html>&quot;); </li></ul><ul><li>out.println(&quot;<head><title>Axis</title></head>&quot;); </li></ul><ul><li>out.println(&quot;<body bgcolor=#F0F0F0 >&quot;); </li></ul><ul><li>out.println(&quot;<center>&quot;); </li></ul><ul><li>out.println(&quot;<form method=post action='CalculatorClient'>&quot;); </li></ul><ul><li>out.println(&quot;<br/>&quot;); </li></ul><ul><li>out.println(&quot;<table BORDER='4' BORDERCOLOR='#007FFF' cellpadding=3 celspacing=3 align=center width=50% bgcolor=CCCCCC>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2 align=center><b><font size='2' face='Verdana'>WebService-Axis Client</font></td></tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2 align=center>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Enter Operand 1:</td><td><input type=text name=oper1 size='20'></font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Enter Operand 2:</td><td><input type=text name=oper2 size='20'></font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td><font size='2' face='Verdana'>Select Operation:</td><td><SELECT NAME='Oper'>&quot;); </li></ul><ul><li>out.println(&quot;<OPTION>--Select Operation--&quot;); </li></ul><ul><li>out.println(&quot;<OPTION>+&quot;); </li></ul><ul><li>out.println(&quot;<OPTION>-&quot;); </li></ul><ul><li>out.println(&quot;<OPTION>*&quot;); </li></ul><ul><li>out.println(&quot;<OPTION>/&quot;); </li></ul><ul><li>out.println(&quot;</SELECT></font></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;<tr><td colspan=2><input type=submit value='Calculate'></td><tr>&quot;); </li></ul><ul><li>out.println(&quot;</table>&quot;); </li></ul><ul><li>out.println(&quot;</form>&quot;); </li></ul><ul><li>out.println(&quot;</body>&quot;); </li></ul><ul><li>out.println(&quot;</html>&quot;); </li></ul><ul><li>if ( out != null ) </li></ul><ul><li>out.close(); </li></ul><ul><li>System.out.println(&quot;Process Request Completed.&quot;); </li></ul><ul><li>} </li></ul><ul><li>private String callAxisWebService(String firstOper, String secondOper, String operator) throws Exception { </li></ul><ul><li>Object ret = null; </li></ul><ul><li>String endpointURL = </li></ul><ul><li>&quot;http://localhost:8080/axis/services/CalculatorService&quot;; </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>Integer first = new Integer(firstOper); </li></ul><ul><li>Integer second = new Integer(secondOper); </li></ul><ul><li>String oper = new String(operator); </li></ul><ul><li>Service service = new Service(); </li></ul><ul><li>Call call = (Call) service.createCall(); </li></ul><ul><li>call.setTargetEndpointAddress(new java.net.URL(endpointURL)); </li></ul><ul><li>call.setOperationName(new QName(&quot;CalculatorService&quot;, &quot;getCalculate&quot;)); </li></ul><ul><li>ret = call.invoke( new Object[] { first, second, oper } ); </li></ul><ul><li>System.out.println(&quot;Object = &quot; + ret.getClass().getName()); </li></ul><ul><li>System.out.println(&quot;Number Returned : &quot; + ret.toString()); </li></ul><ul><li>} </li></ul><ul><li>catch(Exception e) </li></ul><ul><li>{ </li></ul><ul><li>e.printStackTrace(); </li></ul><ul><li>} </li></ul><ul><li> return ret.toString(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Web Services using Apache Axis | Atul Kahate
  79. 79. Understanding the Client Code <ul><li>// Endpoint is used for making the call </li></ul><ul><li>String endpointURL=&quot;http://localhost:8080/axis/services/CalculatorService&quot;; </li></ul><ul><li>// The Service object is the starting point for accessing the web service. </li></ul><ul><li>Service service = new Service (); </li></ul><ul><li>//The call object is used to actually invoke the web service. </li></ul><ul><li>Call call = (Call)service.createCall(); </li></ul><ul><li>// Sets the call objects endpoint address </li></ul><ul><li>call.setTargetEndpointAddress(new java.net.URL(endpointURL)); </li></ul><ul><li>// Sets the operation name associated with this Call object. </li></ul><ul><li>call.setOperationName(new QName(&quot;CalculatorService&quot;, &quot;getCalculate&quot;)); </li></ul><ul><li>// Calls the object, passing in the String objects for the operands & Operators. </li></ul><ul><li>//The return value is stored as an object named “ret”. </li></ul><ul><li>ret = call.invoke (new Object [] {first, second, oper } ); </li></ul>Web Services using Apache Axis | Atul Kahate
  80. 80. Testing the Web Service <ul><li>Compile the Web Service client </li></ul><ul><li>Use this URL: http://localhost:8080/axis/servlet/CalculatorClient </li></ul><ul><li>Screen: Next slide </li></ul>Web Services using Apache Axis | Atul Kahate
  81. 81. Web Service Client Screen Web Services using Apache Axis | Atul Kahate
  82. 82. Un-deploying the Web Service <ul><li>Create undeploy.wsdd in the same folder </li></ul><ul><ul><li><undeployment xmlns=&quot;http://xml.apache.org/axis/wsdd/&quot;> </li></ul></ul><ul><ul><li><service name=&quot;CalculatorService&quot;/> </li></ul></ul><ul><ul><li></undeployment> </li></ul></ul><ul><li>Run the following command: </li></ul><ul><ul><li>java org.apache.axis.client.AdminClient undeploy.wsdd </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  83. 83. SOAP Monitor
  84. 84. What is SOAP Monitor? <ul><li>Web service developers often have the need to see the SOAP messages being used to invoke web services along with the results of those messages. </li></ul><ul><li>The goal of the SOAP Monitor utility is to provide a way for these developers to monitor the SOAP messages being used without requiring any special configuration or restarting of the server. </li></ul>Web Services using Apache Axis | Atul Kahate
  85. 85. Enabling SOAP Monitor – 1 <ul><li>By default, SOAP Monitor is not enabled </li></ul><ul><li>We need to explicitly enable it </li></ul><ul><ul><li>Step 1: Compile the SOAP monitor applet </li></ul></ul><ul><ul><ul><li>javac SOAPMonitorApplet.java </li></ul></ul></ul>Web Services using Apache Axis | Atul Kahate
  86. 86. Enabling SOAP Monitor – 2 <ul><li>Step 2: Deploy the SOAPMonitorService web service with the admin client and the deploy-monitor.wsdd file </li></ul><ul><li>See next page </li></ul>Web Services using Apache Axis | Atul Kahate
  87. 87. Enabling SOAP Monitor – 3 <ul><li>Deploy-monitor.wsdd file </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><deployment xmlns=&quot;http://xml.apache.org/axis/wsdd/&quot; </li></ul></ul><ul><ul><li>xmlns:java=&quot;http://xml.apache.org/axis/wsdd/providers/java&quot;> </li></ul></ul><ul><ul><li><handler name=&quot;soapmonitor&quot; </li></ul></ul><ul><ul><li>type=&quot;java:org.apache.axis.handlers.SOAPMonitorHandler&quot;> </li></ul></ul><ul><ul><li><parameter name=&quot;wsdlURL&quot; </li></ul></ul><ul><ul><li>value=&quot;/axis/SOAPMonitorService-impl.wsdl&quot;/> </li></ul></ul><ul><ul><li><parameter name=&quot;namespace&quot; </li></ul></ul><ul><ul><li>value=&quot;http://tempuri.org/wsdl/2001/12/SOAPMonitorService-impl.wsdl&quot;/> </li></ul></ul><ul><ul><li><parameter name=&quot;serviceName&quot; value=&quot;SOAPMonitorService&quot;/> </li></ul></ul><ul><ul><li><parameter name=&quot;portName&quot; value=&quot;Demo&quot;/> </li></ul></ul><ul><ul><li></handler> </li></ul></ul><ul><ul><li><service name=&quot;SOAPMonitorService&quot; provider=&quot;java:RPC&quot;> </li></ul></ul><ul><ul><li><parameter name=&quot;allowedMethods&quot; value=&quot;publishMessage&quot;/> </li></ul></ul><ul><ul><li><parameter name=&quot;className&quot; </li></ul></ul><ul><ul><li>value=&quot;org.apache.axis.monitor.SOAPMonitorService&quot;/> </li></ul></ul><ul><ul><li><parameter name=&quot;scope&quot; value=&quot;Application&quot;/> </li></ul></ul><ul><ul><li></service> </li></ul></ul><ul><ul><li></deployment> </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  88. 88. Enabling SOAP Monitor – 4 <ul><li>Deploy SOAP monitor </li></ul><ul><ul><li>java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy-monitor.wsdd </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  89. 89. Enabling SOAP Monitor – 5 <ul><li>Step 3: For each service that we need to monitor, add the following entries to its deploy.wsdd file: </li></ul><ul><ul><li><requestFlow> <handler type=&quot;soapmonitor&quot;/> </requestFlow> <responseFlow> <handler type=&quot;soapmonitor&quot;/> </responseFlow> </li></ul></ul><ul><li>In this case, add these to the C:tomcatwebappsaxisWEB-INFclasses deploy.wsdd file – Modified file on next slide </li></ul>Web Services using Apache Axis | Atul Kahate
  90. 90. Enabling SOAP Monitor – 6 <ul><li><deployment xmlns=&quot;http://xml.apache.org/axis/wsdd/&quot; </li></ul><ul><li>xmlns:java=&quot;http://xml.apache.org/axis/wsdd/providers/java&quot;> </li></ul><ul><li><service name=&quot;CalculatorService&quot; provider=&quot;java:RPC&quot;> </li></ul><ul><li><parameter name=&quot;className&quot; value=&quot;CalculatorService&quot;/> </li></ul><ul><li><parameter name=&quot;allowedMethods&quot; value=&quot;*&quot;/> </li></ul><ul><li><requestFlow> </li></ul><ul><li><handler type=&quot;soapmonitor&quot;/> </li></ul><ul><li></requestFlow> </li></ul><ul><li><responseFlow> </li></ul><ul><li><handler type=&quot;soapmonitor&quot;/> </li></ul><ul><li></responseFlow> </li></ul><ul><li></service> </li></ul><ul><li></deployment> </li></ul>Web Services using Apache Axis | Atul Kahate
  91. 91. Enabling SOAP Monitor – 7 <ul><li>Un-deploy and re-deploy the Calculator Web Service </li></ul><ul><ul><li>java org.apache.axis.client.AdminClient undeploy.wsdd </li></ul></ul><ul><ul><li>java org.apache.axis.client.AdminClient deploy.wsdd </li></ul></ul><ul><li>Now rerun the client: http://localhost:8080/axis/servlet/CalculatorClient </li></ul>Web Services using Apache Axis | Atul Kahate
  92. 92. Web Services using Apache Axis | Atul Kahate
  93. 93. SOAP Monitor Web Services using Apache Axis | Atul Kahate
  94. 94. SOAP Monitor FAQ <ul><li>http://wiki.perfsonar.net/jra1-wiki/index.php/Installing_SOAPMonitor_for_Axish </li></ul><ul><li>Installing SOAPMonitor for Axis </li></ul><ul><li>From GEANT2-JRA1 Wiki </li></ul><ul><li>Step 1: Make sure you have the necessary files for soap monitor </li></ul><ul><li>Checklist: </li></ul><ul><li>SOAPMonitorApplet.java (usually present in the tomcat/webapps/axis directory) </li></ul><ul><li>deploy-monitor.wsdd - download </li></ul><ul><li>undeploy-monitor.wsdd - download </li></ul><ul><li>Step 2: Make sure your classpath contains the following jars </li></ul><ul><li>You can do this by either modifying CLASSPATH variable in .bash_profile (for unix) or by modifying it in Windows Environment Variables or by including the complete path to each of the following jar files in the javac and java commands (-cp option) </li></ul><ul><li>xercesImpl.jar </li></ul><ul><li>xml-apis.jar </li></ul><ul><li>xalan.jar </li></ul><ul><li>xmlrpc-1.2-patched.jar </li></ul><ul><li>xmlParserAPIs.jar </li></ul><ul><li>axis-1.4.jar </li></ul><ul><li>commons-discovery-0.2.jar </li></ul><ul><li>commons-logging-1.0.4.jar </li></ul><ul><li>jaxrpc.jar </li></ul><ul><li>saaj.jar </li></ul><ul><li>wsdl4j-1.5.1.jar </li></ul><ul><li>resolver.jar </li></ul><ul><li>log4j-1.2.8.jar </li></ul><ul><li>mail.jar </li></ul><ul><li>Note: The above list probably contains more jars than actually required. Also, the version numbers are the ones that have been tested with. You might be able to use a different version than the one specified above. Make sure that the axis.jar version is the same as the axis servlet that you are trying to deploy your service onto. Or else, you will get an IncompatibleClassChange error. </li></ul><ul><li>Step 3: Compile SOAPMonitorApplet.java </li></ul><ul><li>You can compile the java file with the help of the following command. </li></ul><ul><li>javac SOAPMonitorApplet.java Of if you want to use the -cp option (if the axis.jar file is not in your classpath) </li></ul><ul><li>javac -cp %AXIS_HOME%libaxis.jar SOAPMonitorApplet.java Step 4: Make sure resulting SOAPMonitoringApplet*.class (around 7 classes) are in your axis directory (ex: /home/loukik/tomcat/webapps/axis) </li></ul><ul><li>Step 5: Uncomment entries in WEB.xml </li></ul><ul><li>You will need uncomment the following lines in WEB.xml. Also, the SOAP monitor requires to run on a port (in the example its 5001). If the default port is already in use by some other application or some other SOAP monitor, you will need to set a different port number. </li></ul><ul><li><servlet> <servlet-name>SOAPMonitorService</servlet-name> <display-name>SOAPMonitorService</display-name> <servlet-class> org.apache.axis.monitor.SOAPMonitorService </servlet-class> <init-param> <param-name>SOAPMonitorPort</param-name> <param-value>5001</param-value> </init-param> <load-on-startup>100</load-on-startup> </servlet> Step 6: Deploy </li></ul><ul><li>The following command was used to deploy the service. You will need to substitute localhost:8080 with your machine's hostname/ip address and port. (This is the machine which is running tomcat and where the service is installed) </li></ul><ul><li>java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy-monitor.wsdd or if you want to include the classpath here </li></ul><ul><li>java -cp %CLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy-monitor.wsdd Step 7: Modify .wsdd file for your service and Re-deploy them </li></ul><ul><li>By default, the .wsdd files that perfSONAR uses for deploying services currently does not support flows via a SOAP Monitor. It needs to be modified as below in order to monitor the flows using the SOAP monitor. </li></ul><ul><li>The modification is quite simple. The following lines need to be added to the deploy.wsdd file (ma-service-deploy.wsdd or mp-service-deploy.wsdd or ls-service-deploy.wsdd, etc). You can find this file in $PERFSONAR/build/org/perfsonar/service/web/wsdd directory. </li></ul><ul><li><requestFlow> <handler name = &quot;soapmonitor&quot; type = &quot;java:org.apache.axis.handlers.SOAPMonitorHandler&quot; /> </requestFlow>   <responseFlow> <handler name = &quot;soapmonitor&quot; type = &quot;java:org.apache.axis.handlers.SOAPMonitorHandler&quot; /> </responseFlow> An example file showing these lines inserted in the wsdd can be found here . </li></ul><ul><li>Step 8: Re-deploy your service, restart Tomcat </li></ul><ul><li>After making changes to the wsdd file, you will need to undeploy the service and then re-deploy it. Check your service's installation guide for instructions on how to undeploy and deploy a service. After redeploying, tomcat will need to be restarted. </li></ul><ul><li>Step 9: Check your SOAP Monitor </li></ul><ul><li>You can check if your SOAP Monitor is working by clicking on the SOAPMonitor link on the axis page (usually http://localhost:8080/axis/SOAPMonitor ). If the SOAPMonitor page loads, it means that the web.xml entry has been properly uncommented. If the SOAPMonitor page shows that the SOAPMonitor has started (see page here ) it means all is ok. If not, check the port number (try making changes), restart tomcat and test again. </li></ul><ul><li>How to undeploy SOAP monitor </li></ul><ul><li>Ok, so you had enough of the SOAP Monitor :).Here is how you can undeploy it. </li></ul><ul><li>Undeploy SOAPMonitorService (make sure you have the undeploy-monitor.wsdd file - see step 1 if not) </li></ul><ul><li>java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService undeploy-monitor.wsdd or </li></ul><ul><li>java -cp %CLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService undeploy-monitor.wsdd </li></ul><ul><li>Comment out the entries in web.xml </li></ul><ul><li><!-- <servlet> <servlet-name>SOAPMonitorService</servlet-name> <display-name>SOAPMonitorService</display-name> <servlet-class> org.apache.axis.monitor.SOAPMonitorService </servlet-class> <init-param> <param-name>SOAPMonitorPort</param-name> <param-value>5001</param-value> </init-param> <load-on-startup>100</load-on-startup> </servlet> --> </li></ul><ul><li>Modify your deploy.wsdd file </li></ul><ul><li>If you do not modify your deploy.wsdd as specified below and re-deploy your service, your service will not work. Remove the following lines from it. </li></ul><ul><li><requestFlow> <handler name = &quot;soapmonitor&quot; type = &quot;java:org.apache.axis.handlers.SOAPMonitorHandler&quot; /> </requestFlow>   <responseFlow> <handler name = &quot;soapmonitor&quot; type = &quot;java:org.apache.axis.handlers.SOAPMonitorHandler&quot; /> </responseFlow> </li></ul><ul><li>Undeploy and then deploy your service </li></ul><ul><li>Look into your installation guide to find out how to undeploy and deploy your service </li></ul><ul><li>Restart Tomcat </li></ul><ul><li>Make sure you restart tomcat so that the changes can be applied. </li></ul><ul><li>Other pages : Apache pages on SOAP Monitor installation </li></ul>Web Services using Apache Axis | Atul Kahate
  95. 95. The Axis Client APIs
  96. 96. Service Object <ul><li>Package org.apache.axis.client.Service </li></ul><ul><li>Acts as a factory for the Call objects </li></ul><ul><li>Contains type mappings for XML<->Java bindings </li></ul><ul><ul><li>Service service = new Service(); </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  97. 97. Call Object <ul><li>Call object is the main entry point into a Web service </li></ul><ul><li>Package org.apache.axis.client.Call </li></ul><ul><li>This class should be used to actually invoke a Web Service </li></ul><ul><li>Call call = (Call) service.createCall(); </li></ul><ul><ul><li>Factory method creates a JAX-RPC Call object – returns a javax.xml.rpc.Call, which we need to type cast to the Axis Call type </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  98. 98. Endpoint URL <ul><li>Call setTargetEndpointAddress () method to pass the endpoint URL of the target Web Service to the newly created Call object </li></ul><ul><ul><li>String endpointURL = &quot;http://localhost:8080/axis/services/CalculatorService&quot;; </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><ul><li>call.setTargetEndpointAddress(new java.net.URL(endpointURL)); </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  99. 99. Operation <ul><li>Set the method name (i.e. operation name) to be called in the Web Service class </li></ul><ul><li>Expects a Qname </li></ul><ul><ul><li>call.setOperationName (new Qname (&quot;CalculatorService&quot;, &quot;getCalculate&quot;)); </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  100. 100. Call the Web Service <ul><li>Use the invoke method </li></ul><ul><ul><li>ret = call.invoke (new Object[] { first, second, oper} ); </li></ul></ul><ul><ul><li>Signature </li></ul></ul><ul><ul><ul><li>java.lang.Object invoke (java.lang.Object [] params) </li></ul></ul></ul><ul><ul><li>Expects an array of Objects, and returns an Object </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  101. 101. Display the Value Returned <ul><li>System.out.println (&quot;Number Returned: &quot; + ret.toString ()); </li></ul><ul><ul><li>ret was an object </li></ul></ul>Web Services using Apache Axis | Atul Kahate
  102. 102. Java Web Services (JWS)
  103. 103. What are JWS? <ul><li>JAX-WS stands for Java API for XML Web Services. JAX-WS is a technology for building web services and clients that communicate using XML </li></ul>Web Services using Apache Axis | Atul Kahate
  104. 104. JWS Details <ul><li>JAX-WS allows developers to write message-oriented as well as RPC-oriented web services </li></ul><ul><li>In JAX-WS, a web service operation invocation is represented by an XML-based protocol such as SOAP </li></ul><ul><li>The SOAP specification defines the envelope structure, encoding rules, and conventions for representing web service invocations and responses. These calls and responses are transmitted as SOAP messages (XML files) over HTTP </li></ul>Web Services using Apache Axis | Atul Kahate
  105. 105. Programmer’s View – 1 <ul><li>Although SOAP messages are complex, the JAX-WS API hides this complexity from the application developer </li></ul><ul><li>On the server side, the developer specifies the web service operations by defining methods in an interface written in the Java programming language </li></ul><ul><li>The developer also codes one or more classes that implement those methods. </li></ul><ul><li>Client programs are also easy to code </li></ul><ul><li>A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy </li></ul>Web Services using Apache Axis | Atul Kahate
  106. 106. Programmer’s View – 2 <ul><li>With JAX-WS, the developer does not generate or parse SOAP messages </li></ul><ul><li>It is the JAX-WS runtime system that converts the API calls and responses to and from SOAP messages </li></ul>Web Services using Apache Axis | Atul Kahate
  107. 107. Client-Server Communication in JWS Web Services using Apache Axis | Atul Kahate
  108. 108. Creating JWS on the Server-side
  109. 109. Web Service Endpoint <ul><li>The starting point for developing a JAX-WS web service is a Java class annotated with the javax.jws.WebService annotation </li></ul><ul><li>The @WebService annotation defines the class as a web service endpoint </li></ul>Web Services using Apache Axis | Atul Kahate
  110. 110. Service Endpoint Interface and Implementation (SEI) <ul><li>A service endpoint interface or service endpoint implementation (SEI) is a Java interface or class, respectively, that declares the methods that a client can invoke on the service </li></ul><ul><li>An interface is not required when building a JAX-WS endpoint </li></ul><ul><li>The web service implementation class implicitly defines an SEI </li></ul>Web Services using Apache Axis | Atul Kahate
  111. 111. Web Service Example <ul><li>package helloservice.endpoint; </li></ul><ul><li>import javax.jws.WebService; </li></ul><ul><li>@WebService </li></ul><ul><li>public class Hello { </li></ul><ul><li>private String message = new String(&quot;Hello, &quot;); </li></ul><ul><li>public void Hello() {} </li></ul><ul><li>@WebMethod </li></ul><ul><li>public String sayHello(String name) { </li></ul><ul><li>return message + name + &quot;.&quot;; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Web Services using Apache Axis | Atul Kahate
  112. 112. Testing the Web Service <ul><li>Create a new Web Service client in NetBeans and test it </li></ul><ul><li>-- OR -- </li></ul><ul><li>Open browser, type URL as http://localhost:4848 and provide ID as admin, password as adminadmin then choose Hello Web Service and click on Test </li></ul>Web Services using Apache Axis | Atul Kahate
  113. 113. JWS Theory
  114. 114. Java Web Services <ul><li>“ New” Java APIs for Web Services </li></ul><ul><ul><li>JAX-WS 2.0 – Java API for XML-based Web Services (Predecessor was JAX-RPC) </li></ul></ul><ul><ul><li>JAXB 2.0 – Java Architecture for XML Binding – Plumbing between Java objects and their XML representation </li></ul></ul><ul><ul><li>WS-Metadata – Web Services Metadata for the Java platform – Provides annotations </li></ul></ul><ul><ul><li>WSEE 1.2 – Web Services for Java EE – Defines the programming model and run-time behavior of Web Services in the Java EE container </li></ul></ul><ul><li>Need Java SE 6 and Java EE 5 </li></ul>Web Services using Apache Axis | Atul Kahate
  115. 115. Earlier Java Web Services Standards Carried Forward <ul><li>SAAJ – SOAP with Attachments API for Java </li></ul><ul><li>JAXR – Java API for XML Registries </li></ul>Web Services using Apache Axis | Atul Kahate
  116. 116. Server-side of a Web Service <ul><li>Receive a SOAP message (e.g. HTTP or JMS end point) </li></ul><ul><li>Invoke a handler that pre-processes the message (e.g. to process headers or to persist the message) </li></ul><ul><li>Determine the target service (i.e. WSDL operation) that the message intends to invoke </li></ul><ul><li>Based on the target WSDL operation, determine the Java class/method (called as Java target ) to invoke (This is called as dispatching ) </li></ul><ul><li>Hand off the SOAP message to the Serialization subsystem to de-serialize it into a Java object that can be passed to the Java target as parameters </li></ul><ul><li>Invoke the Java target using the parameters generated by the Serialization subsystem and getting the Java object returned by the target method </li></ul><ul><li>Hand off the returned object to the Serialization subsystem to serialize it into an XML element conformant with the return message specified by the target WSDL operation </li></ul><ul><li>Wrap the returned XML element as a SOAP message response conforming to the target WSDL operation </li></ul><ul><li>Hand the SOAP message back to the transport for delivery </li></ul>Web Services using Apache Axis | Atul Kahate
  117. 117. Client-side of a Web Service <ul><li>Create an instance of the Web Service end point implementing a Java interface (called as Service Endpoint Interface or SEI ) </li></ul><ul><li>Handle an invocation of the SEI instance </li></ul><ul><li>Take the parameters passed to the SEI and pass them to the Serialization subsystem to be serialized into XML elements that conform to the XML schema specified by the target service’s WSDL </li></ul><ul><li>Based on the target service’s WSDL, wrap the parameter elements in a SOAP message </li></ul><ul><li>Invoke handlers that post-process the message (e.g. add SOAP headers, persist the message) </li></ul><ul><li>Hand off the message to the transport for delivery to the target Web Service </li></ul><ul><li>Receive the SOAP message response from the transport </li></ul><ul><li>Hand off the SOAP message to the Serialization subsystem to de-serialize it into a Java object that is an instance of the class specified by the SEI’s return type </li></ul><ul><li>Complete the invocation of the SEI by returning the de-serialized SOAP response </li></ul>Web Services using Apache Axis | Atul Kahate
  118. 118. Thank you! Questions and Comments Welcome!

×