Sunday, 5 May 2013

How to consume JAX-WS published web-service using soapUI client?

Use of soapUI client for consuming the JAX-WS web-services

In the earlier post I mentioned how to create web-services using JAX-WS(Java API). Below is the link given:-

In the above link I also mentioned the process of creating client program but suppose that i don't want to create client program then in that case we can use soapUI tool as a client. Now I will tell how to use soapUI in order to test JAX-WS web-service.

Steps to test JAX-WS web-service with soapUI Client :-

  • Open soapUI, I am using 4.5.1 version of soapUI.

  • Go to File menu and select New soapUI project

  • Give the path of the wsdl file, where we published our services during the creation of web-service using JAX-WS. The example is shown below:-


  • Click on OK button.
  • Now the soapUI project structure will be displayed as below:-

  • Now double click on Request 1 inside getFactorial method in GenericMethodsImplPortBinding, it will display below screen:-

  • The Generated request for the getFactorial method is like below, pass any number in the arg0 parameter like 9. It will display the response as below:-

Test Number - 1
  • Soap Request for getFactorial method:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getFactorial>
         <!--Optional:-->
         <arg0>9</arg0>
      </ser:getFactorial>
   </soapenv:Body>
</soapenv:Envelope>

  • Soap Response for getFactorial method:-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getFactorialResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>Factorial of given number 9 is 362880</return>
      </ns2:getFactorialResponse>
   </S:Body>
</S:Envelope>

Test Number - 2
  • soap request for Negative scenario when sending string instead of number in the request argument:-
  • Pass any string for the arg0 parameter like “Gaurav”, now the request which I am sending to get the response is available below:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getFactorial>
         <!--Optional:-->
         <arg0>Gaurav</arg0>
      </ser:getFactorial>
   </soapenv:Body>
</soapenv:Envelope>

  • Response for the Negative scenario is available below:-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getFactorialResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>Not a Valid Number</return>
      </ns2:getFactorialResponse>
   </S:Body>
</S:Envelope>

  • Similarly we can do the testing for getOddAndEven method request and getPrimeNumber method request. I am proceeding with the both methods testing. Below are soap request available for the requests and their corresponding response :-
Test Number - 3
  • soap Request Test for Even number:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getOddAndEven>
         <!--Optional:-->
         <arg0>18</arg0>
      </ser:getOddAndEven>
   </soapenv:Body>
</soapenv:Envelope>

  • Response for Even number Request :-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getOddAndEvenResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>18 is even number</return>
      </ns2:getOddAndEvenResponse>
   </S:Body>
</S:Envelope>

                                                                       Test Number - 4
  • soap Request Test for Odd number:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getOddAndEven>
         <!--Optional:-->
         <arg0>23</arg0>
      </ser:getOddAndEven>
   </soapenv:Body>
</soapenv:Envelope>

  • Response for Odd number Request:-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getOddAndEvenResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>23 is odd number</return>
      </ns2:getOddAndEvenResponse>
   </S:Body>
</S:Envelope>



Test Number - 5
  •  soap Request Test for Negative scenario’s by passing string instead of number:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getOddAndEven>
         <!--Optional:-->
         <arg0>Kumar Gaurav</arg0>
      </ser:getOddAndEven>
   </soapenv:Body>
</soapenv:Envelope>

  • soap Response for Negative scenario’s when passed string instead of number as in above request:-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getOddAndEvenResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>Not a Valid Number</return>
      </ns2:getOddAndEvenResponse>
   </S:Body>
</S:Envelope>


Test Number - 6
  • soap Request Test for getPrimeNumber method(positive scenario’s):-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getPrimeNumber>
         <!--Optional:-->
         <arg0>53</arg0>
      </ser:getPrimeNumber>
   </soapenv:Body>
</soapenv:Envelope>
  • soap Response Test for getPrimeNumber method(positive scenario’s):-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getPrimeNumberResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>53 is Prime Number</return>
      </ns2:getPrimeNumberResponse>
   </S:Body>
</S:Envelope>
                         


Test Number - 7
  •  soap Request Test for getPrimeNumber method(Negative scenario’s):-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getPrimeNumber>
         <!--Optional:-->
         <arg0>99</arg0>
      </ser:getPrimeNumber>
   </soapenv:Body>
</soapenv:Envelope>
  • soap Response Test for getPrimeNumber method(Negative scenario’s):-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getPrimeNumberResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>99 is not Prime Number</return>
      </ns2:getPrimeNumberResponse>
   </S:Body>
</S:Envelope>



Test Number - 8
  •  soap Request Test for getPrimeNumber method(Negative scenario’s) by passing string instead of number:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.jaxws.gaurav.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getPrimeNumber>
         <!--Optional:-->
         <arg0>Gaurav Kumar</arg0>
      </ser:getPrimeNumber>
   </soapenv:Body>
</soapenv:Envelope>
  •  soap Response Test for getPrimeNumber method(Negative scenario’s) when passed string instead of number:-
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getPrimeNumberResponse xmlns:ns2="http://services.jaxws.gaurav.com/">
         <return>Not a Valid Number</return>
      </ns2:getPrimeNumberResponse>
   </S:Body>
</S:Envelope>


Finally, This is the way to create soapUI test client for testing or consuming the JAX-WS webservices. 

No comments:

Post a Comment