View Christos Tranoris's profile on LinkedIn


Visit The Model Driven Software Network

Who's online

There are currently 0 users and 18 guests online.

Recent comments

Syndicate

Syndicate content

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

The purpose of these series Tutorial (updated with eclipse Indigo) 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 Indigo version. 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-indigo-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 7.0.16 Server. I used Windows Service Installer (since during this tutorial is made on Windows Vista. ).
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 7.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 e.g. C:\Program Files\Apache Software Foundation\Tomcat 7.0 and finish.
·        In the Servers view 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. (Click Unblock on any firewall notices)
 
 Before continuing we will need Apache Axis( an implementation of the SOAP). Download it from here. (This tutorial uses axis2-1.6.0)
Save it for example on c:\axis2-1.6.0 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 -> Dynamic Web Project
  

 On the configuration click Modify..and check the Axis2 Web Services (check also Dynamic Web Module version 2.5), 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!)  If something goes wrong, just procced, finish the wizard and then go to the Servers and Right click to start the Tomcat server at localhost)
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/ (At the first time you run this wizard, you need to specify the Tomcat. You can check on Always use this server when running this project)
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 June 28, 2011 - 10:27.



Anonymous | August 12, 2014 - 13:27

I have worked with Eclipse while developing Android Apps in Indigo version, but have never dealt with the same platform for creating web services. It was exciting to know how Eclipse platform can be effectively used to create Web Services from this tutorial. http://bestcrmservice.com/

Anonymous | June 3, 2014 - 06:51

Would like to see such nice articles in future too..

Anonymous | November 1, 2013 - 19:38

i got this error The service cannot be found for the endpoint reference (EPR) http://localhost:8080/ResourceA/services/AdminService org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) http://localhost:8080/ResourceA/services/AdminService at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:78) at org.apache.axis2.engine.Phase.invoke(Phase.java:329) at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:168) at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.

Anonymous | June 14, 2012 - 17:49

After pasting the wsdl address to open the wsdl, I get the following error in the status window of the Web Services Explorer:

IWAB0379E Unable to open http://localhost:8080/ResourceA/services/MyService. IWAB0135E An unexpected error has occurred. WSDLException WSDLException: faultCode=OTHER_ERROR: http://localhost:8080/ResourceA/services/MyService

Anonymous | June 22, 2012 - 07:47

Hello i am getting the same error.. if you are able to solve it please respond.

Anonymous | July 13, 2012 - 15:27

I had this same error.  I started over completely and when creating the web service, you need to be sure to click on the link for "Web Service Runtime" on the first page of the wizard and change from default (for me) of "Apache Axis" to "Apache Axis2".

Anonymous | June 11, 2012 - 10:58

When I try to invoke getStatus(), I get the error "IWAB0135E An unexpected error has occurred. 403 Forbidden".
How do I resolve this ?

Anonymous | November 16, 2012 - 23:20

i was able to correct this error by closing and reopening eclipse, and then the web services explorer, and providing my login credentials to the prompt. note - this error should probably only be happening if you request on the soap endpoint.

Anonymous | May 20, 2012 - 23:05

Good article, good explanation, it was useful to me, because I'm starting in java development, testing another environment than .NET and comparing :D

Anonymous | April 11, 2012 - 14:35

As a beginner to Java..this tutorial has helped me a lot.
Thank you Christos
 

Anonymous | March 8, 2012 - 23:36

Nice tutorial.
I tried using some Jax-ws annotations to try and get the response to look a bit more intuitive. However, I cannot get them to work. I can build and deploy the service, but I cannot get the Axis2 page to load, and I cannot create a project in SOAP UI. SOAP UI is telling me the wsdl is invalid. I believe this may be a problem with the Axis2 Eclipse plugin. Can anyone help me out with this?

Anonymous | March 4, 2012 - 17:23

I am Using Websphere application server and following your instructions, but unable to deploy my web service.
Can you suggest me the way out of this..?
I am getting the following error at the Server end.
 

Could not load servlet class org.apache.axis2.transport.http.AxisAdminServlet
org.apache.geronimo.common.DeploymentException: Could not load servlet class org.apache.axis2.transport.http.AxisAdminServlet
    at org.apache.geronimo.tomcat.deployment.TomcatModuleBuilder.addGBeans(TomcatModuleBuilder.java:626)
    at org.apache.geronimo.j2ee.deployment.SwitchingModuleBuilder.addGBeans(SwitchingModuleBuilder.java:174)
    at org.apache.geronimo.j2ee.deployment.EARConfigBuilder.buildConfiguration(EARConfigBuilder.java:763)
    at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:255)
    at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:140)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.geronimo.gbean.runtime.ReflectionMethodInvoker.invoke(ReflectionMethodInvoker.java:34)
    at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:131)
    at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:883)
    at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:245)
    at org.apache.geronimo.kernel.KernelGBean.invoke(KernelGBean.java:344)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.geronimo.gbean.runtime.ReflectionMethodInvoker.invoke(ReflectionMethodInvoker.java:34)
    at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:131)
    at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:883)
    at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:245)
    at org.apache.geronimo.system.jmx.MBeanGBeanBridge.invoke(MBeanGBeanBridge.java:172)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
    at javax.management.remote.rmi.RMIConnectionImpl.access$200(Unknown Source)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor73.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.transport.http.AxisAdminServlet
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:467)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
    at org.apache.geronimo.tomcat.deployment.TomcatModuleBuilder.addGBeans(TomcatModuleBuilder.java:624)
    ... 43 more

Anonymous | March 1, 2012 - 06:50

Its really a brilliant tutorial to start with WS..
Thanks for such a post

Anonymous | February 13, 2012 - 15:37

Hi there.
Excellent post, was one of the first that I could follow that worked perfectly the first time.

Are you planning on making on for the client side though (hint hint)
It would round this series of excellently.

Cheers
Lachaln

Anonymous | February 12, 2012 - 12:23

With loads of tutorials available online with all the older versions, this seems to be a simple guide to get on with the newer versions.
Love it!

Anonymous | February 9, 2012 - 19:00

Hi,
Everything went perfectly till I had to run the service on Tomcat. After I did that, I was greeted by a screen saying 'Request Not Found'.
Any suggestions?
Thank you so much.
The tutorial was very helpful.

Anonymous | January 4, 2012 - 18:20

Hello,
Thanks for taking the time to do this, worked great. My question is this production ready? When I worked with Web Services in C we would create interface classes to expose the web service methods, is this what the above is doing? Are they not needed with axis2?
For instance, say i had to create a stand alone webservice that returned the total of 2 numbers. Would I be able to adda method like:
//Added to MyService class
public int Total(int first, int second){
return first + second;
}
and it would be the correct to code this. Or should it be more like:
public int Total(int first, int second){
return calcTotals(first, second); // calcTotals will be a new class
}

Thanks for taking the time to do this.
 

Anonymous | October 31, 2011 - 03:50

My service runs well, but in eclipse it keeps showing this Java Problems: "Return type for the method is missing" on line 4, which is:
public MyService() {
    }
 
Is it ok to have this messege although the service can run?

Anonymous | October 26, 2011 - 22:13

Thanks very much. This article was very helpful and easy to follow.

Anonymous | September 26, 2011 - 21:39

I've followed your tutorial and when I proceed to create the Webservice, I get the following error:

[INFO] The DaisyWebservice service, which is not valid, caused java.lang.NoClassDefFoundError: org/outerj/daisy/repository/Repository

- the JARs are present in my library
- they get imported (and get resolved)
- I even copied them in the lib folder of Tomcat 6.5

Should the JARs be present somewhere else? What am I missing?

Also, about the web service not being valid... would the fact that I haven't done the necessary exception handling be the cause of this?

Regards,

Dan

Anonymous | October 6, 2011 - 05:15

Which versions of your software are you using, that is Eclispe, Axis2 and Tomcat?

It IS important to use the right version.

Do you get more errors from the Javaservlet Console (Tomcat console)?

Anonymous | May 29, 2013 - 07:33

I am getting this exception when try to creating web service.

Anonymous | August 21, 2013 - 22:15

Make sure that the right version of java has been definied in JAVA_HOME and CLASSPATH.