Learn in Java
 


   

JAX-WS SOAP Webservice client using CXF

 
In our JAX-WS webservice using CXF tutorial, we have created a SOAP based webservice that contains a single method sayHi().

Remember, in our test case, HelloAngryWorldImplTest.java, by default, there was one method that tests the webservice as below:

1. HelloAngryWorldImplTest.java :

package com.learninjava;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
 * @author learninjava.com
 * @see www.learninjava.com
 */
public class HelloAngryWorldImplTest {

    @Test
    public void testSayHi() {
        HelloAngryWorldImpl helloAngryWorldImpl = new HelloAngryWorldImpl();
        String response = helloAngryWorldImpl.sayHi("Angry World");
        System.out.println("Response from web service is : " + response);
        assertEquals("HelloAngryWorldImpl not properly saying hi", "Hello Angry World", response);
    }
}

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

Output:
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
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.

To test the sayHi method of HelloAngryWorld, enter the following in Poster UI :

URL          :   http://localhost:<port-number>/jaxws-service/HelloAngryWorld?wsdl
Content Type :   application/xml
Payload(Text Box at bottom) :  <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <sayHi xmlns="http://learninjava.com/">
            <arg0 xmlns="">Angry World</arg0>
        </sayHi>
    </Body>
</Envelope>

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:<port-number>/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.
 
   

Related Articles

Restful WebService using CXF
Restful Client using CXF
SOAP WebService using CXF
Restful WebService using Jersey
Restful Client using Jersey
 
   

Recommended Articles

User and Daemon Threads
Thread States
Java 8 Stream
Java 8 Functional Interfaces
Java 8 Lambda Expressions
Top 10 Free Tutorials




LIKE/SHARE
 
 
 
Download Source:

Comments:


 

Top Picks

1. Top 5 websites offering free e-books

2. Top 10 websites for free Java Articles and Tutorials

3. Top 5 websites for Java Certifications

4. Top 5 Softwares for Java developers




   
   
   
 
 
© Copyright 2017. All rights reserved. All trademarks and logos belongs to their owners.         Website Counter