Sunday, July 24, 2016

WSO2 Data Mapper - Properties operator


Introduction


WSO2 Data Mapper supports using of ESB Properties(Synapse Properties) while data mapping.

Let's say we want to add a value of already defined ESB property into a resultant payload. In this use case we have two properties called "appID" and "time" defined previously and we want to use them while data mapping. See the below Proxy service which defines two properties before the Data mapper mediator



Proxy configuration

<proxy name="DataTransformerWithDataMapper" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property name="appID" scope="default" type="STRING" value="APP0001"/>
            <property expression="get-property(&quot;SYSTEM_DATE&quot;, &quot;yyyy.MM.dd G 'at' HH:mm:ss z&quot;)" name="time" scope="default" type="STRING"/>
            <datamapper config="gov:datamapper/propertyOperator.dmc" inputSchema="gov:datamapper/propertyOperator_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/propertyOperator_outputSchema.json" outputType="XML"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>


How to add Property operator and configure.


Go to Data Mapper editor by double clicking on DataMapper mediator. In the tool palette you can see there is a operator called "Properties" under "Common" category. 

This operator can be used to retrieve already defined properties and use them in Data Mapping. 

Drag and drop "Properties" operator into canvas. Right click on this operator and select "Configure Property Operator". Use opened dialog box to provide property scope(synapse(default), transport, axis2, axis2-client, operation), property name values.



You can compose your Data Mapping diagram as shown below to retrieve already defined properties and append them to output payload.  




Try it by yourselves


I have attached sample input.xml, output.xml and proxy service configuration. Load input and output files into input and output of data mapper diagram and do the mapping as shown above using "Property" operator. Deploy all the required artifact into an ESB and invoke the proxy service with input.xml as the payload.

Furthermore I have attached Maven Multi Module project which contains all the required projects, input.xml and output.xml in following location. You can try it by yourself.

https://drive.google.com/folderview?id=0BzCWN6PPAojbOHV1dGZNSVdCMzQ&usp=sharing

Download the archive. Unzip and use steps mentioned in following link to import PropertyOperatorSample project into workspace.

https://docs.wso2.com/display/DVS380/Quick+Start+Guide#QuickStartGuide-Importingexistingprojects


Saturday, December 14, 2013

Set up WSO2 ESB developement environment using WSO2 Developer Studio

      WSO2 developer studio helps you to develop, deploy and test WSO2 ESB artifacts such as Proxy service, Sequences, APIs. After setting up ESB development environment using WSO2 developer Studio properly, it is just few steps to deploy artifact to server and test it while you are developing ESB artifacts. 


Prerequisites


WSO2 Enterprise Service Bus   -  4.8.0
WSO2 Developer Studio            -  3.3.0 Alpha3 (http://builder1.us1.wso2.org/~developerstudio/developer-studio/3.3.0/Alpha3/installed-distributions/)


Setup Development Environment


1. Download and install both WSO2 ESB & WSO2 Developer Studio. I'll use 'ESB_HOME' to refer ESB installation directory throughout this article.

2. Go to Developer Studio dashboard and click on "Server" link.


3. Select "WSO2 Carbon 4.2 based server" in the wizard page(you can find this under WSO2 category). Give a server name. Click Next.




4. Give 'ESB_HOME' (ESB Installation directory location) for CARBON_HOME. In my case CARBON_HOME is "/media/Manganese/WSO2/Products/wso2esb-4.8.0". Click Next.




5. We can change ports for running ESB in next page. But we are not going to do that this time. So click Finish.

6. Server View will be pop up with the added ESB server. Click the 'Restore' icon in the Right corner of the Server view to set the Server View in a fixed position in Developer Studio workbench. You have added an ESB server to Developer Studio. Now You can do server operation such as Server Start, Shutdown, deploy artifacts etc. through Developer Studio.


7. Lets start the ESB. Right click on added server in the Server view, click on 'Start' in the context menu. ESB will be started. It will take few seconds to complete the startup process. You can monitor the server logs using 'Console' view in Developer Studio.


8. Now we have setup a WSO2 ESB and it is running. Let's start development. I'm going to implement a simple Proxy service which invoke a backend web service after logging the actual request. And this proxy service will send the backend response back to the client. First create an 'ESB Config project' (Ex : MyESBProject). Create a Custom Proxy service inside it (Ex : MyProxyService). You can use Developer Studio dashboard for this.




9. Drag and drop a Log mediator to the InSequence of the Proxy service(Top arrow at the left hand side indicates the beginning of the InSequence). Go to Properties view of the Log mediator and change the Log Level to "full". Then drop a Send mediator after the Log mediator. Drop a Address Endpoint into the Send mediator.  I'm going to keep this article simple. So I'm using the "echo" axis2 service deployed in ESB itself, as my backend. So give https://localhost:8243/services/echo as the "uri" of the Address endpoint.





10. Let's design the outSequence of the proxy service. Add a Send mediator to the outSequence (Bottom arrow at the right hand side indicates the beginning of the outSequence).



11. Save the diagram.

12. We have completed the implementation our configuration. All we need is to deploy this configuration to our ESB and test it. We need to create a "Composite Application Project" to deploy this proxy service to ESB. Goto Developer Studio dashboard and click on "Composite Application Project" link. Give a name for project(Ex : MyCapp) and select created proxy service as a Dependency. Then click finish. (Before creating "Composite Application Project", deselect ESBConfig project from the Project Explorer if it has been selected. Otherwise "Composite Application Project" project will be created inside the ESBConfig Project as a child project.)



13. When we create a Proxy Service, Developer Studio changes its perspective to "WSO2 ESB Graphical" from "Java EE" perspective. So Server View will not be there in the workbench now. So goto Window --> Show View --> Other and select Servers from the dialog box and click OK. Server view will be pop up with the created ESB server.

14.  We need to add the created "Composite Application Project" to the added ESB server in server view. There are two ways to do this.

(i) Drag and drop the created "Composite Application Project" (Ex : MyCapp) from the project explorer, on to the created ESB server of the Server view.

(ii) Right click on added ESB server (Ex : MyESB) in the sever view and select "Add and Remove..." from the context menu. Then add created "Composite Application Project" (Ex : MyCapp) and untick "If server started, publish changes immediately" checkbox. Click finish.



15. Lets deploy "MyCapp" to the server. Since we have included the proxy service inside this "MyCapp", this operation ultimately will deploy the proxy service to the ESB. So right click on "MyCapp" in server view and click on "Redeploy" from the context menu.


16. "MyCapp" will be deployed to the ESB and then deploys the proxy service.

17. We can test this proxy service using SoapUI plugin in Developer Studio. Goto Window --> Open Perspective --> Other. Select SoapUI perspective and click OK.

18. Now we are in the SoapUI perspective. Create a new SoapUI project by giving wsdl of the deployed proxy service. We can find it from WSO2 ESB management console. (In my case it is http://localhost:8280/services/MyProxyService?wsdl).

19. Then send the following request to the proxy service from SoapUI.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org">
   <soapenv:Header/>
   <soapenv:Body>
      <echo:echoString>
         <!--Optional:-->
         <in>foo</in>
      </echo:echoString>
   </soapenv:Body>
</soapenv:Envelope>


you will get the following response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:echoStringResponse xmlns:ns="http://echo.services.core.carbon.wso2.org">
         <return>foo</return>
      </ns:echoStringResponse>
   </soapenv:Body>
</soapenv:Envelope>


20. Change the perspective to "WSO2 ESB Graphical" and get the "Console view" You can see the request has been logged in the console as well. (this is because we have put a Log mediator in the inSequence of the proxy service)

[2013-12-15 06:50:49,452]  INFO - LogMediator To: /services/MyProxyService.MyProxyServiceHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:20a4f818-b31b-4600-914d-a703c2a9169a, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org"><soapenv:Body>
      <echo:echoString>
         <!--Optional:-->
         <in>foo</in>
      </echo:echoString>
   </soapenv:Body></soapenv:Envelope>

21. Now you know how to develop, deploy and test a proxy service using WSO2 Developer Studio. You can continue your development of the proxy service through WSO2 Developer Studio, when you want to test your proxy service while development, all we need is to save the diagram and redeploy the "MyCapp" using steps mentioned in step 15 and test it.

22. For example lets add another log mediator to the outSequence and set the "Log Level" to "full" to log the response.


23. Save the diagram. Right click on "MyCapp" in server view and click on "Redeploy" from the context menu. It will take few seconds to deploy the proxy service.

24. Invoke the proxy service using SoapUI using the same request. You can see the response massage has been logged in the Console.

2013-12-15 06:50:49,469]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0c70044b-e510-409f-9a2e-e5f628da9f2e, Direction: response, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:echoStringResponse xmlns:ns="http://echo.services.core.carbon.wso2.org"><return>foo</return></ns:echoStringResponse></soapenv:Body></soapenv:Envelope>



Tuesday, October 22, 2013

How to use WSO2 Developer Studio - Cloud Connector feature.

This simple guide will help you to use WSO2 Developer Studio to create WSO2 ESB configurations for cloud connectors.



1. Create new ESBConfig project (MyConnectorProject).

2. Right click on 'MyConnectorProject' ESB project. Click on 'Import Cloud Connector' from the context menu.




3. Browse a cloud connector zip (salesforce-connector.zip) and click Finish. (You can download latest cloud connectors from https://svn.wso2.org/repos/wso2/people/isuruu/480release/connectors/)



4. Create a sequence 'MySeq'. Drag and drop a operation from the tool palette.



5. Right click on added operation. Click 'Show Properties View' from context menu.

6. Create a new config for added operation using 'New Config' property of the properties view. Click the button(Right hand side) of 'New Config' property in properties view.




7. Set Config parameters using properties view. Click OK.



8. Set operation parameters using properties view.