cop 4991 component based software development lecture #4 java web services onyeka ezenwoye
TRANSCRIPT
![Page 1: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/1.jpg)
COP 4991Component Based Software
Development
Lecture #4Java Web Services
Onyeka Ezenwoye
![Page 2: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/2.jpg)
Acknowledgement
Tapas Banerjee
Pankaj Kumar
Sang Shin
![Page 3: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/3.jpg)
AGENDA
Java APIs for Web Services.Apache AxisWeb Services deployment.
![Page 4: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/4.jpg)
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
![Page 5: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/5.jpg)
JAXR
Java API for XML RegistryEnables 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.
![Page 6: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/6.jpg)
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
![Page 7: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/7.jpg)
JAX-RPC Physical Architecture
Transport
SOAP
Server Side JAX-RPCRuntime System
JAX-RPC API JAX-RPC APIClient Side JAX-RPC
Runtime System
Stub
Service Endpoint
WSDL description
WSDL<->Java Mapping
Service Client
Dispatch
Container
![Page 8: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/8.jpg)
AGENDA
Java APIs for Web ServicesApache AxisWeb Services deployment
![Page 9: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/9.jpg)
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
![Page 10: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/10.jpg)
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)
![Page 11: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/11.jpg)
Axis Tools
Support for WSDL
Java2WSDL– for building WSDL from Java classes
WSDL2Java– for building Java proxies and skeletons from
WSDL documents
![Page 12: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/12.jpg)
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/
![Page 13: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/13.jpg)
Sending requests,
getting results
Sending requests,
getting results
SOAP-awareSOAP-awareServletServlet
(e.g. Apache Axis)(e.g. Apache Axis)
SOAP-awareSOAP-awareServletServlet
(e.g. Apache Axis)(e.g. Apache Axis)
Any classprocessing
the incomingrequests
(“business logic”
Any classprocessing
the incomingrequests
(“business logic”
Any classprocessing
the incomingrequests
(“business logic”
Any classprocessing
the incomingrequests
(“business logic”
Any classprocessing
the incomingrequests
(“business logic”
Any classprocessing
the incomingrequests
(“business logic”
Any classAny classprocessingprocessing
the incomingthe incomingrequestsrequests
(“business logic”(“business logic”
Any classAny classprocessingprocessing
the incomingthe incomingrequestsrequests
(“business logic”(“business logic”
HTTP Server HTTP Server (e.g. Apache Tomcat)(e.g. Apache Tomcat)
Servlet engineServlet engine
![Page 14: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/14.jpg)
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/axisUnzip it and look at the dir. tree. Note that Axis runs as a Servlet.
Direcotry Structure:
axis-1_0
docslibwebapps samples
axis
WEB-INF
lib
classes
web.xml
……
![Page 15: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/15.jpg)
Apache AxisInstallation– Copy webapps\axis, paste to tomcat\webapps\– Run Tomcat: issue bin\startup from
Tomcat home.– Installation Testing http://localhost:8080/axis/
Classpathset AXIS_HOME=C:\jakarta-tomcat-4.0.6\webapps\axisset AXIS_LIB=%AXIS_HOME%\WEB-INF\libset 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.jarset classpath=%AXIS_CP%
![Page 16: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/16.jpg)
AGENDA
Java APIs for Web ServicesApache AxisWeb Services deployment
![Page 17: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/17.jpg)
Test the Deployment
Point your browser to http://localhost:8080/axis
![Page 18: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/18.jpg)
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.
![Page 19: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/19.jpg)
Creating a Web Service in Java
Typical steps:1. Create the application
2. Generate WSDL document using some Web Service tool
3. Deploy Web Service to a Web Server
4. Generate client stubs from WSDL
5. Create client application
Then publish, discover and use web service
![Page 20: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/20.jpg)
Develop a service
Step 1 – Write a Java Class
public class AdderImpl implements Adder
{
public int add(int x, int y) throws RemoteException
{
return x + y;
}
}
![Page 21: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/21.jpg)
public interface Adder {int add (int x, int y);
}
public class AdderImpl implements Adder
{
public int add(int x, int y) throws RemoteException
{
return x + y;
}
}
Adder.java
AdderImpl.java
![Page 22: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/22.jpg)
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>
![Page 23: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/23.jpg)
Develop a service
Step 2 - Deploy to the SOAP engine
– Copy the Java Class to the Web Server
– Start the Web Server
– Deployjava org.apache.axis.client.AdminClient *.wsdd
![Page 24: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/24.jpg)
Develop a service
Step 3 - Check– Check (List all services) http://localhost:8080/axis/servlet/AxisServlet
![Page 25: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/25.jpg)
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)
outputlocation
namespace
class name
![Page 26: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/26.jpg)
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 factory
Service
Binding stub
![Page 27: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/27.jpg)
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); …
![Page 28: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/28.jpg)
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();}
}
}
AdderClient.java
![Page 29: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/29.jpg)
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
![Page 30: COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye](https://reader030.vdocuments.site/reader030/viewer/2022032708/56649e6c5503460f94b6abb3/html5/thumbnails/30.jpg)
Resources
Apache Tomcat– http://jakarta.apache.org/tomcat/
Apache Axis Home– http://xml.apache.org/axis
XMethods– http://www.xmethods.net