JAX-WS SOAP Client using CXF

JAX-WS SOAP Client using CXF

Aug 06, 2015 - Webservices


In our JAX-WS webservice using CXF tutorial, we have created a SOAP based webservice that contains single method sayHi().
Remember, in our test case, HelloAngryWorldImplTest.java, by default, there was one method that tests the webservice as below:

1. HelloAngryWorldTest.java :

The client code looks straightforward. Just create the implementation class object and directly call the required method.

Testing the webservice: 

There are number of ways you can test this SOAP webservice. Before running any of the below, make sure the tomcat server is started and the webservice is running using,
mvn clean package -DskipTests=true tomcat7:run or mvn clean package -DskipTests=true jetty:run

1. Using maven command :

mvn test

Running com.learninjava.HelloAngryWorldImplTest
Response from web service is : Hello Angry World
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.508 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

2. Using Poster plugin :

Poster is a plugin for firefox browser. This is a very useful and handy tool to test your SOAP webservices quickly.
i. To test the sayHi method of HelloAngryWorld, enter the following in Poster UI :
URL: http://localhost:/jaxws-service/HelloAngryWorld?wsdl
Content Type: application/xml
Payload(Text Box at bottom):
and click on POST button. The response is displayed in the Response window.

3. Using Wizdler plugin :

Wizdler is a plugin for Chrome browser. wizdler plugin can be used to generate the sample request instead of using the heavyweight SoapUI.
i. To test the sayHi method of HelloAngryWorld, enter the following URL in Chrome browsers address bar :
URL: http://localhost:/jaxws-service/HelloAngryWorld?wsdl
You will see a small icon to the right corner of the address bar. See highlighted area in the screenshot below.
Click on the icon to get a list of all the methods in the WSDL. Since we have only one method, click on it sayHi(). You will get a sample SOAP request as shown.
Edit the request and replace [string?] with "Angry World", without quotes and click Go button. The response from webservice will be displayed as shown below:
You can click on "Request" and "Response" buttons at the bottom of the screen to navigate between request and responses.
Like us on: