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

 

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

Progress

1. Design for server side (JSP/Java servlet)

Based on the discussion on my previous blog, remove the embedded Jetty and make everything run in Tomcat.

On server side:

(1) JSP/servlet gets the parameters in the request from client;

(2) Start SimpleAxisServer(SAS) to call a CIMA web service;

(3) Receive the data at a listener of SAS;

(4) Write the data to a file;

(5) Send the URL of file back to client

On client side:

(1) Send the request to server;

(2) Receive the URL of the file;

(3) Parse the file content and display them on the browser

2. Implementation

(1) Server side

(a) Using Java servlet

Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

in class

public class Main extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet

(b) Using JSP

In a JSP page,

  • Get the parameters from request;
  • Call a Java method to invoke the CIMA web service and another method to write data to a file;
  • Return the URL of the file to client

(2) Client side

In Ajax, make a request either to the Java servlet or the JSP. Parse the file content and show the data on the browser via an Ajax function.

Discussion

(1) Comparison between Java servlets and JSP in this project.

Both Java servlets and JSP have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such high-level utilities. But as for outputting the result to the client, we need to write a zillion println statements to generate HTML. Plus, by separating the presentation from the content, we can separate the tasks on Web page design and servlet programming. In this project, it involves some static HTML content, and the client only needs the URL of the file, so use of a combination of JSP and servlets would simplifies the creation and maintenance of the HTML.

(2) Currently, we invoke CIMA web service by start a SimpleAxisServer, but in SimpleAxisServer API, there is a note -- This is a simple implementation of an HTTP server for processing SOAP requests via Apache's xml-axis. This is not intended for production use. Its intended uses are for demos, debugging, and performance profiling. Note this classes uses static objects to provide a thread pool, so you should not use multiple instances of this class in the same JVM/classloader unless you want bad things to happen at shutdown.

So 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

  • JSP : the complete reference. Hanna, Phil.
  • Core servlets and JavaServer pages. Hall, Marty; Brown, Larry

Status Report for 12/26/2007 -- 01/09/2008

Progress

1. Design for server side (Embedded Jetty)

In this design, we embedded Jetty into our Java applications and used it as the core HttpServer, an HTTP server with the ability to serve static content and servlets.

The basic idea is to implement a handler in the servlet and start a jetty server with it. Once the jetty server gets a request from the jetty port, the handler will get the parameters and start SimpleAxisServer(SAS) to call a CIMA web service and then get the data at a listener of SAS.

2. Implementation

(1) Create an instance of the Jetty server (org.mortbay.jetty.Server) listening at some port, but does not start the server.

Server server = new Server();

Connector connector=new SelectChannelConnector();

connector.setPort(some port);

server.setConnectors(new connector[]{connector});

(2) Add resource handlers which will get the parameters from the client’s request and start the web service.

Handler param = new ParamHandler();
Handler rqst = new RqstHandler();
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{rqst, param});

server.setHandler(handlers);

(3) Start the Jetty server.

server.start();

server.join();

(4) Set up the embedded axis server with deployment descriptor generated by WSDL2Java

SimpleAxisServer server = new SimpleAxisServer();

ServerSocket WSserverSocket = new ServerSocket(someport);

WSserverSocketPort = WSserverSocket.getLocalPort();

server.setServerSocket(WSserverSocket);

server.setMyConfig(wsdddoc.getDeployment());

server.start();

set up the call to the CIMA service


String endpointURL = new String(some IP address);
Call call = new Call(endpointURL);
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName(somename);
call.addParameter(……);

call.invokeOneWay(……);

Discussion

On the client side, Ajax is being used for this web application. In a standard way, making a request to a servlet/JSP page on the server in Tomcat would be much easier and convenient. So instead of using embedded Jetty, we can just use servlet/JSP page to get the parameter and call a web service and send the response to client. In that case, everything on the server is running in the Tomcat, and just one port is necessary.