Web Services For Java

Creating clients for Web Services

 * Download Apache Axis
 * Bellow you can find a syntax to generate the java code automatically for a given WSDL.

java -Djava.ext.dirs= org.apache.axis.wsdl.WSDL2Java 


 * Change the  to the corresponding Apache Axis lib directory. Use quotes (windows) or single quotes (unix) for long directory names with spaces.


 * Change the  for the desired local WSDL file or for the url where the WSDL is.

Example: Open the console and type the following:

java -Djava.ext.dirs='/home/jaraujo/dev/Apache Axis 1.4/lib' org.apache.axis.wsdl.WSDL2Java http://www.nanonull.com/TimeService/TimeService.asmx?WSDL

You can create some batch file to do the job. For example create the file for windows:

rem SET THE PATH FOR THE AXIS LIBRARIES java -Djava.ext.dirs= org.apache.axis.wsdl.WSDL2Java %1

echo. echo. Ready. Check for new directories. echo.

Or for example create the file for unix:

java -Djava.ext.dirs= org.apache.axis.wsdl.WSDL2Java $1
 * 1) SET THE PATH FOR THE AXIS LIBRARIES

echo echo "Ready. Check for new directories." echo


 * Take a look for new folders in your current directory. There will be some classes like YourServiceLocator and YourServiceSoap.


 * Now you are ready to use the web service. Take a look bellow for an example:

import java.util.Locale; import java.util.TimeZone;

import org.apache.axis.client.Stub;

import com.Nanonull.www.TimeService.TimeServiceLocator; import com.Nanonull.www.TimeService.TimeServiceSoap;

public class Test {

public static void main (String args[]) {			try { // These 2 lines will always be similar: TimeServiceLocator locator = new TimeServiceLocator; TimeServiceSoap soap = locator.getTimeServiceSoap; // don't delete this org.apache.axis.client.Stub s =(Stub) soap; s.setTimeout(10000); // 10 seconds

// s.setUsername("testuser"); // s.setPassword("testpasswd"); // some action with the webservice System.out.println("-- SERVER INFORMATION --"); System.out.println(soap.getServerCity); System.out.println(soap.getServerTime); System.out.println(soap.getUTCTime); } catch(Exception e) { e.printStackTrace; }	 } }

Creating Web Services

 * Create a web project using Eclipse.
 * Copy the file of the installation directory of Apache Axis into  directory of your application.
 * Copy all the jar files form the lib directory of the installation directory of Apache Axis into the directory of your application.
 * Copy the jar file "jaf-*.zip" for JavaBeans Activation Framework into the directory.
 * Copy the jar file "javamail-*.zip" for JavaMail into the directory.
 * Copy the jar file "xmlsec-*.jar'" for XML Security into the directory.
 * Create packages and classes that will be used as web services.

Web Service Deployment Descriptor (WSDD)

 * Create the file, describing the web services, classes, allowed methods, scope, etc. :

    

A reference about this file is found under http://www.oio.de/axis-wsdd/


 * I am not sure, but I think that you should generate a node for each class. In other words, each class will be a new web service.

Deploying the Web Service

 * Start Tomcat. I used the Sysdeo Tomcat Plugin for Eclipse.


 * To deploy the web service open a console window and change the directory (use the cd command) to the directory of your application. Run the command:

java -Djava.ext.dirs=./lib org.apache.axis.client.AdminClient -s /soa/servlet/AxisServlet


 * The class AdminClient uses the following default values:
 * Search a file "deploy.wsdd"
 * Uses the localhost and the context path /axis
 * The default port is 8080


 * You can also create a script (, for example) to deploy automatically the web services:


 * 1) Usage:  AdminClient [Options] [list | ]
 * 2) Processes a set of administration commands.
 * 3) The following Options are available:
 * 4)        -l         sets the AxisServlet URL
 * 5)        -h  sets the AxisServlet port
 * 7)        -s sets the path to the AxisServlet
 * 8)        -f    specifies that a simple file protocol should be used
 * 9)        -u    sets the username
 * 10)        -w    sets the password
 * 11)        -d              sets the debug flag (for instance, -ddd would set it to 3)
 * 12)        -t        sets the transport chain touse
 * 13) Commands:
 * 14)        list            will list the currently deployed services
 * 15)        quit            will send a quit message to SimpleAxisServer
 * 16)        passwd          value changes the admin password
 * 17) If -l or -h -p -s are not set, the AdminClient will invoke
 * 18) http://localhost:8080/axis/servlet/AxisServlet
 * 1)        list            will list the currently deployed services
 * 2)        quit            will send a quit message to SimpleAxisServer
 * 3)        passwd          value changes the admin password
 * 4) If -l or -h -p -s are not set, the AdminClient will invoke
 * 5) http://localhost:8080/axis/servlet/AxisServlet
 * 1) http://localhost:8080/axis/servlet/AxisServlet

echo echo "Generating/Updating the file server-config.wsdd" echo

java -Djava.ext.dirs=./lib org.apache.axis.client.AdminClient -s /soa/servlet/AxisServlet gen

echo echo "Ready. Check the file server-config.wsdd" echo


 * The file will be generated. This file will be used when Apache Tomcat starts.


 * Done. Now you can test it to know if the web service was really deployed: http://localhost:8080/soa/services/MyWebService?wsdl


 * For this example I did not used the default context path /axis. I used instead the context called soa. Therefore in this case I should use some parameters with the class AdminClient.