View Christos Tranoris's profile on LinkedIn


Visit The Model Driven Software Network

Who's online

There are currently 0 users and 6 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.



Anonymous | December 29, 2012 - 20:04

for all those people getting any error, try troubleshooting it by using the eclipse tcp/ip monitor

Anonymous | November 29, 2012 - 00:14

Really helpful, Thanks!

Anonymous | October 28, 2011 - 16:40

I can create simple web services but I need save some data during web service invocation.I don't know how I can do it.
Thank you for your time and consideration.
Best,
Mahdi
sargol2001@yahoo.com

Anonymous | September 16, 2011 - 13:00

Good example for new learners

Anonymous | August 29, 2011 - 06:10

Thank you for the tutorial !
I followed it and got a simple service running.

Anonymous | August 3, 2011 - 12:23

thank you very much for this tutorial,
i have a problem when i want to connect my web service to mysql database
in a java project, i have created a package named: com.server which has a class named: Base.
this class contains a method named connect()
i have added a main method to test the connection and it works very well.
now, the problem is in the following step:
i want to create a web service
i select the Base.java file Right click and Web Services -> Create Web Service
the Web Service window appears, when i click next i have the following message:
"The service class "com.server.Base" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly.
  The method "connect" on the service class "com.server.Base" uses a data type, "java.sql.Connection", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result."

how can i connect my web service to my database correctly?
& thank you again for this tutorial :D

Anonymous | July 6, 2011 - 09:45

This a wonderful artical for learning.Thanks for this

Anonymous | June 16, 2011 - 17:24

Hi,
I can see the wsdol but i ma getting the error IWAB0135E An unexpected error has occurred 403 Forbidden. Can you help me out on this!! :(

Anonymous | June 3, 2011 - 12:48

Nice tutorial. The example is so simple and easy to understand.
 

Anonymous | May 24, 2011 - 23:44

Gracias por la ayuda! .. Excelente Tutorial!

Anonymous | January 10, 2011 - 13:56

when running the web service run time it is throwing an error msg that it is unable to copy the axis2 and what is the reason for this exception

Anonymous | December 14, 2010 - 22:09

Good tutorial.  More up-to-date than than the Eclipse tutorial.  I ran into one problem where an exception thrown upon deploying the service in Tomcat.  The exception said that some class from org.apache.xmlbeans couldn't be found.  I downloaded xmlbeans, installed the JARs in the lib directory, and all worked.
Mike

Anonymous | December 6, 2010 - 08:50

when I do this,
Open Window -> Preferences -> Server -> Runtime Environments to create a Tomcat installed runtime
I dont see the list of the Apache Runtimes.
I am using Version: Helios Service Release 1 Build id: 20100917-0705.
I have installed Tomcat 6.0 and Tomcat 7.0 using Windows Service Installer. I can see the 6.0 and 7.0 under C:\Program Files\Apache Software Foundation.
Tried search by specifying the C:\Program Files folder. But still cant see the apache runtimes.
please let me know what could be problem.
Thanks in advance.

Anonymous | November 1, 2010 - 14:36

Hi,
Very nice,useful article it work for me.
Initially Clicking on Services gave me following Error ,
noClassDefinitionFound org.apache.http.httpResponsefactory
Then I downloaded httpcore-4.0.1.jar and added it to the apache-tomcat-6.0.29\lib folder and it gets solved.
Thanks.

Anonymous | October 27, 2010 - 15:41

Great Article.... Clear and descriptive... and the comments from you guys are so useful ... Thanks All.

I have a problem after applying all what in the article and after getting the axis2 1.4.1, that is after copying the location of my wsdl to the web services explorer I go the below message message .. Would any body help me in this case? Thank you

On the status area I got

IWAB0379E Unable to open http://localhost:8080/MyWebService/services/Majdoub/.
IWAB0135E An unexpected error has occurred.
WSDLException
WSDLException: faultCode=OTHER_ERROR: Server returned HTTP response code: 500 for URL: http://localhost:8080/MyWebService/services/Majdoub/

and on the console I got

[ERROR] The endpoint reference (EPR) for the Operation not found is /MyWebService/services/Majdoub/ and the WSA Action = null
org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /MyWebService/services/Majdoub/ and the WSA Action = null
at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:89)
at org.apache.axis2.engine.Phase.invoke(Phase.java:333)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)
at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)
at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)
at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)
at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)

Anonymous | May 31, 2011 - 10:02

am too getting the same sort of trouble.........er, lemme know if u can get soem lead....

tranoris | October 27, 2010 - 19:19

Check also the update: http://www.softwareagility.gr/index.php?q=node/28 What version of eclipse are you using?

Anonymous | October 28, 2010 - 07:55

Thanks for the prompt response ... I am using Eclipse Java EE IDE for Web Developers - Galileo 3.5.2 ...

Anonymous | October 28, 2010 - 08:11

Tomcat: apache-tomcat-6.0.20
Axis : Axis2-1.4.1

I tried Axis2-1.5.2, but I got an error same as the one the guys talked about, so I tried the 1.4.1 following their advice.

Anonymous | October 28, 2010 - 14:03

Dear Tranoris,
It is solved now .. It worked on both axis2-1.2.1 and axis2-1.4.1 except that the latter had an exception about Java Mail, and once I added mail.jar to the lib folder it worked just fine.

Actually, the main problem that I missed to append [?wsdl] after the wsdl location which I copied as is ;P. Anyway, nice experience, I learned a lot within.

Thanks all
Majdoub

Anonymous | October 16, 2011 - 12:11

Make sure you chosen Axis2 and not Axis itself ..i got a lot trouble..just in that part whilke getting this error

Anonymous | September 20, 2010 - 14:19

 
I am working with another tutorial on testing webservices and I'm getting the error below in running the client. Just like to ask if you know how to fix such error? Thanks a lot.
 
org.apache.axis2.AxisFault: java.lang.NoSuchMethodError: org.apache.axis2.context.MessageContext.getLocalProperty(Ljava/lang/String;)Ljava/lang/Object;
      at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486)
      at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:343)
      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389)
      at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:211)
      at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
      at ws.example.webservice.stubs.TemperatureConverterStub.c2FConvertion(TemperatureConverterStub.java:440)
      at ws.example.TemperatureConverterServiceClient.main(TemperatureConverterServiceClient.java:16)

Anonymous | September 17, 2010 - 21:48

Thanks again for the great tutorial. It worked, and used Axis2, and showed me how to test and confirm what the heck is happening.

Anonymous | September 7, 2010 - 06:54

Really good tutorial.

Anonymous | August 17, 2010 - 14:45

Folks,

This was a great tutorial.  Actually worked for me.  I extended the service so
it actually does something.  You can change the status message and get it
to add numbers.
 <code>
package myPkg;

public class MyService {
   
    static String status;
    static int one, two;
   
    public MyService() {
    }
   
    public Boolean Configure(String param){
       
        status = param;       
        return true;
    }
   
    public Boolean StartMe(){
    return true;
    }
   
    public Boolean StopMe(){
    return true;
    }
   
    public Boolean SetNums(int x, int y) {
       
        one = x;
        two = y;
        return true;
    }
   
    public int AddNums() {
       
        return(one+two);
       
    }
   
    public String getStatus(){
        return status;
    }
   
}
</code>

Anonymous | August 11, 2010 - 14:35

To potentially save someone else some time, if you're thinking about grabbing Tomcat 7, don't. I spent a few hours trying to get that to work with various Axis versions, with no luck. Once I switched to 6.0.29 I had no issues. It even works with Axis2 1.5.1 (using Eclipse Helios).

Anonymous | July 26, 2010 - 23:27

Hi,
a good tutorial but I have always had problem with using Axis2 in Eclipse. I have tried with different versions of Axis2 (1.4, 1.4.1, 1.5) and Eclipse (3.3, 3.4, 3.5, 3.6), even on different computers, but until now I still could not solve the problem. I have done exactly the same as described in the steps above (extract Axis2 binary, load the runtime in Preferences). Besides, I have also tried to include the Axis2_Codegen_Wizard_1.3.0 & Axis2_Service_Archiver_1.3.0 plugins as well as deployed axis2.war on JBoss, but all ended up in vain.
When I create a bottom-up Web service via the Web service wizard, no wsdl is generated. Besides, I always get the error message when I run the AxisServlet:
"The service cannot be found for the endpoint reference (EPR) /xxx/servlet/AxisServlet
org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) /xxx/servlet/AxisServlet
"
 
Really hope someone could help me on this issue.
Thanks in advance.
Regards,
Louis
 
 

Anonymous | June 10, 2010 - 20:31

When I test MyService with the Web Service Explorer,  I get null for all the methods that I invoke.

Anonymous | June 10, 2010 - 20:31

When I test MyService with the Web Service Explorer,  I get null for all the methods that I invoke.

Anonymous | June 4, 2010 - 21:57

You are simply best! Great tutorial!!

Anonymous | May 14, 2010 - 19:53

Thanks for this great  tutorial ...
 
 

Anonymous | May 8, 2010 - 14:03

The simplest and the best tutorial on axis2+Eclipse. Thanks a lot!

Anonymous | April 28, 2010 - 10:34

One rave review every month in 2010!
I find your tutorial here very helpful and concise.

Anonymous | March 3, 2010 - 13:31

Thanks a loat.......... for this documentation
 

Anonymous | February 6, 2010 - 09:03

I still use axis2 1.5.1
Also getting a 500 error, but i can solve by copying all files from My :
\Apache Software Foundation\Tomcat 6.0\webapps\axis2\WEB-INF\lib
into:
\ECLIPSE\workspace\eclipse_3_5\testWsvc1\WebContent\WEB-INF\lib
may be help others.
Sorry i am beginner too and facing this error to using axis2 1.5.1

Anonymous | January 20, 2010 - 17:25

The only issue I had was when it instructed me to "Run on Server". Nothing happened. But I got around it by pasting the URL on my browser page. Other than that it was a fun learning experience.
Thanks a bunch 

Anonymous | November 27, 2009 - 15:48

Fantastic article. Clearly written by someone who's spent time developing rather than a Microsoft engineer.
The industry need more articles like this.

Anonymous | November 22, 2009 - 13:01

Thank you very much for your tutorial it is very clear and direct.
The effort to update your tutorial is very much appreciated not only by me, but I believe for all your readers. But, sometimes, someone would like just to apply the solution he/she saw in your site months ago for a specific eclipse distribution, so, just as a suggestion, I'd like to ask you to keep the old versions of this tutorial and show them as links classified by eclipse distribution.
Best regards
Roberto

tranoris | November 22, 2009 - 14:32

Thank you and sure I'll have this in mind!

Anonymous | July 9, 2009 - 21:31

I followed this tutorial but when I try to access the listServices page I'm getting a 500 error.
java.lang.NoClassDefFoundError: org/apache/http/HttpResponseFactory org.apache.axis2.transport.http.SimpleHTTPServer.init(SimpleHTTPServer.java:116) org.apache.axis2.engine.ListenerManager.init(ListenerManager.java:74) org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:449) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:619)
Any ideas?

tranoris | July 10, 2009 - 10:05

Which version of axis2 are you using? The eclipse plugin uses  axis2-1.4.1.  If you downloaded axis2 1.5 the you have a problem.  Check also this page http://ws.apache.org/axis2/tools/index.html

Anonymous | September 15, 2009 - 18:09

Thanks for the tip...had the same problem. I was using Axis2-1.5. on Eclipse 3.4 and have spent hours troubleshoooting. Switching over to 1.4.1 solved my problems.

Anonymous | July 10, 2009 - 15:37

That was the issue thanks!  Its worth noteing that simply changing the Axis2 preferences after I've built the project did not fix the issue.  Once I had changed the preferences and recreated the project and it worked perfect.

Anonymous | August 11, 2010 - 12:23

Oh God....u r superb man......IT was really worth noting that point and great thought of sharing that piece of info.....
Thanks a looootttttttttttttttttttt.....may u be successful in all ur endeavours....

Anonymous | April 10, 2010 - 19:43

initially i was using axis 1.5.1 and was frustated with the above errors.today i came across this wonderful piece of suggestion that i migrated to axis 1.4.1. even after change my axis preferences i was not able to solve the problem.This is when i read ur post that i recreated my project..
Finally ,, finally to my suprise it worked.. thanks a lot man.. this is were i was struck in my project.. thanks a lot..
jayaram

Anonymous | June 23, 2010 - 16:15

Or you could just add httpcore-4.0 to the J2EE path for the project and get your project up on axis 1.5.1 :)

Anonymous | May 3, 2012 - 05:09

I am using axis2 1.5, adding httpcore-4.0.1.jar to classpath --> user entries of tomcat 5.5 resolved the issue.

Anonymous | June 29, 2010 - 04:53

I have tried, only use altered 1.4.1 can solve this issue.

Anonymous | July 10, 2009 - 09:30

I get the exact same error. I've been working on it for a while, but couldn't find a solution. Could somebody please help? I'd very much appreciate it...

Anonymous | December 20, 2009 - 06:09

I got the same errors as above. If you uninstall and go from scratch it does work (at least for me)
my configuration was
- apache-tomcat-6.0.20
- axis2-1.4.1-war.zip
- eclipse-jee-galileo-SR1-win32.zip
- jdk-6u17-windows-i586.exe
- wtp-S-3.2.0M4-20091210120653.zip
I suspect that my problem was not following the instructions :) in particular
"On the window that appears just click the Web Service Run Time and on the dialog select Apache Axis2"
How this helps others.