1 / 30

COP 4991 Component Based Software Development

COP 4991 Component Based Software Development. Lecture #4 Java Web Services Onyeka Ezenwoye. Acknowledgement. Tapas Banerjee Pankaj Kumar Sang Shin. AGENDA. Java APIs for Web Services. Apache Axis Web Services deployment. Web Services Programming APIs. APIs for RPC-based Web Services:

nituna
Download Presentation

COP 4991 Component Based Software Development

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. COP 4991Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye

  2. Acknowledgement • Tapas Banerjee • Pankaj Kumar • SangShin

  3. AGENDA • Java APIs for Web Services. • Apache Axis • Web Services deployment.

  4. Web Services Programming APIs • APIs for RPC-based Web Services: • JAX-RPC (Java API for XML-RPC) • Java API for XML-based RPC (JAX-RPC) sends SOAP method calls to remote parties over the Internet and receives the results • APIs for Message-based Web Services: • JAXM (Java API for XML Messaging) • Java API for XML Messaging (JAXM) sends SOAP messages over the Internet in a standard way • APIs for publishing and discovering Web Services: • JAXR (Java API for XML Registry) • Java API for XML Registries (JAXR) provides a standard way to access business registries and share information

  5. JAXR • Java API for XML Registry • Enables Java programs to access XML registries. • JAXR provider: • Accesses XML registry. • JAXR client: • A client program that accesses an XML registry using JAXR API. • Perform queries and update UDDI registries.

  6. JAX-RPC • API for XML-based RPC • Sends SOAP method calls to remote parties over the Internet and receives the results • WSDL/XML to Java Mapping • Java to WSDL/XML Mapping

  7. WSDL description Service Client Service Endpoint Container WSDL<->Java Mapping Stub Dispatch JAX-RPC API JAX-RPC API Client Side JAX-RPC Runtime System Server Side JAX-RPC Runtime System SOAP Transport JAX-RPC Physical Architecture

  8. AGENDA • Java APIs for Web Services • Apache Axis • Web Services deployment

  9. Apache Software Foundation • Who is Apache • an open community of Java developers worldwide. • Open Source • Lots of free software (just great!) • Downside • Lack of support • Use at your own risk

  10. Tools &APIs: Apache Axis • Apache SOAP: First Open Source SOAP Implementation • Axis next generation Apache SOAP, New Code base – lessons learned from Apache SOAP development • Implements JAX-RPC (alternative to SUN’s JAX-RPC)

  11. Axis Tools • Support for WSDL • Java2WSDL • for building WSDL from Java classes • WSDL2Java • for building Java proxies and skeletons from WSDL documents

  12. Runtime Environment • Web Server • Apache Tomcat • Allows to access Java application provided via an HTTP server • http://jakarta.apache.org/tomcat/ • SOAP engine • Apache Axis • http://ws.apache.org/axis/

  13. HTTP Server (e.g. Apache Tomcat) Servlet engine Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” SOAP-aware Servlet (e.g. Apache Axis) Sending requests, getting results

  14. Direcotry Structure: axis-1_0 webapps lib docs samples axis WEB-INF lib classes web.xml …… Install & Deploy Apache Axis • Make sure that you have • J2SE SDK. We will use 1.4 • A Servlet Container: We will use Tomcat 4.1 • Download axis binaries from http://xml.apache.org/axis • Unzip it and look at the dir. tree. Note that Axis runs as a Servlet.

  15. Apache Axis • Installation • Copy webapps\axis, paste to tomcat\webapps\ • Run Tomcat: issue bin\startup from Tomcat home. • Installation Testing http://localhost:8080/axis/ • Classpath set AXIS_HOME=C:\jakarta-tomcat-4.0.6\webapps\axis set AXIS_LIB=%AXIS_HOME%\WEB-INF\lib set AXIS_CP=.;%AXIS_CP%;%AXIS_LIB%\axis.jar; %AXIS_LIB%\commons-discovery.jar; %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\wsdl4j.jar set classpath=%AXIS_CP%

  16. AGENDA • Java APIs for Web Services • Apache Axis • Web Services deployment

  17. Test the Deployment • Point your browser to http://localhost:8080/axis

  18. Different web service creation paths • From an existing application – bottom-up • Most common. We like to expose existing back-end systems for enterprise integration (EAI) purposes. • From WSDL, generate a completely new application – top-down • The wizards can create skeleton code from WSDL, we then fill up the details • Combine independent web services to provide new functionality.

  19. Creating a Web Service in Java • Typical steps: • Create the application • Generate WSDL document using some Web Service tool • Deploy Web Service to a Web Server • Generate client stubs from WSDL • Create client application • Then publish, discover and use web service

  20. Develop a service • Step 1 – Write a Java Class publicclass AdderImpl implements Adder { publicint add(int x, int y) throws RemoteException { return x + y; } }

  21. Adder.java public interface Adder { int add (int x, int y); } AdderImpl.java public class AdderImpl implements Adder { public int add(int x, int y) throws RemoteException { return x + y; } }

  22. Develop a service • Step 2 - Deploy to the SOAP engine • Create the deployment descriptor (*.wsdd) <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name=“adderService" provider="java:RPC"> <parameter name="className" value=“AdderImpl"/> <parameter name="allowedMethods" value=“*"/> </service> </deployment>

  23. Develop a service • Step 2 - Deploy to the SOAP engine • Copy the Java Class to the Web Server • Start the Web Server • Deploy java org.apache.axis.client.AdminClient *.wsdd

  24. Develop a service • Step 3 - Check • Check (List all services) http://localhost:8080/axis/servlet/AxisServlet

  25. Consume a service • Step 1 – Get the WSDL file of the service • Java2WSDL (usage example) java org.apache.axis.wsdl.Java2WSDL -o adder.wsdl -l http://localhost:8080/axis/services/adderService -n http://cop4991/adder adderImpl • We use this tool because the service is built by ourselves (we have the Java Class) output location namespace class name

  26. Consume a service • Step 2 – Generate the Client Stub • WSDL2Java (usage example) java org.apache.axis.wsdl.WSDL2Java myecho.wsdl • 4 files will be generated • AdderImpl.java • AdderImplService.java • AdderImplServiceLocator.java • AdderServiceSoapBindingStub.java interface Service Service factory Binding stub

  27. Consume a service • Step 3 – Write the Client Program … // Make a service AdderImplService adderService = new AdderImplServiceLocator(); // Now use the service to get a stub AdderImpl adder = adderService.getadderService(); // Make the actual call int sum = adder.add(10,9); …

  28. AdderClient.java public class AdderClient{ public static void main(String[] args){ try{ //Make a service instance AdderImplService adderService = new AdderImplServiceLocator(); //Now use the service to get a stub AdderImpl adder = adderService.getadderService(); //Make the actual call int sum = adder.add(10,9); System.out.println("the sum is: "+sum); }catch(Exception e){e.printStackTrace();} } }

  29. Static Stub Client • Our client is static • Tightly bound to generated stub • Can only use one service • Dynamic Clients • Use WSIF (Web Service Invocation Framework) instead

  30. Resources • Apache Tomcat • http://jakarta.apache.org/tomcat/ • Apache Axis Home • http://xml.apache.org/axis • XMethods • http://www.xmethods.net

More Related