SESSION 5: WEB SERVICES ======================= 0.- Understand what RMI is and how it works. A good starting point is: http://en.wikipedia.org/wiki/Webservices 1.- Setting everything: - TOMCAT (Web server) bash insttomcat - AXIS (Web service framework) wget http://studies.ac.upc.edu/FIB/PXC/lab/bin/axis-1_1.tar.gz tar xzf axis-1_1.tar.gz - XERCES (packages for parsing and manipulating XML) wget http://studies.ac.upc.edu/FIB/PXC/lab/bin/xerces.jar mv xerces.jar axis-1_1/webapps/axis/WEB-INF/lib/ cp -R axis-1_1/webapps/axis/ ~/tomcat/webapps/ - JAF (JavaBeans Activation Framework) wget http://docencia.ac.upc.edu/FIB/PXC/lab/bin/jaf-1_1-fr.zip unzip jaf-1_1-fr.zip cp jaf-1.1/activation.jar ~/tomcat/webapps/axis/WEB-INF/lib/ - AXIS.XML mkdir ~/tomcat/conf/Catalina/ mkdir ~/tomcat/conf/Catalina/localhost/ # Create 'axis.xml': 8<---------------------------------------------------------------------- ---------------------------------------------------------------------->8 cp axis.xml ~/tomcat/conf/Catalina/localhost/ - COPYING TOOLS.JAR: # We do this to avoid the error # "No compiler found in your classpath! (you may need to add tools.jar)" # when executing 'CalcClient' below. cp /usr/lib/jvm/java-1.6.0-sun-1.6.0/lib/tools.jar ~/tomcat/webapps/axis/WEB-INF/lib 2. Start Tomcat: - CLASSPATH # Create 'setCLASSPATH.sh': 8<---------------------------------------------------------------------- #!/bin/bash export AXIS_HOME=$(pwd)/axis-1_1 export TOMCAT_HOME=$HOME/tomcat export CLASSPATH=.:$AXIS_HOME:$AXIS_HOME/lib/axis.jar:$AXIS_HOME/lib/jaxrpc.jar:$AXIS_HOME/lib/saaj.jar:$AXIS_HOME/lib/commons-logging.jar:$AXIS_HOME/lib/commons-discovery.jar:$AXIS_HOME/lib/wsdl4j.jar:$TOMCAT_HOME/webapps/axis/WEB-INF/lib/xerces.jar ---------------------------------------------------------------------->8 source setCLASSPATH.sh - START TOMCAT tomcat start 3. Run the calculator example: cp axis-1_1/samples/userguide/example2/Calculator.java ~/tomcat/webapps/axis/Calculator.jws java samples.userguide.example2.CalcClient -p8080 add 2 5 4. Use tcpmon to monitor WebServices messages: java org.apache.axis.utils.tcpmon & # Set tcpmon to listen 8000 & target 8080 java samples.userguide.example2.CalcClient -p8000 add 2 5 5. Run the BotigaWeb example: mkdir botigaWeb # Create botigaWeb/BotigaWeb.java: 8<---------------------------------------------------------------------- package botigaWeb; public interface BotigaWeb { // Method that returns the price of a product public float veurePreu(String producte); } ---------------------------------------------------------------------->8 # Crear botigaWeb/BotigaWebImpl.java: 8<---------------------------------------------------------------------- package botigaWeb; public class BotigaWebImpl{ float preu = 10.0F; public float veurePreu(String producte){ return preu; } } ---------------------------------------------------------------------->8 javac botigaWeb/BotigaWeb.java # If you're not using 'tcpmon', port in the following command should be 8080 # instead of 8000 java org.apache.axis.wsdl.Java2WSDL -o botigaWeb.wsdl -l"http://localhost:8000/axis/services/botigaWeb" -n urn:botigaWeb -p"botigaWeb" urn:botigaWeb botigaWeb.BotigaWeb java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p botigaWeb.ws botigaWeb.wsdl # Edit botigaWeb/ws/BotigaWebSoapBindingImpl.java adding the lines that start # by '+': 8<---------------------------------------------------------------------- package botigaWeb.ws; +import botigaWeb.BotigaWebImpl; public class BotigaWebSoapBindingImpl implements botigaWeb.ws.BotigaWeb{ + BotigaWebImpl botiga = new BotigaWebImpl(); public float veurePreu(java.lang.String in0) throws java.rmi.RemoteException { + return botiga.veurePreu(in0); } } ---------------------------------------------------------------------->8 javac -source 1.4 botigaWeb/ws/*.java jar cvf botigaWeb.jar botigaWeb/*.class botigaWeb/ws/*.class mv botigaWeb.jar ~/tomcat/webapps/axis/WEB-INF/lib/ # If you're not using 'tcpmon', port in the following command should be 8080 # instead of 8000 java org.apache.axis.client.AdminClient -p8000 botigaWeb/ws/deploy.wsdd # Create botigaWeb/BotigaWebTester.java: 8<---------------------------------------------------------------------- package botigaWeb; public class BotigaWebTester{ public static void main (String [] args) throws Exception{ // Creates service botigaWeb.ws.BotigaWebService service = new botigaWeb.ws.BotigaWebServiceLocator(); // Uses service to obtain the service stub botigaWeb.ws.BotigaWeb botiga = service.getbotigaWeb(); // Calls the service System.out.println("Preu: " + botiga.veurePreu("aa")); } } ---------------------------------------------------------------------->8 javac botigaWeb/BotigaWebTester.java java botigaWeb.BotigaWebTester #Important: If you want to repeat point #5 with a different port, first make a backup copy of the file BotigaWebSoapBindingImpl.java to another directory and delete the original file before running WSDL2Java. After doing WSDL2Java copy the file back. 6. Implement a WebService that does the car rental requests and the list of requests.