Home Webservices Java Building a Simple Web Service ? A Tutorial Tutorial
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java Building a Simple Web Service ? A Tutorial Tutorial

Advertisement
In this tutorial we will create a simple web service and a client web application using eclipse IDE along with Lomboz plug in. We will also deploy and test the web service on Tomcat 5.5.4 web application server. This application, while simple, provides a

Building a Simple Web Service ? A Tutorial

    By Jeevaraj Gnanaselvan Dhanaraj (jeevaraj_1970@yahoo.com)

  (Jeeva has over 7 years of experience in designing and developing enterprise class web applications using JAVA and J2EE technologies.

  He currently works for Itreya Technologies, Bangalore, leading a team of over 10 programmers and designers, developing a multi-user, distributed, web-based workflow application)

   Introduction

In this tutorial we will create a simple web service and a client web application using eclipse IDE along with Lomboz plug in. We will also deploy and test the web service on Tomcat 5.5.4 web application server. This application, while simple, provides a good introduction to Web service development and some of the Web development tools available.

    Environment

J2SDK 1.4.2
http://java.sun.com/

Eclipse 3.1

http://www.eclipse.org/

Tomcat 5.5.4

http://tomcat.apache.org/

Lomboz 3.1RC2
http://lomboz.objectweb.org/

   Installation

Install JDK (in D:\j2sdk1.4.2_04)

Install Tomcat (in E:\Tomcat5.5)

Install Eclipse (in E:\Eclipse3.1)

Install Lomboz (in E:\Eclipse3.1)

   Setting up

  1. Set up the installed JRE in eclipse (Windows -> Preferences -> Java -> Installed JREs)

 

 

  1. Set up the installed runtime for server in eclipse (Windows -> Preferences -> Server -> Installed Runtimes)

 

 

  1. Set up the Server view in eclipse (Windows -> Show View -> Other)

 

  1. Set up the Tomcat Server by right clicking and selecting New -> Server option from the Server view in eclipse

 

 

 

   Creating a Web service

  1. Create a new Dynamic Web Project in eclipse (File -> New -> Other)

 

  1. Enter name as ?WebServiceTutorial?, select project location as ?E:\Test? and select Apache Tomcat v5.5 as the Target server.

 

  1. Now create a new Java class from the Project Explorer (Dynamic Web Projects -> Java Source -> New -> Class)

 

 

  1. Enter name as ?Hello? and package as ?com.tutorial?.

 

  1. Add a simple method in the ?Hello? class as below.

  public String sayHello(String name){

  return "Hello " + name;

  }  

 

 

  1. Save and build the project.
  2. Create a new Web service in eclipse (File -> New -> Other)

 

  1. Select Generate a proxy.
  2. Select Test the Web service.
  3. Select Overwrite files without warning.

 

  1. Select or enter the Bean name as ?com.tutorial.Hello?. This is the java class that we just now created.

 

  1. Continue the wizard by clicking Next and finish.
  2. On Finish, the Tomcat server starts up and launches the Test client.
  3. Verify the generated contents. Look for Hello.class and the generated JSPs as below.

 

 

  1. Verify the Tomcat folder and ensure the newly created web applications ? WebServiceTutorial, WebServiceTutorialClient.

 

 

  1. We can also run the following url from the browser to access/test the Web service.

http://localhost:8080/WebServiceTutorialClient/sampleHelloProxy/TestClient.jsp

  1. If servlet error ?org.eclipse.jst.ws.util.JspUtils cannot be resolved or is not a type? is thrown on the browser, then copy the webserviceutils.jar file from the E:\Eclipse3.1\eclipse\plugins\org.eclipse.jst.ws.consumption_0.7.0 into the WEB-INF\lib folder of the WebServiceTutorialClient application and restart the Tomcat server.
  1. The browser displays the methods available in the web service.

 

  1. Click on the sayHello(..) method, enter your name (for e.g. ?Jeeva?) in the inputs section and click ?Invoke?.

 

 

  1. The browser greets using the web service.

 

  1. The WSDL for the Hello Web service can be found in E:\Test\WebServiceTutorial\WebContent\wsdl\Hello.wsdl. On double-click, the WSDL opens in a graphical editor.

 

 

  1. Right-click on the WSDL file and explore the options to test the web service / publish the WSDL file / generate client / etc.

 

 

   Conclusion

In this tutorial we learned how to create a simple web service and a client web application using eclipse IDE along with Lomboz plug in. We also deployed and tested the web service on Tomcat 5.5.4 web application server. This application, while simple, provides a good introduction to Web service development and some of the Web development tools available.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2006

Related Tutorials

Ask Questions?    Discuss: Java Building a Simple Web Service ? A Tutorial Tutorial   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
ankur chauhan
April 8, 2011
computer science

very nice tutes.......... thanks for guiding me. i m a beginner in java web service programming....
nguyen van phuong
April 17, 2011
rebuild webservice

could you please help me.When I add new method in web service and I want to deploy it. I don't know deploy. I use Eclipse and tomcat 5.5 Thank so much
manan d shah
June 2, 2011
Nice Tutorial Sir!!!

Good explanation.
hong lily ju
July 7, 2011
Simple Web Service with Java

This is the best tutorial for showing a simple Web Service with java that I have seen so far. It is so clear and intuitive.
subbareddy
September 28, 2011
regarding web service

when i installed eclipse with out myeclipse that one inside there is no option server and web for that what i have to do if u know please send to me step by step how to install tomcat with out my eclipse
subbareddy
September 28, 2011
regarding web service

there is no option to install tomcat without my eclipse for that any one help to me
Ayan Basu
November 17, 2011
Excellent WebServices Introduction

Tho I hav 8yrs of experiences, but I was totally new to WebServices. So I needed a doc which can teach me WS very quickly, without going into too much details.I ran this code, and now feeling confident to explore more. Thank u ROSEindia!
Jacob
January 17, 2013
Good Example for begineers

This is a very good example for someone who wants to start with the Web Services.
pmr
February 16, 2012
webservice client

you explained abt creating webservice and creation client and its steps missing !
vajrakumar
March 12, 2012
Got ERROR in step 12

I got below error on step 12 (Continue the wizard by clicking Next and finish.) IWAB0489E Error when deploying Web service to Axis runtime axis-admin failed with {http://schemas.xmlsoap.org/soap/envelope/}Server.userException java.net.ConnectException: Connection refused: connect can anybody please guide me to get rid of the same
Raj
April 26, 2012
message

Simple and easy expression
Bbible
March 22, 2012
GvnaZqiEmAiHUhi

I have been using launcher pro plus for over 1 year now and love it. I do hveeowr miss some functionality that I have seen in other launchers available on the market. My biggest concern is about the lack of customizability in the application drawer. Could you make it possible to change icons of each app, change the scrolling effect (3D drawer is nice but some more effects would awesome, such as sideways scrolling etc.) or group applications in tabs. Keep up the good work. Thank You
Nick
March 22, 2012
question

Hello...If we just want to to send an integer from the server to client and and the oposite what we have to vhange to this tutorial to do that??? thanks!
Nick
March 22, 2012
question

Hello...I want to send from the server to client an integer...What i have to change in this tutorial to do that ??? thanks
olfa
April 22, 2012
web service

hello :) I'd like to make a web service that allows to find the shortest path between bus stations with Dijkstra's algorithm, then the path will be displayed on a map. (I have a database that contains the coordinated stations) but I do not know "how to start": , I am really blocked for a week and i dont find any thing :( , i dont find a tutorials as this subject :( :( :( ( This web service will be used by my android application) realy i need help :( (i use eclipse) thank you in advance :)
olfa
April 29, 2012
web service

hello :) if any body have any idea that can help me I would be grateful: So i want to creat a web service that display the bus that has the shortest path. i have a dijkstra java class and i have a data base that contain the coordinate of bus station and the distance between them . the point of start and arrival will be choosen in my android app and thes coordinate will be send to my web service in a array list but i cant translate this into a code; my problem is in the web service side : in wich class i will do the connexion to my data base to find the shortest path between this tow point and what is the query that i need ... im soory but i need help thank you in advance
hussain
May 3, 2012
doubt

Hi Jeeva, I was following this basic web service flow which you are mentioned above. But i dint see any explanation jsp file which you mentioned in 14th point. can you please help me out to where i can find that part. Thanks Hussain
chakilela.srinath
July 2, 2012
webservice aplication

thank you. it is easy to understand.
umapathi
August 28, 2012
nice

nice
Naree
September 26, 2012
Good subject

Thank you for your subject. very helpfull
mina
October 15, 2012
Thanks for this

Hi I am a fifth grader and this really helps for my school project. Mina
DMCA.com