View Christos Tranoris's profile on LinkedIn


Visit The Model Driven Software Network

Who's online

There are currently 0 users and 10 guests online.

Recent comments

Syndicate

Syndicate content

Tutorial 1: Creating Web Services in Eclipse (Bottom Up)

(Please check also the update Tutorial with Helios here)
The purpose of these series Tutorial (updated with eclipse galileo) is to introduce tools needed, setup and initial guidelines for Service Oriented Applications.
Since there are many tutorials out there, this text will provide urls that point to each step and fill any gap between them. Web Services, Service Orchestration, Enterprise Service Buses and Business Rules Engine will be explored during these tutorials. The tool that we will mainly use as development platform is Eclipse. One might debate for NetBeans 6 (i.e. for a fair comparison see http://www.javaworld.com/javaworld/jw-03-2008/jw-03-java-ides0308.html?page=4). It's plugin ecosystem, OSGi based architecture makes it though my personal favorite choice.
We will start by just downloading the latest version of Eclipse. Download the EE bundle. Although one could use Yoxos and create a custom Eclipse download, we will just use Eclipse's update feature and install things as we go. You will need also a JDK. During this tutorial jdk1.6.0_12 is used.
 
These tutorials use Eclipse 3.5.0 (galileo). Just unzip your Eclipse file on your hard disk. As a rule of thumb, try to have different Eclipse installations for different needs, thus making your environment lighter. I.e. don't load your Java EE Eclipse with C/C++ plugins. (I have it under C:\eclipse-jee-galileo-win32)

Creating Bottom Up web services is the most simpler way, since you just make your POJO and you let to Eclipse the hard work to create WSDL, deploy service, etc.
Before starting your web services development, we need Apache Tomcat. So, download it and install it on your machine. During this tutorial we have used Apache Tomcat 6.0.18 Server. I used Windows Service Installer (since during this tutorial is made on Windows Vista. Linux would be a much more serious choice! ).
To configure your Apache Server in Eclipse,

·        Open Window -> Preferences -> Server -> Runtime Environments to create a Tomcat installed runtime.
·        Click on Add... to open the New Server Runtime dialog, then select your runtime under Apache (Apache 6.0 from the list). “Create a new local server” must be checked when adding the Apache Tomcat runtime environment. (This is usefull so not to mess up your actual web services with your web services that you are developing and testing)
·        Put your Tomcat installation dir C:\Program Files\Apache Software Foundation\Tomcat 6.0 and finish.
·        In the Servers panel, you will see the Tomcat server Stopped. In the Project Explorer view, a Server configuration will appear.
·        If you run the Server you might encounter an error if your Tomcat is already running. So you must configure different ports for your installation , otherwise you must stop your Tomcat server while you are developing and testing your web services. If you double click the server, the local configuration will appear. Change the ports as you wish and the Right Click the server Icon and select Start to start the server
 
 Before continuing we will need Apache Axis( an implementation of the SOAP). Download it from here. (This tutorial uses axis2-1.4.1.)
Save it for example on c:\axis2-1.4.1 and point Eclipse WTP to downloaded Axis2 Runtime. Open Window -> Preferences -> Web Services -> Axis2 Preferences and put there the path of Axis2.
On preferences check Generate an interface for the skeleton and Click OK
A nice Creating Bottom Up Web Service tutorial could be found here with similar action. However in this tutorial things are updated.
Create a project "ResourceA" with the support of Axis2 features. Open File -> New -> Other... -> Web -> Dynamic Web Project
  

 On the configuration click Modify..and check the Axis2 Web Services, click OK and Finish
 
Create a package named pkg (Right click on Java Resources ->New->Package) and a class name MyService (Right click on Java Resources->New->Class) . At the end you will have something like the following:
  

 Write the small Java code:
public class MyService {
public MyService() {
}
public Boolean Configure(String param, String val){
return true;
}
public Boolean StartMe(){
return true;
}
public Boolean StopMe(){
return true;
}
public String getStatus(){
return "No status available!";
}
}
Save it and Select the MyService.java file Right click and (down on the menu) Web Services -> Create Web Service
On the window that appears just click the Web Service Run Time and on the dialog select Apache Axis2

Click Next and leave the default services.xml.
Click Next and if prompted Start the server (remember here the ports otherwise the server will not run!) 
The ResourceA now is deployed and start in our Tomcat server (remember the Eclipse copy of Tomcat (listens on 8081) not your system Tomcat (listens on 8080))
   
 
Now if you Select the ResourceA project, right-click and select Run -> Run As -> Run on Server you will go to http://localhost:8081/ResourceA/ which is a not found. (I don’t know why yet.Is this a bug?)
Just change it with the correct http://localhost:8081/ResourceA/axis2-web/index.jsp . You will get the home page:
 
 
Click on services. Check that your web service is Active. Check also the available Operations:
  

 If you click on the MyService link you will get the WSDL of your service (http://localhost:8081/ResourceA/services/MyService?wsdl)
 Copy this link on your clipboard.
 
Go to menu Run-> Launch the Web Services Explorer, and select from the icons the WSDL
 

Click on WSDL Main and paste the wsdl address, click Go.
  

 
The service will open. Just go for ie MyServiceSoap11Binding find the getStatus and click Go. A Soap call will be invoked and the message in the Body of the response will appear.
 

 
During this tutorial we created our first Web Service with Eclipse Web Tools Platform. In this tutorial here a Java client is also created that utilizes a web service.
To deploy your service on your Tomcat server, just right click the project ResourceA choose Export->WAR file.
 
Probe further:
 
The alternative way of Top-Down can be found in other tutorials. Check also a nice tutorial here.
Here you can find a nice getting started guide with Web Tools Platform. 

Posted in Submitted by tranoris on July 6, 2009 - 10:46.



tranoris | June 17, 2009 - 17:08

Well the mistake is that the web service is not persistent. Once you call it, the service is instantiated, returns you something and then is destroyed. So when you call it back, actually a new instance is created. If you really want to store the status then you need to put it somewhere in a file or in a database

Anonymous | June 17, 2009 - 17:38

Thankx alot for your help..
I have another question regarding this issue:
if my service client invoke a method in the web service, and the web service suppose to send this value to another client "such as .net application , or flex client" , is that possible with axis technology..
Regards
Salwa

tranoris | June 18, 2009 - 11:50

The axis technology gives SOAP support to your web service. If you want your web service to communicate with other web services, this is possible if the other web services support SOAP.

Anonymous | January 26, 2010 - 23:09

I wish I could write some like this (I might try).
So thanks for a GREAT tutorial.
I had problems with the Axis2 1.5, and missed that in the documentation.

According to the documentation, Axis2 could also handle REST, not just SOAP. But I have to check that out, now when I works.

(All documentation should be like this at Eclipse.org! The quality and tha great number of tutorials and such to NetBean on their web site also a very strong point of using that instead of Eclipse)

Anonymous | December 17, 2010 - 06:50

Great Documentaiton Work

Anonymous | January 18, 2011 - 12:46

The other methods are working fine. But the configure method always receive null argument values. I am using Axis2 1.4.1. Any idea ?