SOAP : Building a WebService

We will be using annotation for creating webservices and deploying on jboss server. Since JBoss comes with JAX-WS jars inbuilt, we will not be adding any jars. First lets setup the jboss env.

Download Jboss from here. I downloaded jboss-eap-6.2. Extract the zip file. Add the server to Eclipse and start. Now, in order to access the adminn console you first have to create a user. Follow these steps:

  • Invoke the add-user.sh or  add-user.bat script from commond promt or terminal. Options to setup a user will come.
  • Choose to add a management user. Enter username password and other required details.

You can check more details about setup here.

Lets create the webserice.

Create a dynamic web project. Create a class EmployeeDetails. For now I have hardcoded the return values.


package mynotes.soap.ws;

import java.util.ArrayList;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class EmployeeDetails {

 @WebMethod
 public List<String> getAllEmployees(){
 List<String> mylist=new ArrayList<String>();
 //some DB connection
 mylist.add("Emp1");
 mylist.add("Emp2");
 mylist.add("Emp3");
 return mylist;

 }

 @WebMethod
 public int getTotalEmpCount(){
 return Integer.MAX_VALUE;
 }

}

And Thats it!!!.. Its done. Deploy it on jboss server and open the admin console:

JBossAdminConsoleWS

Notice the WSDL url which you can share wiwth your webservice consumer who can then generate client accordingly.

To test any webservice we can follow the generate client approach as discussed in the previous post, but there is an quick alternate way. Open Run -> Launch Web Service Explorer

EclipseWSexplorer1

EclipseWSexplorer2

 

SoapUI is an open source web service testing application for service-oriented architectures (SOA). Its functionality covers web serviceinspection, invoking, development, simulation and mocking, functional testing, load and compliance testing.

Download SoapUI from here, and install.

In the SoapUI interface create a new soap project and give the WSDl url in the Intial WSDL box:

SoapUInewSoapProject

This will create all sample request. Since we do not have any input parameter so we can directly run the request. The respose will be displayed on the righ side.

SoapWebServiceTest1

Lets go back to the class we created the @WebMethod is actually optional, because once you annotate the class with @WebService every public method of the class is considered to be an operation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: