Thursday, January 31, 2008

Status Report for 01/23/2008 -- 01/30/2008

Progress

Based on the discussion in my previous posts, I did some work on Axis 1.4 for the project.

1. Install and Deploy Apache Axis 1.4

(1) Make sure that we have

· J2SE SDK 1.5

· A Servlet Container: Tomcat 5.5.17

(2) Download axis-bin-1.4.zip from http://apache.oc1.mirrors.redwire.net/ws/axis/1_4/

(3) Unzip it and look at the dir. tree. Note that Axis runs as a Servlet.

(4) Deploy Axis.

· Copy webapps/axis tree to webapps directory of Tomcat.

· Alternatively, modify server.xml of Tomcat.

(5) Run Tomcat: issue bin/startup from Tomcat home.

Direcotry Structure:

axis-1_0

docs

lib

samples

webapps

axis

WEB-INF

lib

classes

web.xml

(6) Test the Deployment

(a) Point my browser to http://localhost:8080/axis

(b) Click the link "Validate", an error message and two warnings were shown on the next page.

Error: could not find class javax.activation.DataHandler from file activation.jar

Axis will not work

See http://java.sun.com/products/javabeans/glasgow/jaf.html

Optional Components

Warning: could not find class javax.mail.internet.MimeMessage from file mail.jar

Attachments will not work

See http://java.sun.com/products/javamail/

Warning: could not find class org.apache.xml.security.Init from file xmlsec.jar

XML Security is not supported

See http://xml.apache.org/security/

The core axis libraries are present. 2 optional axis libraries are missing

(7) Shutdown Tomcat, and follow the instructions above to

(a) download the zip files;

(b) unzip these files;

(c) find the jar files;

(d) copy them to $CATALINA_HOME/webapps/axis/WEB-INF/lib

activation.jar, mail.jar, xmlsec-1.4.1.jar are in jaf-1_1_1.zip, javamail-1_4_1.zip, xml-security-bin-1_4_1.zip respectively.

(8) Startup Tomcat, and run http://localhost:8080/axis

2. A test Web Services Using Apache Axis

The easiest way is to simply copy any independent Java class into our Axis web application directory and access it via SOAP remotely.

(a) developing the Java class,

(b) deploying it,

(c) building and running a client to access it.

(1) Developing a Java class

Try out a Hello World -style class which has one method, called greet() that takes someone's name as a parameter and returns a nice greeting message with that person's name.

(a) Locate the $AXIS_HOME/samples directory;

(b) Create a new subdirectory called "hello";

(c) In this subdirectory, create the file Hello.java, and include the following code;

public class Hello {

public String greet(String a_name) {

return "Nice to meet you, "+a_name;

}

}

(d) Copy it into $TOMCAT_HOME/webapps/axis and name it Hello.jws

(2) Building a client to access our service.

Develop the client code in the file HelloClient.java, which we will store at $AXIS_HOME/samples/hello. HelloClient.java needs to do the following:

· Connect to the our Hello service (a SOAP endpoint)

· Invoke the service method remotely, marshalling parameters in and out.

· Print out the reply from the service.

Below is code for HelloClient.java that enables this:

package samples.hello;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.axis.encoding.XMLType;

import org.apache.axis.utils.Options;

import javax.xml.rpc.ParameterMode;

public class HelloClient

{

public static void main(String [] args) throws Exception {

Options options = new Options(args);

String endpoint = "http://localhost:" + options.getPort() + "/axis/Hello.jws";

args = options.getRemainingArgs();

if (args == null || args.length != 1) {

System.err.println("Usage: Hello ");

return;

}

Service service = new Service();

Call call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName("greet");

call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);

call.setReturnType(XMLType.XSD_STRING);

String msg = (String)call.invoke(new Object[] {args[0]});

System.out.println("Reply: " + msg);

}

}

Compile this client: javac samples/hello/HelloClient.java

Run the client: java samples.hello.HelloClient -p8080 Greg

which returns the message:

Nice to meet you, Greg!

Discussion

Based on the previous discussion, it is necessary to remove SimpleAxisServer and just use Axis as an engine to invoke the web service.

http://ws.apache.org/axis/java/apiDocs/org/apache/axis/transport/http/SimpleAxisServer.html

Reference

·         http://www.javaranch.com/journal/2002/05/axis.html
http://ws.apache.org/axis/java/user-guide.html#CustomDeploymentIntroducingWS

 

No comments: