Send As SMS

Friday, August 11, 2006

Deploy Eclipse Web Service To Tomcat Axis

This tutorial is based upon how to deploy a developed web service in Eclipse to Apache Tomcat Server with Axis SOAP.

1) From Eclipse select the project that contains the Web Service and then highlight the source directory. Right click on the source directory and select Export->Java Jar file and then click Next.
2) The Web Service should be selected and verify that the "Export generate class files and resources" and "Export java source files and sources" check boxes are checked. Under options make sure the "Compress the contents of the jar file" and "Add directory entries" are checked". You can the select the directory and file name that you want this jar to placed. Click Finish button.
3) Copy the exported jar flie to the Axis lib directory within Apache Tomcat (ex: C:\Program Files\Apache Software Foundation\Tomcat 5.5.15\webapps\axis\WEB-INF\lib)

In addition to the web service jar file any other jars that the web service calls need to be copied into this directory.

4) Now we need to deploy the service. Start->Run->cmd

Navigate to the directory within the Web Service project where the deploy.wsdd (Web Service Deployment Descriptor) is located. (In a project like BASS there may be more than one wsdd file. Once per service.) The deploy.wsdd is created and exists within the web service project within Eclipse.

5) Startup Apache Tomcat server. (The server must be started for the Web Service to be deployed or else an error will occur.)

6) Type the following command: java org.apache.axis.client.AdminClient deploy.wsdd (deploy.wsdd would be the wsdd file name for the service that you want to deploy. In addition, if you are not in the folder where the wsdd is located you will need to add the path name as well.)

Startup the Tomcat Server. This is how Tomcat will pickup the changes that you made.)
->Manager->/axis->/view and the Web Services that you deployed should be present.

rmi tutorial and setup

In order to get a rmi server to run. In the following example three rmi sample files were created: ServerPublishInstanceData, PublishInstanceData, and ClientPublishInstanceData. In this exapmle they code was created using Eclipse but the deployment was done through the cmd prompt. The code was created under project rmiPublishInstanceData with the package name being org.rmi.publish.

The following tutorial may be used as a reference: http://java.sun.com/j2se/1.5.0/docs/guide/rmi/index.html

1. The rmiPublishInstanceData project folder was copied from the Eclipse work space and pased into a root directory folder called "RMI".
2. Eclipse has two options turned on. (1) It has the auto generate class option turned on so we do not have generate the classes for the java code. (2) My version of Eclipse has the rmi plugin and will auto generate the stub files. If you don't have the plugin you canuse the rmic command to generate the stub flies.
3. Start the rmiregistry this is performed by typing: start rmiregistry

When the rmi registry strat a different command window will open but no messages will be displayed if everything started correctly.

If the registry will not start make sure that the java directory is in the path and classpath environment variables.

4. Next you must start the rmiserver.

In my example I navigate to the c:\RMI\rmiPublishInstanceData\bin folder. Because I copied the entire project folder from Eclipse in the my RMI directory I will have a bin and a src folder. The src folder will contain the java code. The bin folder if the auto generate classes is turned on will contain the class files.

5. From the specified folder above I start the rmi server by typing the following: start java -classpath . org.rmi.publish.ServerPublishInstanceData

This should start a different window that has the server running in it. When ever the server writes anything to system out it will be written to this window.

At this point the rmi server is running.

6. If you have created a test client to run the server such as the ClientPublishInstanceData that I have created then you can follow the following steps to run the client. From the same folder as you started the server type the following: java -Djava.security.policy=c:\wideopen.policy ClientInstanceData serverNave stringValue

In this example the client took in two variables, the name of the server that it is running on and the a string value to write to a file. Also, to start the client you need to specify the policy file. In this example the policy file is located at the root of the C drive.

This example will read the string and in a loop write the string value with the count appended to it 10 times to the file. In addition, it will write the string to the output file.

The code for this example can be found on both babbage and hopper.

Thursday, August 10, 2006

Web Service Client

How to create a Web Service Client from the Web Service that was created.

1) Within the Web Service project got to WebContent->wsdl and you should see a new soap wsdl file generated from the wsdl file to create the web service.
2) Right click on the new wsdl file and select new->other->Web Services->Web Service Client (hit next)
3) On the Clicent slider select "Test Client" the top leve. In addition, select the "Monitor the Web service" check box. Click the next button.
4) Continue to click the next button until the until no longer available and then hit the Finish button.

Web Service

Setting up simple Web Service Project in Eclipse:
1) New->Other->Web->Dynamic Web Project
2) Project name and default should be valid (Finish)
3) Copy WSDL file into the WebContent folder
4) In Eclipse open project go to WebContent folder and right click on it and select new->other->Web Services->Web Service
5) Accept defaults, set Web Service slider to be "Start Service". Don't bother setting client service slider yet. Select "Publish the Web service" and "Monitor the Web Service" check boxes. Hit "Next".
6) Continue to hit "Next" button until you reach the "Web Service Publicagtion" screen and uncheck the two "Launch" buttons. Click "Finish"

Congratulations!!! You now have a Web Service

Resource Out of Synce with File System

When starting the Tomcat server from Eclipse and you receivce the message "Resources out of sync with file system" you should high light your projects and press f5 and your resources will be insync and ready to run.

Friday, August 04, 2006

Java FileWriter, XML and UTF-8

The java.io.FileWriter class doesn’t use UTF-8 by default. This causes a problem when using FileWriter to save XML, some XML parsers/editors are tolerant of the difference, some are not. Using OutputStreamWriter as follows fixes the problem:


OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");

Credit goes to the blog on the website Angus Thinks… which provided this solution.