HomeDocumentation > Developing > Tutorials > Developing Web services > Developing a JAX-WS EJB Stateless Session Bean Web Service

This tutorial will take you through the steps required in developing, deploying and testing a EJB Stateless Session Bean Web Service in Apache Geronimo. After completing this tutorial you should be able to understand how to develop simple JAX-WS compliant EJB web services in Apache Geronimo using Eclipse development environment.

It is highly recommended that you go through the Developing a JAX-WS POJO Web Service tutorial before jumping into this. We will be using the same sample from the tutorial to develop a EJB Web Service.

Client Development
Client development is excluded from this tutorial because there is no difference in creating a client for EJB Stateless Session Bean Web Service and a POJO Web Service.

You can refer to Developing a JAX-WS POJO Web Service tutorial for further knowledge about how to develop a client for Web Services.

To run this tutorial, as a minimum you will be required to have installed the following prerequisite software.

  1. Sun JDK 6.0+ (J2SE 1.6)
  2. Eclipse IDE for Java EE Developers, which is platform specific
  3. Apache Geronimo Eclipse Plugin 2.1.x
  4. Apache Geronimo Server 2.1.x
    Geronimo version 2.1.x, Java 1.5 runtime, and Eclipse Ganymede are used is used in this tutorial but other versions can be used instead (e.g., Geronimo version 2.2, Java 1.6, Eclipse Europa)

Details on installing eclipse are provided in the Development environment section. This tutorial will take you through the following steps:

Setting Up Eclipse for Application Development

  1. Create a Stateless Session EJB Project

    • Select File --> New --> Project




    • In the popup window, select EJB --> EJB Project and then click Next




    • Type jaxws-converterejb as the Project Name and click Next..




    • The default option should work for Geronimo, so click Next




    • Here also default options will work, but the service and wsdl file will be located at the URL specified by the annotations




      Changing Service Location
      If you want to change the service location to any custom URL you want, make sure that the check box Generate Deployment Descriptor is selected.



    • Modify the Group Id to org.apache.geronimo.samples.jaxws and the artifact id to jaxws-converterejb.




    • Click Finish

This completes the configuration of Eclipse for application development.

Creating the Web Services Implementation code

To deploy the Converter EJB Service, we are going to create a remote interface and a stateless session bean that implements the interface. The steps required are as follows:

  1. Right-click on ejbModule and select New --> Package




  2. Name the package to org.apache.geronimo.samples.jaxws and click Finish




  3. Right-click on the new package and select New --> Interface




  4. Name the interface as Converter and use the org.apache.geronimo.samples.jaxws package, then click Finish




  5. Add the following code to the Converter class:
    Converter.java


  6. Right-click on the new package and select New --> Class




  7. Name the class as ConverterBean and use the org.apache.geronimo.samples.jaxws package, then click Finish




  8. Add the following code to the ConverterBean class:
    ConverterBean.java
A little observation
If you have already gone through the Developing a JAX-WS POJO Web Service tutorial, you might have observed that there's not much difference between an EJB Web Service and POJO Web Service except for the EJB specific annotations.

This completes the development of the Web Service Implementation code.

Setting Up the Deployment Descriptor and Deployment Plan

Geronimo default location
If you are comfortable with the location that Geronimo deploys the EJB Web Service, you can skip this section and go to the Deploy and Test Section below.
  1. Expand the META-INF directory present under ejbModule and add the following code to ejb-jar.xml
    ejb-jar.xml
    If ejb-jar.xml is not present, create a XML file and name it as ejb-jar.xml
    ejb-jar.xml


  2. Also add the following code to the openejb-jar.xml present at the same location.
    openejb-jar.xml

This completes the setting up of Deployment descriptor and Deployment Plan.

Deploy and Test the Web Service

Now, we will look into the steps involved in deploying and testing our web service without any clients.

Deploy

  1. Right-click on the Apache Geronimo Server Runtime present in the servers view and select Add or Remove Projects

  2. In the popup dialog, select the jaxws-converterejb project and click Add




  3. Make sure that jaxws-converterejb is in the configured projects list and then click Finish




  4. Wait for some time till the server status is changed to synchronized.
    Errors at Deploy time
    If you see any errors at deploy time like Unable to read WSDL file null, simply ignore them.



Testing

  1. Once the application is deployed on to the server, Launch a browser and go to the following url:

    http://localhost:8080/Converter/ConverterPortType

    Custom location
    If you have followed the steps to deploy the service onto custom location, go to the url http://localhost:8080/CUSTOM_URL



  2. Now you should see the screen telling that service is located at the following URL:



    Using Web Service Explorer in Eclipse
    You can also use Web Services Explorer present in Eclipse to rapidly test your web service without developing a client.
    To know how to use Web Services Explorer in Eclipse, one can refer to the Developing a JAX-WS POJO Web Service#Using Web Services Explorer in Eclipse