Sunday, 29 June 2008

How to Setup and Test Axis with Tomcat to run Web Services

See also: http://ws.apache.org/axis/java/install.html.

Installation


1. Download and install Tomcat and verify it works (http://localhost:8080)
2. Download and unpack Axis to C:\tools.
3. Copy the directory $AXISDIR\ webapps\axis in $CATALINA_HOME/webapps.
4. Download xerces and extract xercesImpl.jar and xml-apis.jar to $AXISDIR\lib.
5. Downalod JavaBeans Activation Framework and extract activation.jar to $CATALINA_HOME\webapps\axis\WEB-INF\lib and to $AXISDIR\lib.
6. Download JavaMail and extract mail.jar to $CATALINA_HOME \webapps\axis\WEB-INF\lib and to $AXISDIR\lib.
7. Copy tools.jar (from $JAVA_SDK\lib) to $CATALINA_HOME\lib.
8. Set the following environment variables:

AXIS_HOME = $AXISDIR
XIS_LIB = %AXIS_HOME%\lib
AXISCLASSPATH = %AXIS_LIB%;%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;%AXIS_HOME%;%AXIS_LIB%\wsdl4j-1.5.1.jar;%AXIS_LIB%\activation.jar; %AXIS_LIB%\mail.jar

9. Check the Axis Happiness Page: http://localhost:8080/axis/happyaxis.jsp. There should not be any warnings in the Needed Components section.

10. Test the command line admin tool. Open a command prompt and type:

java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient list

Testing: Simple A Web Service


To test that Axis is working correctly with Tomcat for simple web services:

1. Create Test.jws in $CATALINA_HOME\webapps\axis:
// Test.jws

public class Test
{
public String echoString(String test)
{
return test;
}

public String stapleString(String test1, String test2)
{
return test1 + " : " + test2;
}
}

2. Build and execute the following Java program:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class TestClient
{
public static void main(String[] args)
{
try
{
String endpoint = "http://localhost:8080/axis/Test.jws";
String ret = "";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );

call.setOperationName("echoString");
ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!' to echoString, got '" + ret + "'");

call.setOperationName("stapleString");
ret = (String) call.invoke( new Object[] { "One","Two" } );
System.out.println("Sent 'One' and 'Two' to stapleString, got '" + ret + "'");

}
catch (Exception e)
{
System.err.println(e.toString());
}
}
}

The output should be:
Sent 'Hello!' to echoString, got 'Hello!'
Sent 'One' and 'Two' to stapleString, got 'One : Two'

Testing: Deploying


1. Create Test.class from the following Test.java:

package onjava;

public class Test
{
public String echoString(String test)
{
return test;
}

public String stapleString(String test1, String test2)
{
return test1 + " : " + test2;
}
}

2. Copy Test.class to $CATALINA_HOME\webapps\axis\WEB-INF\classes\onjava.
3. Create the following deploy.wsdd file:
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Test" provider="java:RPC">
<parameter name="allowedMethods" value="echoString,stapleString"/>
<parameter name="enableRemoteAdmin" value="false"/>
<parameter name="className" value="onjava.Test"/>
</service>
</deployment>


4. Deploy the service:
java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd

Expected output:
Processing file deploy.wsdd
<Admin>Done processing</Admin>

5. Check that the Test service appears in the service list: http://localhost:8080/axis/servlet/AxisServlet
6. Build and execute the following Java program to test the serivce:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class TestClient
{
public static void main(String[] args)
{
try
{
String endpoint = "http://localhost:8080/axis/services/Test";
String ret = "";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );

call.setOperationName("echoString");
ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!' to echoString, got '" + ret + "'");

call.setOperationName("stapleString");
ret = (String) call.invoke( new Object[] { "One","Two" } );
System.out.println("Sent 'One' and 'Two' to stapleString, got '" + ret + "'");

}
catch (Exception e)
{
System.err.println(e.toString());
}
}
}


The output should be:
Sent 'Hello!' to echoString, got 'Hello!'
Sent 'One' and 'Two' to stapleString, got 'One : Two'

7. The Test.class file can also be archived in a JAR. To be found, the JAR must be copied to $CATALINA_HOME\webapps\axis\WEB-INF\lib and Tomcat restarted.

Double Disappointment

Continuing our love of live Comedy, Charlotte and I went to see Double Header at the Norwich Play House last night:

"Hattie Hayridge and Norman Lovett both starred as the face of the computer in the incredibly popular and cult TV series Red Dwarf.

"2008 is the twentieth anniversary of the program hitting the UK television screens; in celebration of this Hattie and Norman come together on stage for the very first time, creating a unique comedy evening. Although the show will feature their own inimitable stand up routines, they will also discuss their association with the poplar TV show, and fans will be able to ask them questions related everything that is Red Dwarf."

With the exception of a few brief moments, neither comic actually had anything funny to say individually. Normal Lovett was obsessed with Football, that turned off at least half the audience, and polythene bags.

It got a lot better when they were both on stage together, although Norman did dominate rather and Hattie seemed happy to let him. They were both doing their individual Holly styles throughout the show and unfortunately I just don't think it works outside of Red Dwarf. They certainly don't stand-up (excuse the pun) next to the modern comics.

Sunday, 22 June 2008

Mindcrime

I've been a Queensryche fan since 1991 when a pen pal of mine from the Netherlands sent me a tape of Empire. Back then all the bands for me that came from Seatle were either Heart or Grunge, but I loved Empire.

I read Raw Magazine back in those days before it went all Indie and all but disappeared. It spoke of the amazing Operation Mindcrime concept album and I finally found a pen pal with it and received another tape. I loved it! I quickly collected all of Queensryche's albums and have bought them all (with the exception of live albums and greatest hits) since. It's just a shame they haven't done a decent album since the follow up to Empire, Promised Land.

In 1995 I was seeing a girl in Bradford and much to my dismay, Queensryche played the week before I went to visit her, so I missed them. I finally got to see them on either the Q2K or Tribe tour, I can't remember which. I was quite disappointed with the run of poor albums, but wanted to see them anyway. They absolutely blew me away and they played so much from Operation Mindcrime.

So, now it's June 2008 and Queensryche have release Operation Mindcrime 2, which I thought was rubbish and are playing both albums all the way through on tour. Not only that, they're playing in Norwich! When Andy and I got there the queue was tiny and even as the band hit the stage the place was nowhere near capacity, but gigs are better like that. You can get closer to the band and we did get very close.

The band brought a full theatrical show. The original Operation Mindcrime was superb. They played it brilliantly. I sang until my throat was sore and then kept singing anyway. It may be twenty years old, but it's just as good today as when I first heard it in the early 90s. The second half was the second Operation Mindcrime album, which was also played very well, but I just can't get excited about it. Still, it was better than expected.

The encore almost couldn't have been better. Three tracks from Empire: Another Rainy Night, Empire and Silent Lucidity. Superb!

Queensryche are out of my system now. I don't think I'd see them again unless they do Operation Mindcrime all the way through again, play significant parts of Empire or Promised Land or release a superb album of new material (unlikely).

Altered Carbon

I was introduced to Richard Morgan by my boss, who is another Alistair Reynolds fan. Altered Carbon is part hard sci-fi and part detective novel.

I was initially quite surprised at the amount of graphic sex and violence and the crude style took some real getting used to. The story is entirely linear and entirely from the point of view of the main character, Kovacs. What makes it a real page turner is that there is so much going on and very little explained until the end where all the events are slotted together. If you hate not knowing things, this book will keep you going to find out.

The core sci-fi concept that the book relies on is the idea that a stack embedded in the back of your neck allows you to be downloaded into a new body, called a sleeve, if you die.

Once I did get used to the style I thoroughly enjoyed this book. I would recommend it and I am intending to read other books by Richard Morgan, but not before I've reread some Alistair Reynolds.

Sunday, 15 June 2008

Java Web Start

Java. I spent years avoiding it. I felt it was inferior to the power of C++. I thought it was slow, clunky, the GUI was rubbish and that garbage collection was for wimps who did not know how to clean up after themselves or use smart pointers. Ok, so we all know I was wrong. And life being the way it is, being so out spoken about Java was sure to come and bite me and it did.

Since December I have been writing Java as part of my day job and I found I liked it so much I've even started using it for some of my own projects. I do not even miss Microsoft's visual studio. I have become very attached to Eclipse and having code checked in real time, therefore negating a build stage, is very useful.

I have been so busy writing Java (and editing my new CVu column Desert Island Books) that I have not written an article on anything else for quite some time. The editor of Overload has been nagging me for material, as has the new publications officer. I have also seen a few comments here and there about how poorly Java is served by the ACCU at present, but then with a strong history in C and C++ this is to be expected. However, my plan here is to redress the balance a little.

I'm spending most of my free time (not that I have a lot these days) working on a file viewer application that allows fixed length record files in excess of 4GB to be viewed without loading the entire file into memory. I wrote one of these in C++ (MFC) for a company I worked for a number of years ago. It worked well, but was a bit clunky and the user interface looked rubbish. I think they are still using it, but I'm not sure. I have had a few failed attempts to write it in C# recently, but it was not until I had a go in Java with its JTable and TableModel classes that I really made some progress.

The file viewer is a little way off being finished, but I am starting to think about package and deployment options. I want it to be easy and one of the application I use in my day job uses Java Web Start and it works really nicely. Sun describe Java Web Start as:

Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE).

It sounds ideal for a constantly developing application that may be used by people all over the world on different operating systems.

As I sit down to write this article I have done no more that briefly read the Java Web Start documentation (so much for writing about what I know about – again!). I am intending to write an article about how to create applications and deploy them using web start by investigating it myself and writing down the steps as I go. I'll assume a reasonable familiarity with Java and Swing.

Read More

Shappi Khosandi

Last night Charlotte and I had another very pleasant meal at Pizza express in Norwich followed by the first of two Norwich Play House comedy evenings we have booked.

A few months ago I took a risk and dragged Charlotte along to see Lucy Porter. I've seen and loved Lucy Porter before, but I wasn't sure if Charlotte would like it. She loved it and said she wanted to do more comedy. That suited me just fine.

When I read about Shappi Khorsandi (this website, quoted on the flyer, doesn't appear to be there yet) in the Norwich Play House what's on guide a female, Iranian comedian who was a bit of a looker really appealed. So we both decided to take a chance.

She was supported by her husband Kristian Riemer. Both were hilarious and more than a little risqué! The quote from Shappi that sticks in my head is “American's still don't know the difference between Iran and Iraq. We're the ones with weapons of mass destruction.”

Shappi also appears on Radio 4 comedy shows. If you get the chance to see her I highly recommend it.