1 / 23

Assignment 1 “Deploying a Simple Web Service”

Assignment 1 “Deploying a Simple Web Service”. Task. To build, deploy and test a simple web service. Tools. This assignment uses: Java 2 platform standard edition Apache Jakarta Tomcat Java servlet container Apache Axis tools. Steps. Write the Java code to implement the web service.

cicero
Download Presentation

Assignment 1 “Deploying a Simple Web Service”

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. Assignment 1“Deploying a Simple Web Service”

  2. Task • To build, deploy and test a simple web service.

  3. Tools This assignment uses: • Java 2 platform standard edition • Apache Jakarta Tomcat Java servlet container • Apache Axis tools

  4. Steps • Write the Java code to implement the web service. • Use Axis to generate all needed Java source files. • Compile the source files just generated. • Create client source and compile. • Execute client to access service. • Extend the functionality of the service.

  5. Web service Client Apache Tomcat hosting environment

  6. Step 1 – Implement Service Write the code for the class that provides the web service. This code is: public class MyMath { public int squared(int x) { return x * x; } } Save that code as a .jws (Java WebService) file, Math.jws.

  7. Step 1 (continued) Copy the .jws file to the axis directory: cp MyMath.jws \ $CATALINA_HOME/webapps/axis/yourusername %CATALINA is an environment variable specifying the path to the home directory of the Apache Tomcat java servlet container.

  8. Axis Java Web Service Facility By placing your Java code as a .jws file in your web application directory structure, Axis will automatically find it, compile it, and deploy the methods.

  9. Axis Java Web Service Facility (cont.) The service is now deployed and can be accessed remotely through it’s URL: http://yourserver.yourdomain.edu :8080/axis/yourusername/… Example http://www.coit-grid0.uncc.edu:8080/axis/abw/MyMath.jws

  10. However, a client cannot access the service without all the code needed handle the SOAP messages, i.e. the stubs and associated files.

  11. Can use Java service code as the basis to create the WSDL file using an Axis “Java2WSDL” tool. • Then use the WSDL as the basis to create the requires Java files using an Axis “WSDL2Java” tool

  12. Step 2 Generate files Use the Axis tools to create four Java source files from MyMath.jws with the composite command: java -classpath $AXISCLASSPATH \ org.apache.axis.wsdl.WSDL2Java \ http://localhost:8080/axis/MyMath.jws?wsdl

  13. Step 2 (continued) Axis finds MyMath.jws file and creates • Two source files each holding a Java interface, • MyMath.java and • MyMathService.java • Two source files each holding a Java class, • MyMathServiceLocator.java • MyMathSoapBindingStub.java These files are put in a new package in localhost/axis/yourusername/MyMath_jws/ which is in /home/yourusername/WebServices/

  14. MyMath.java -- Client code MyMathService.java -- Service code

  15. MyMathServiceLocator.java -- Java class used by client to find location of service. MyMathSoapBindingStub.java -- Java class that converts client service call to form to be sent to service. – client stub.

  16. Other files deploy.wsdd – WSDD file provided to registry when service deployed. undeploy.wsdd -- for undeploying service

  17. Files used by service Service stub (skeleton): MyMathSoapBindingSkeleton.java MyMathSoapBindingImpl.java – used by MyMathSoapBinding Skeleton.java

  18. Structure deploy.wsdd undeploy.wsdd WSDD Registry (Locator) MyMathServiceLocator.java Deploy Request WSDL Client Stub Service Stub WSDL Method call/return WSDL MyMathSoapBindingSkeleton.java MyMathClient.java MyMathService.java MyMathSoapBindingStub.java MyMath.java MyMath.wsdl

  19. Step 3 Compile new source files Compile source files generated by step 2 with: javac -classpath $AXISCLASSPATH \ localhost/axis/yourusername/MyMath_jws/*.java

  20. Step 4: Write Client Source Below is client code for an earlier version of Axis (1.1). Version 1.2 used in the assignment requires more code. import localhost.axis.yourusername.MyMath_jws.MyMathServiceLocator; import localhost.axis.yourusername.MyMath_jws.MyMathService; import localhost.axis.yourusername.MyMath_jws.MyMath; public class MyMathClient { public static void main(String args[]) throws Exception { MyMathService service = new MyMathServiceLocator(); MyMath myMath = service.getMyMath(); int x = (new Integer(args[0])).intValue(); System.out.println("The square of " + args[0] + " is " + myMath.squared(x)); } }

  21. Step 5 Compile Client code Compile the client source file with: javac -classpath $AXISCLASSPATH:. MyMathClient.java

  22. Step 6 Execute Web Service program java -classpath $AXISCLASSPATH MyMathClient 4 The square of 4 is 16

  23. Step 7 Extend the Web Service Add functionality to the MyMath web service: • Add a method that identifies whether a number is even. • Add a method that identifies whether a number is prime. Modify MyMath.jws file and repeat all previous steps to test the extended web service.

More Related