Sunday, August 25, 2013

Maven jax-ws plugin usage

This post shows an example of jax-ws maven plug-in usage. This maven plug-in can be found in two repositories
  1. org.codehaus.mojo
  2. org.jvnet.jax-ws-commons
First repository contains old versions of this plug-in. ( available upto versions 1.12 ). Second one has the Latest version (2.3) and it can be found in http://jax-ws-commons.java.net/jaxws-maven-plugin/. To use latest version, replace groupID and version fields with following .


 <groupid>org.jvnet.jax-ws-commons</groupid>
 <artifactid>jaxws-maven-plugin</artifactid>
 <version>2.3</version>


Tuesday, August 20, 2013

Working with SOAP Headers in BPEL - WSO2 BPS / Apache ODE


Most of the web services use soap headers to pass various kinds of information and it is required to manipulate those headers within a BPEL process when we are creating a complex business logic. Sometimes we have to deal with soap headers which aren't declared in the WSDL abstract message. These kind of headers are called Dynamic headers and both Apache ODE and WSO2 BPS can handle these type of soap headers.

For more information about header handling in Apache ODE, follow this article.

This post will show you how to handle soap headers, covering following scenarios,

  1. Reading a soap header in request message.
  2. Create a new soap header in a variable and assign a value to it.
  3. Copying soap header from one variable to another.  

Sample BPEL Process

To demonstrate above scenarios let's consider this simple BPEL process. These are process's default request and response messages.


1. Reading SOAP Header in Request Message.

Let's read "echo" header from the input message and set its value into the process output message (to result element). To do this, add another copy into the Assign activity like this. Note that we are using "header" attribute to refer a soap header. (Resultant process's response is shown in response.xml)


2. Create a new soap Header in a variable and assign a value to it

Let's add new soap header called "echo2" in the output variable and assign request message text (input) value as new header value. First copy will create the echo2 header and second copy will do the value assigning. (Resultant response is shown in response.xml)

3. Copying soap header from one variable to another.  

Let's copy request message's echo header to output message. In the Assign activity define a copy as follow. (Resultant response is shown in response.xml)

Sunday, August 18, 2013

Mocking an Asynchronous Web Service using SoapUI.


This is an example scenario.

Echo service is an asynchronous web service and this is the service which we are going to mock using SoapUI. Clients send requests to the echoService using ws-Addressing. Echo service uses ws-addressing headers to identify client's callback information and sends back echo-Response to client's callback services.






Tools used:

Step 1 : Obtain or Create wsdls files of the services which you are going to mock and client callback service.


Here I am using EchoService.wsdl file as my service's wsdl and ClientCBService.wsdl as client's callback service wsdl.

Step 2 : create a new SoapUI project using service and client WSDLs.
  • Open SoapUI.
  • Then goto File -> new SoapUI project or use shortcut key Ctrl + N
  • Give the your service wsdl path in initial wsdl/wadl filed and give an appropriate project name. ( Let's say EchoService ) and Click OK

Now Let's add client's wsdl into the same project.
  • right click on your SoapUI project and select "Add wsdl"

  • In "Add WSDL" window select your client wsdl and Click OK

( Note: Create Sample Requests for both server and client's callback operations if they were not created by default )



 Step 3 : Generate Mock service for EchoService

  • Right click on EchoService and select Generate MockService
  •   In Next windows click OK to create mock service with default values.


  • Now we have created the mock service. In Mock service window, click configure icon ( the most right icon) to set host name and port.

  • Give host name as localhost and give port which you prefer.


Step 4: Create a TestCase to invoke Client's callback service with echoService response. 

  • Right click on the client wsdl project and select Generate TestSuite.
  •  In next windows Click Ok to reate test suite with default values.


  •  Now You have create the TestSuite. Open the test-step which was created by default. Set echoString and messageID parameters in the request message. ( you can set parameter using ${parameter_name} )

  •  We will extract and set values to the above parameters in next step.


Step 5 : Write a groovy script to handle asynchronous behavior of the service.

  •  Double click on echo Operation in Mock-Service
  •   In opened Window select Dispatch type as Script.

  •  Then enter following code as our dispatch logic. It extract values from incoming request and parse to the testcase using a map. Also it sets testcase's end point address to the value that came with ReplyTo header.

Note: I wrote above script by modifying an answer in stackoverflow.com


Step 6 : Testing out Asynchronous Service

Now we have finished mocking our asynchronous service. But we need to have a callback service to get the response back.

  • Let's create another soapUI project to mock the callback wsdl. Follow above steps to create a mock service for client callback. For your reference I have added only few screenshots of most important steps. Note that I am using port as 8087 and host as localhost.





  • Start client Callback service by clicking green arrow of the mock service.


  •  Start our asynchronous echo (mock) service.

  • Now we are ready send a request to our mock service. Open request in EchoServiceSOAP and add mockservice endpoint to it.



  •  Click WS-A tab and enable ws-addressing. Then set "Action", "To", "ReplyTo", and "MessageID" fields in the request message as follow.

  •  Now we are ready to invoke our service. Click submit button in request window to send the request to mock service.
  • It returns an empty response. But if you check your callback service, you can see that actual echo response was sent to it.
  • You can view incoming request messages in both mock-services windows. Open both echoService request and echoReult message and Compare them for echoed string and ws-a messageID. ( see bellow screenshot.)



Links to Files: