Professional Documents
Culture Documents
Lab Objective
23 March 2009
Lab Outline
WS Sum Up:
JWS WSDD
23 March 2009
REST (Representational State Transfer): uses plain old HTTP to make method calls and you get XML back.
XML-RPC: is a remote procedure call protocol which uses XML for marking up both requests and responses. SOAP (Simple Object Access Protocol): is a protocol specification for exchanging structured information in the implementation of Web Services in computer networks.
23 March 2009
WS protocol stack
23 March 2009
XML- messaging
23 March 2009
XML- messaging
23 March 2009
Is available over the Internet or private (intranet) networks Uses a standardized XML messaging system Is not tied to any one operating system or programming language Is self-describing via a common XML grammar (WSDL) Is discoverable via a simple find mechanism (UDDI)
23 March 2009 Gaia Trecarichi - Web Languages Course
WS architecture
23 March 2009
Axis functionalities
23 March 2009
Today Class
23 March 2009
WSDL2Java Tool
1. 2. 3. 4. 5. 6.
server
7.
*.java: New interface file with appropriate remote usages. *Service.java: client side service interface. *ServiceLocator.java: client side service implementation factory. *SoapBindingStub.java: Client side stub. (data types): Java files produced for non-standard types. *SoapBindingImpl.java: default server implementation WS, modify manually to actual implementation. *SoapBindingSkeleton.java: Server side skeleton.
23 March 2009
WSDL2Java Generates
used by AdminClient to deploy the service implementation class referred to will either be the skeleton
class (if skeleton generated) or the impl. class (if no skeleton generated) can change to refer to your own class
23 March 2009
Using WSDL2Java
Command
Option highlights -Nnamespace=package : maps a namespace to a Java package -o dir : specifies output directory where generated files should
be written -p pkg : overrides default package name for generated classes -s : generates service-side interfaces and classes required by a service implementation, including a skeleton class -t : generates JUnit test case for the web service -v : prints a message about each file that is generated
23 March 2009 Gaia Trecarichi - Web Languages Course
Steps
If
not there already, copy axis directory in webapps directory of the Axis distribution to the deployment directory of a server that supports Java servlets
For Tomcat, this is the webapps directory No special code is required All public, non-static methods are exposed
Gaia Trecarichi - Web Languages Course
23 March 2009
Change the file extension from .java to .jws To view the WSDL of a JWS web service, enter
the following URL in a web browser
http://host:port/axis/file-name.jws?wsdl
JWSHandler, JWSProcessor RPCProvider classes do the job
\webapps\axis\WEB-INF\jwsClasses
23 March 2009
Pros
Cons
No
23 March 2009
Customized Deployment
deploy/undeploy multiple services deploy/undeploy handlers deploy classes with no source custom type mapping these are web service implementation classes and classes they use when using Axis webapp
Server-side classes
23 March 2009
Customized Deployment
Specifies components to be deployed and undeployed typically called Specifies type mappings
deploy.wsdd or undeploy.wsdd
outputs server-config.wsdd which is used when the server is restarted to redeploy all previously deployed services
Gaia Trecarichi - Web Languages Course
23 March 2009
WSDD To Deploy
identifies the pivot handler to be used; Axis provides three: RPC, MSG and EJB; MSG is for message or document-centric calls as opposed to RPC-style calls
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="CarQuote" provider="java:RPC"> don t need to <parameter name="className" have source value="com.ociweb.auto.CarQuoteImpl"/> for this class <parameter name="allowedMethods" value="*"/> </service> </deployment>
makes all public, non-static methods of the class available; can be a whitespacedelimited list of method names 23 March 2009 Gaia Trecarichi - Web Languages Course
WSDD To Undeploy
23 March 2009
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="CarQuote" provider="java:RPC"> beanMapping is <parameter name="className needed if a Car value="com.ociweb.cardealer.CarQuoteImpl"/> object is passed to or returned from <parameter name="allowedMethods" value="getQuote"/> a web service </service> operation <beanMapping qname="ns:Car" xmlns:ns="urn:CarQuote" languageSpecificType="java:com.ociweb.cardealer.Car"/> </deployment>
namespace 23 March 2009 Gaia Trecarichi - Web Languages Course
Steps
23 March 2009
<typeMapping xmlns:ns="urn:CarQuote" qname="ns:Car" type="java:com.ociweb.cardealer.Car" serializer="com.ociweb.cardealer.CarSerializerFactory" deserializer="com.ociweb.cardealer.CarDeserializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> </typeMapping> add as child of deployment element
23 March 2009
classes generation
WSDL2Java tool
WSDL
Generation Exercises
Steps
Use WSDL2Java tool for generating WSDD files, Skeleton (optional) and Implementation class:
java
javac
-d classes src\localhost\axis\AddFunction_jws\*.java
23 March 2009
WSDD Deployment
Copy the generated classes under ../axis/WEB-INF/classes Startup tomcat
Run
\apache-tomcat-5.5.26\bin\startup.bat
-cp %AXISCP% org.apache.axis.client.AdminClient src\localhost\axis\AddFunction_jws\undeploy.wsdd -cp %AXISCP% org.apache.axis.client.AdminClient src\localhost\axis\AddFunction_jws\deploy.wsdd \apache-tomcat-5.5.26\bin\shutdown.bat \apache-tomcat-5.5.26\bin\startup.bat
Gaia Trecarichi - Web Languages Course
[optional but adviced] Shutdown tomcat [optional but adviced] Startup tomcat
23 March 2009
Exercise 1
You should see something like that Click on wsdl link Compare the browsed wsdl with the original Where is the difference?
23 March 2009
Steps
1. Create the code for your service 2. Create the wsdd files
(deploy.wsdd
and
undeploy.wsdd) 3. Compile the service code 4. Copy the classes under /axis/WEB-INF/classes 5. Deploy the service with AdminClient 6. [optional] Create the service stubs (with WSDL2Java tool)
Note: [optional but advised] Use an Ant Task to automate the steps 3-6
23 March 2009 Gaia Trecarichi - Web Languages Course
Exercises
Exercise 2
Steps
Download the source code Open the project Lab7 Have a look to the files Calculator.java, deploy.wsdd, undeploy.wsdd, build.xml Change the properties (files build.properties) according to your settings Run the ant task deploy A service named Calculator should be created Check on the Axis page Run the ant task create-stubs see what happens Write a client to test the new deployed service
23 March 2009 Gaia Trecarichi - Web Languages Course
Exercise 3
Given: a customer order Return: a string with info concerning the order Hints & Advices: the customer order is represented by a Java Bean class which contains, among the others,
info like the customer name, the shipping address, a list of items to buy and respective quantities Create a new project (i.e., Order) Copy the files build.xml and *.properties from the project Lab7
Hints: remember to enclose in the wsdd file the type mapping using the
beanMapping tag
Exercise 4
1.
Hints: add the following lines of code in the main of the Client class
Qname qn = new QName( YourBeanNameSpace", YourBeanName" ); call.registerTypeMapping(YourBeanName.class, qn, new org.apache.axis.encoding.ser.BeanSerializerFactory(YourBeanName.class, qn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(YourBeanName.class, qn));
2.
23 March 2009
Build.xml: axis-java2wsdl
<!-=============== JAVA 2WSDL SECTION =============== --> <target name="create-wsdl" depends="do-jar" description="gen WSDL from java"> <mkdir dir="${wsdl}" /> <axis-java2wsdl classname="yourClassName" namespace="http://localhost:8080/axis/services/yourService" location="http://localhost:8080/axis/services/yourService" style="RPC" output="${j2w.wsdl}"> <classpath> <path path="${wsdl.classpath}" /> </classpath> </axis-java2wsdl> </target>
5/5/2009 Gaia Trecarichi - Web Languages Course 40
Notice that you do this for two reasons: - to generate the deploy.wsdd and the undeploy.wsdd * - to generate the stub classes (client side) to be imported in my tester class
* The option serverside="true must be enabled in order to obtain the .wsdd files
23 March 2009
Notice that when the wsdd is automatically generated, Axis puts "*SoapBindingImpl" because it takes the name from the skeleton class (which you don't use because you have already your service implementation). Actually, the class where the service is implemented is myservice.MyServiceImpl, that's why you have to change it.
23 March 2009
[optional, for cleaness purposes]: put the .wsdd files under the directory "deployment" of your project
Notice that if you skip this step, you have to set the proper lines in the project.properties file to tell Axis where are the .wsdd files: #directory containing the deployment files deployment.wsdd=deployment/deploy.wsdd undeployment.wsdd=deployment/undeploy.wsdd
23 March 2009
6.
23 March 2009
Exercise 5
Given: a customer order Return: a string with info concerning the order Hints & Advices: Create a new project (i.e., Order1) Copy the files build.xml and *.properties from the project Lab7
Hints: use target create-wsdl of build.xml
Use Java2WSDL tool to create the wsdl file Create *.wsdd files and modify deploy.wsdd properly Deploy the service Generate the service stubs and make a test client
23 March 2009 Gaia Trecarichi - Web Languages Course
Some Remarks
Use Java Beans when you want to pass complex data types as input/output parameters for your own web services.
Axis doesnt mind if you nest Java Beans as much as you want
Dont try to pass ArrayList types. Use the Java arrays instead.
23 March 2009
References
http://www.ibm.com/developerworks/webservices/library/w s-whichwsdl/#listing7
Troubleshooting
Ant Problems
Eclipse
seems to recognize an Ant file (i.e., build.xml) but cannot actually run its targets It may be a problem of Eclipse version, ant version, how Eclipse was installed. Actions
If
you have Ubuntu, avoid the Eclipse packages provided by Ubuntu. Install Eclipse by downloading it from the official website Run the ant file from the command line Tell eclipse to use an external ant installation and see what happens (last optionso far)
23 March 2009 Gaia Trecarichi - Web Languages Course
Ant Problems
It
Example:
you fixed . as a basedir property in your build.xml file and some files (i.e, the wsdl file), indicated together with a relative path (i.e, wsdl) in a .properties file (i.e, stub.properties), are not accessible.
put the absolute path for the file in question (i.e., wsdl
23 March 2009 Gaia Trecarichi - Web Languages Course
WSDL Problems
DONT SAVE
COPY AND PAST THE CONTENT OF THE WEB PAGE THE FILE AS AN XML FILE AND CHANGE THE EXTENSION TO WSDL
23 March 2009
Axis Problems
Make sure the 14 axis libraries (*.jar) are placed under %TOMCAT_HOME%/webapps/axis/WEB-INF/lib List of the libraries: activation.jar
axis-ant.jar axis.jar commons-discovery-0.2.jar commons-logging-1.0.4.jar jaxp-1.3.jar jaxrpc.jar log4j-1.2.8.jar mail.jar saaj.jar servlet-api.jar wsdl4j-1.5.1.jar xml-apis.jar, tool.jar
23 March 2009
Type the command env to display your Unix environment variables If not there, set the environmental variable AXISLIB with the command export
export
AXISLIB=/webapps/axis/WEB-INF/lib
java -cp $AXISLIB/activation.jar:$AXISLIB/axis.jar:$AXISLIB/commons-discovery0.2.jar:$AXISLIB/commons-logging1.0.4.jar:$AXISLIB/jaxrpc.jar:$AXISLIB/log4j1.2.8.jar:$AXISLIB/mail.jar:$AXISLIB/saaj.jar:$AXISLIB/wsdl4j1.5.1.jar:$AXISLIB/xml-apis.jar:$AXISLIB/axis-ant.jar Usually 8080 org.apache.axis.client.AdminClient -h yourhostname -p tomcatport /fulldeploypath/deploy.wsdd Usually 127.0.0.1 23 March 2009 Gaia Trecarichi - Web Languages Course