Deploying to Tomcat

•June 17, 2008 • Leave a Comment

My next goal was to deploy the book service to tomcat instead of the small http server included with Axis2.

I created a small build3.xml file which creates the .aar file from class files & resources.

I created an empty NetBeans web application project.

I unzipped the axis2.war file and copied axis2-web to the web directory.

I copied everything under WEB-INF to WEB-INF.

Then I ran the “Build main project” and “Run main project”.

This ran correctly.

Next I copied the BookDB.aar created by build3.xml into build/web/WEB-INF/services

But this is not enough to get the BookDB service deployed.

WSDL to Java using Axis2

•June 15, 2008 • Leave a Comment

I just used Axis2 to generate code from the WSDL I generated earlier with Microsoft Visual Studio. I’m posting the batch file in the hope that it will save someone else a few minutes.

rem change this to the uri or path to your wsdl
set WSDL=”schema\book.wsdl”

rem check JAVA_HOME, ANT_HOME, and AXIS2_HOME settings

rem make sure that the java bin directory is in your path
echo PATH=%PATH%

REM setup the classpath painfully
set AXIS2_LIB=%AXIS2_HOME%\lib\
set CP=%CP%;%AXIS2_LIB%activation-1.1.jar
set CP=%CP%;%AXIS2_LIB%annogen-0.1.0.jar
set CP=%CP%;%AXIS2_LIB%axiom-api-1.2.7.jar
set CP=%CP%;%AXIS2_LIB%axiom-dom-1.2.7.jar
set CP=%CP%;%AXIS2_LIB%axiom-impl-1.2.7.jar
set CP=%CP%;%AXIS2_LIB%axis2-adb-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-adb-codegen-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-ant-plugin-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-clustering-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-codegen-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-corba-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-fastinfoset-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-java2wsdl-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-jaxbri-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-jaxws-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-jaxws-api-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-jibx-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-json-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-jws-api-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-kernel-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-metadata-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-mtompolicy-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-saaj-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-saaj-api-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-spring-1.4.jar
set CP=%CP%;%AXIS2_LIB%axis2-xmlbeans-1.4.jar
set CP=%CP%;%AXIS2_LIB%backport-util-concurrent-3.1.jar
set CP=%CP%;%AXIS2_LIB%commons-codec-1.3.jar
set CP=%CP%;%AXIS2_LIB%commons-fileupload-1.2.jar
set CP=%CP%;%AXIS2_LIB%commons-httpclient-3.1.jar
set CP=%CP%;%AXIS2_LIB%commons-io-1.4.jar
set CP=%CP%;%AXIS2_LIB%commons-logging-1.1.1.jar
set CP=%CP%;%AXIS2_LIB%geronimo-annotation_1.0_spec-1.1.jar
set CP=%CP%;%AXIS2_LIB%geronimo-stax-api_1.0_spec-1.0.1.jar
set CP=%CP%;%AXIS2_LIB%httpcore-4.0-beta1.jar
set CP=%CP%;%AXIS2_LIB%httpcore-nio-4.0-beta1.jar
set CP=%CP%;%AXIS2_LIB%jalopy-1.5rc3.jar
set CP=%CP%;%AXIS2_LIB%jaxb-api-2.1.jar
set CP=%CP%;%AXIS2_LIB%jaxb-impl-2.1.6.jar
set CP=%CP%;%AXIS2_LIB%jaxb-xjc-2.1.6.jar
set CP=%CP%;%AXIS2_LIB%jaxen-1.1.1.jar
set CP=%CP%;%AXIS2_LIB%jettison-1.0-RC2.jar
set CP=%CP%;%AXIS2_LIB%jibx-bind-1.1.5.jar
set CP=%CP%;%AXIS2_LIB%jibx-run-1.1.5.jar
set CP=%CP%;%AXIS2_LIB%log4j-1.2.15.jar
set CP=%CP%;%AXIS2_LIB%mail-1.4.jar
set CP=%CP%;%AXIS2_LIB%mex-1.4.jar
set CP=%CP%;%AXIS2_LIB%neethi-2.0.4.jar
set CP=%CP%;%AXIS2_LIB%soapmonitor-1.4.jar
set CP=%CP%;%AXIS2_LIB%woden-api-1.0M8.jar
set CP=%CP%;%AXIS2_LIB%woden-impl-dom-1.0M8.jar
set CP=%CP%;%AXIS2_LIB%wsdl4j-1.6.2.jar
set CP=%CP%;%AXIS2_LIB%wstx-asl-3.2.4.jar
set CP=%CP%;%AXIS2_LIB%xalan-2.7.0.jar
set CP=%CP%;%AXIS2_LIB%xercesImpl-2.8.1.jar
set CP=%CP%;%AXIS2_LIB%xml-apis-1.3.04.jar
set CP=%CP%;%AXIS2_LIB%xml-resolver-1.2.jar
set CP=%CP%;%AXIS2_LIB%xmlbeans-2.3.0.jar
set CP=%CP%;%AXIS2_LIB%XmlSchema-1.4.2.jar

REM -s synchronous style code only
REM -uri
REM -o output directory
REM -ss generate server side code
REM -sd generate service descriptor
REM -g generate all the classes (use with ss)
REM -ssi generate an interface

REM defining W2J so the command will not wordwrap in the blog
set W2J=org.apache.axis2.wsdl.WSDL2Java

java -cp %CP% %W2J% -uri %WSDL% -ss -sd -s -o gensrc -g -ssi

Making a WSDL Using Visual Studio

•June 14, 2008 • Leave a Comment

I recently figured out how to use MS Visual Studio to generate a WSDL to use for some web service methods I planned to write in Java. It was very easy and painless. A month or so later, I wanted to generate a new WSDL and I drew a complete blank on the “easy procedure”. So this time I’m writing it down.

Background: The web services will provide an alternate method of interacting with a book database application. The page below shows the information I’m collecting on each book.

website sample page

Procedure: Start up Visual Studio and create a new project. Select ASP.NET Web Service Application. Note: you’ll need something better than the free MS Visual Studio Express because it doesn’t support web services.

This next step is quite optional. From screen shot of the book database you can see that I will be transferring a list of data items about each book. So following good object-oriented techniques, I’m making a class (really a data bean) to bundle these together.

Service1.asmx.cs was created automatically by Visual Studio when the project was created. Here’s what it originally looked like. Note that any method that should be exposed as a webservice is annotated with [WebMethod] and that Studio has written a hello world one for you.

After editing, the Service1.asmx.cs now looks like this. I tried to change Service1 something more appropriate but doing a simple rename through the Solution Explorer is not enough. So I’ve left it unchanged. I updated the namespace. And I’ve added create, read, update, delete (CRUD) methods, along with search and a few others.

As much as possible I’m passing databeans or arrays of databeans. For some reason, Studio won’t let you use Hashtable as a return type so I had to create my own simple minded Pair class.

Now we are really ready to get results. Choose Debug -> Start Debugging.

Studio launches IE and displays this page with the available web service methods. Note: This is the part that doesn’t work if you try to change Service1 to something else and just rename the .asmx.cs file.

Click on the Service Description link to see the WSDL. Save this and you are done!