In Java, a method can return void or one value. So returning multiple values using JAX-WS requires more effort than just returning a single value.
With mondCloud, developers can create, deploy and test web services using a browser. Lets define a web service that takes 2 numbers as inputs and returns the sum and the product of these two numbers. You do not have to install any development studio on your desktop/laptop. To generate web services that return more than one output does not require any special configuration within mondCloud.
Step 1: Login to mond BPM using this link to mondCloud™ BPM. From the Left Hand size Accordion click Wizards and then choose Web Service.
Step 2: Enter the name of the web service as “addAndMultiply”, the namespace as “com.math.fs” and description as “Adds and returns 2 numbers” and click next.
Step 3: Enter “addAndMultiply” as the operation name and “Returns the sum and product of 2 numbers” as the description for this operation and click next.
Step 4: Now lets enter the input parameters for this service. The input parameters are two variables firstNumber and secondNumber, both of type double.
Click the “Add New Row” icon to create a new input parameter. In the Data Type dropdown choose “double” and enter the fieldName as “firstNumber” and “My first number’ as description, press tab out and then press the enter key to save the row. Click the “Add New Row” icon to create another input parameter. In the Data Type dropdown choose “double” and enter the fieldName as “secondNumber” and “My second number” as description, press tab out and the press the enter key to save the row. Click next.
Step 5 :Now let’s enter the output parameters for this service. Let’s name the output parameters sum and product, both of type double. As before click the “Add New Row” icon to create a new output parameter. In the Data Type dropdown choose “double” and enter the fieldName as “sum”, description as “Sum of the two numbers,” tab out and then press the enter key to save the row. In the Data Type dropdown choose “double” and enter the fieldName as “product”, description as “Product of the two numbers,” tab out and then press the enter key to save the row. Click next.
Step 6: Now we are ready to choose an implementation service for this operation. You can choose an existing service, or let mondCloud create the service based on the input and output you have defined so far. In the Project drop down, choose New Project and enter a unique project name. In this case we choose “WebService.” In the Map drop down choose “New Map” and enter “sumAndProduct” and click next.
Step 7: We are now ready to save and publish this service. Click “Save and Publish”. You will see a series of messages. mondCloud will now generate the java code, compile it, create a war file and publish it.
If everything goes well, you can now view the WSDL.
We created a new web service, created a new operation within it, added 2 input parameters, added 2 output parameters and entered the name of a new service (sometimes called ‘Map’ within mondCloud) and published this service. We now have to create the actual implementation that adds and multiplies 2 numbers.
Login to mondCloud ESB using this link mond ESB (http://test.mond-cloud.com:9090/mond03/). Click the Build Tab and from the Project dropdown, select the project name you entered before. In our example, the project name entered in Step 6 was WebService. Click the service name you entered in Step 6. (‘sumAndProduct’ was what I entered in Step 6).
Step 9: Click the Input Output Button to verify if the input parameters and output parameters we entered in the Web Service wizard are displayed here. You will see something like this:
Close the tab by clicking the ‘cross’ icon. You will go back to the mond service canvas.
Click the “Add at same level” icon and from the operators drop down, choose “Math” and then choose “Add.” In the Operand1 dropdown select “$firstNumber.” Any variable prefixed by a ‘$’ is a temporary variable. In the Operand2 dropdown select “$secondNumber” and in Set Field drop down choose “$sum.” Click the save button to save this row.
Now to calculate the product, from the the operators drop down choose “Math” and then choose “Multiply”. In the Operand1 drop down select “$firstNumber”. In the Operand2 drop down select “$secondNumber” and in Set Field drop down choose “$product.” Click the save button to save this row.
We have now implemented service. There is no need to compile the service. It is now ready to be tested from mondCloud or from any tool of your choice.
Step 10: Testing the Web Service
Go back to mond BPM and from the Designer menu, choose the link “Web Service.” A list of web services will be displayed. Select the ‘addAndMultiply’ by clicking the web service icon and then click the play icon on the tool bar. This will display the operations in this web service. Choose ‘addAndMultiply’ and click the Simulate button. Choose the Generate Sample button to generate an input sample XML structure. Change the generated sample and enter the 2 numbers. Click simulate.
You will see the response returned by the web service. We created a web service, implemented it, published it and tested it all using our browser.In the next example we will implement a complex input and output and see how mondCloud simplifies this as well.