03 - Let us say Hello in EJB: Page 3 of 6

Now your project explorer view should display 2 project as follows:

          

Creating the Web Service class

From the Project Explorer View, Select the HelloEJB project, right click with the mouse, select New->Session Bean (EJB3.x)

       

This will open the Create EJB 3.x Session Bean

       

 In the dialog type the java package as “com.test.hello”, in the class name field type “HelloWebService”, keep the rest as is, then click the “Finish” button, this will create the following EJB class:

          

No convert your class to be with the following code:

 

package com.test.hello;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@Stateless
@WebService(serviceName = "HelloService")
public class HelloWebService {

    @WebMethod
    public double fromUSDtoGBP(@WebParam(name = "amount") double amount) {
        return amount * 0.60;
    }
    @WebMethod
    public double fromGBPtoUSD(@WebParam(name = "amount") double amount) {
        return amount / 0.60;
    }
    @WebMethod
    public double fromUSDtoEURO(@WebParam(name = "amount") double amount) {
        return amount * 0.72;
    }
    @WebMethod
    public double fromEUROtoUSD(@WebParam(name = "amount") double amount) {
        return amount / 0.72;
    }
}

                  

Now lets test what we have done till now, for testing the created web service we will need to use SoapUI tool, download from http://sourceforge.net/projects/soapui/files/

Packaging and Deploying the EAR

From the Servers Views, select the JBOSS server and right click with the mouse, then select “Add and Remove”

         

This will open the Add Remove Dialog

       

Select HelloEJB3EAR from the Available list and double click or just click the Add button, click Finish button to deploy the EAR of the JBOSS AS, this will display the following lines in the Console View, which will contain a URL to access the web service     

Our Web Service URL: http://localhost:8080/HelloEJB/HelloService/HelloWebService and the WSLD file http://localhost:8080/HelloEJB/HelloService/HelloWebService?WSDL

You can use your browser to check the WSLD file, just type the URL in the address bar and you will see the WSDL XML file

Like us on Facebook