Java Building a Simple Web Service ? A Tutorial Tutorial

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

Java Building a Simple Web Service ? A Tutorial Tutorial

Building a Simple Web Service ? A Tutorial

 ·   By Jeevaraj Gnanaselvan Dhanaraj ([email protected])

  (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 0

  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

 

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

  2

 

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

  3

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

  public String sayHello(String name){

  return "Hello " + name;

  }   4

 

 

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

5

 

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

  6

  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.

  7

 

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

  8

 

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

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

  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?.

  0

 

  1. The browser greets using the web service.

1

 

  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.

2

 

 

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

  3

 

·   Conclusion 4

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.

Tutorials

  1. Apache Axis2 - Apache Axis2 Tutorial
  2. Why Web Services?
  3. Java Building a Simple Web Service ? A Tutorial Tutorial
  4. Apache Geronimo Application server Tutorial
  5. Apache Axis2 Tutorial, Develop the Next Generation of Apache Web Services using Apache Axis2
  6. SOA and Web Services
  7. Web Services Examples in NetBeans
  8. SOA and Web Services
  9. J2EE Web Service Development with Attachments Using Axis
  10. J2EE Web Service Development with Attachments Using Axis
  11. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
  12. Web Services - Web Services Tutorials
  13. Developing Axis Web services with XML Schemas.
  14. What is Service-Oriented Architecture?
  15. WEBSERVICE USING APACHE AXIS -TUTORIAL-2 UNDERSTANDING APACHE AXIS
  16. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)
  17. WEBSERVICE USING APACHE AXIS TUTORIAL-1
  18. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
  19. WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-5)
  20. Web Services Tutorials and Links
  21. WEBSERVICE USING APACHE AXIS TUTORIAL-2
  22. WEBSERVICE USING APACHE AXIS- TUTORIAL-2 J2ME CLIENT FOR EJB & EJB-WEBSERVICE
  23. Web Service
  24. Java Client webservice
  25. Ejb Webservice
  26. SOAP with Attachments API for Java
  27. SOAP Header
  28. WSDL program
  29. Application Using JAX-RPC
  30. Security in Web Service
  31. JAX-RPC Advance Concepts
  32. Database driven webservices
  33. Apache Axis2 - Apache Axis2 Tutorial
  34. Apache Axis2 Introduction
  35. Downloading and Installing Apache Axis2
  36. Apache Axis2 Hello World Example
  37. Axis2 client - Axis2 Client example
  38. Axis2 ant wsdl2java - Learn WSDL2java utility of Axis2 with example
  39. Axis2 Eclipse plugin Tutorial
  40. Installing axis2 eclipse plugin