Monday, February 20, 2017

How to enable specific Builder and Formatter in mediation flow in WSO2 ESB 4.9.0

This article explains a need where we need to enable Builder and Formatter in a mediation flow, which is only needed for a specific configuration in the Proxy Service and not for global. By default for global settings on builders and formatters, we do at axis2.xml, in this case we are going to override the global setting for a particular proxy service.

Below is the sample proxy service which handles a similar requirement.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="BuilderMediatorCheckProxy"
       transports="https http"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property name="STATUS"
                      value="-------------------BuilderMediatorCheckProxy IN Invoked-------------------"/>
         </log>
         <builder>           
            <messageBuilder contentType="application/json"
                            class="org.apache.synapse.commons.json.JsonStreamBuilder"
                            formatterClass="org.apache.synapse.commons.json.JsonStreamFormatter"/>           
         </builder>
         <log level="full"/>
         <send>
            <endpoint>
               <http uri-template="http://www.mocky.io/v2/58aa8e97100000060d4b626c"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="custom">
            <property name="STATUS"
                      value="-------------------BuilderMediatorCheckProxy OUT Invoked-------------------"/>
         </log>
         <log level="full"/>
         <send/>
      </outSequence>
   </target>
</proxy>


Note: If you are using a send / call mediator and in the outsequence or insequence you need to specify use same builder, then you need to again define it as below, as when the send/call is made the proxy level previous setting will be overridden by the axis2.xml global settings.


A sample proxy service for that kind of scenario as below:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="BuilderMediatorCheckProxy"
       transports="https http"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>
         <log level="custom">
            <property name="STATUS"
                      value="-------------------BuilderMediatorCheckProxy IN Invoked-------------------"/>
         </log>
         <builder>           
            <messageBuilder contentType="application/json"
                            class="org.apache.synapse.commons.json.JsonStreamBuilder"
                            formatterClass="org.apache.synapse.commons.json.JsonStreamFormatter"/>           
         </builder>
         <log level="full"/>
         <send>
            <endpoint>
               <http uri-template="http://www.mocky.io/v2/58aa8e97100000060d4b626c"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="custom">
            <property name="STATUS"
                      value="-------------------BuilderMediatorCheckProxy OUT Invoked-------------------"/>
         </log>
         <builder>           
            <messageBuilder contentType="application/json"
                            class="org.apache.synapse.commons.json.JsonStreamBuilder"
                            formatterClass="org.apache.synapse.commons.json.JsonStreamFormatter"/>           
         </builder>
         <log level="full"/>
         <send/>
      </outSequence>
   </target>
</proxy>


Before and After logs are below. You can observe that as our global axis2.xml pointing to org.wso2.carbon.relay.BinaryRelayBuilder, the outsequence of the first sample proxy service build the message as binary and the second proxy message build in the json format.

Log for Proxy - 1
[2017-02-20 14:11:29,531]  INFO - ProxyService Stopped the proxy service : BuilderMediatorCheckProxy
[2017-02-20 14:11:29,531]  INFO - DeploymentInterceptor Removing Axis2 Service: BuilderMediatorCheckProxy {super-tenant}
[2017-02-20 14:11:29,535]  INFO - ProxyService Building Axis service for Proxy service : BuilderMediatorCheckProxy
[2017-02-20 14:11:29,536]  INFO - ProxyService Adding service BuilderMediatorCheckProxy to the Axis2 configuration
[2017-02-20 14:11:29,537]  INFO - DeploymentInterceptor Deploying Axis2 service: BuilderMediatorCheckProxy {super-tenant}
[2017-02-20 14:11:29,537]  INFO - ProxyService Successfully created the Axis2 service for Proxy service : BuilderMediatorCheckProxy
[2017-02-20 14:11:29,537]  INFO - ProxyServiceDeployer ProxyService named 'BuilderMediatorCheckProxy' has been update from file : /home/ajanthan/wso2/blog/builders_check/wso2esb-4.9.0/repository/deployment/server/synapse-configs/default/proxy-services/BuilderMediatorCheckProxy.xml
[2017-02-20 14:11:34,590] DEBUG - wire >> "POST /services/BuilderMediatorCheckProxy HTTP/1.1[\r][\n]"
[2017-02-20 14:11:34,591] DEBUG - wire >> "Host: ajanthan-thinkpad-t440p:8280[\r][\n]"
[2017-02-20 14:11:34,591] DEBUG - wire >> "Connection: keep-alive[\r][\n]"
[2017-02-20 14:11:34,591] DEBUG - wire >> "Content-Length: 23[\r][\n]"
[2017-02-20 14:11:34,591] DEBUG - wire >> "Postman-Token: f0010840-1ba4-8989-12be-9e0cd29b09c4[\r][\n]"
[2017-02-20 14:11:34,591] DEBUG - wire >> "Cache-Control: no-cache[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "Content-Type: application/json[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "Accept: */*[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "Accept-Encoding: gzip, deflate[\r][\n]"
[2017-02-20 14:11:34,592] DEBUG - wire >> "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2017-02-20 14:11:34,593] DEBUG - wire >> "[\r][\n]"
[2017-02-20 14:11:34,593] DEBUG - wire >> "{"test":"from postman"}"
[2017-02-20 14:11:34,594]  INFO - LogMediator STATUS = -------------------BuilderMediatorCheckProxy IN Invoked-------------------
[2017-02-20 14:11:34,595]  INFO - LogMediator To: /services/BuilderMediatorCheckProxy, MessageID: urn:uuid:7029af4a-3845-4dae-b4d2-625ce55986bb, Direction: request, Payload: {"test":"from postman"}
[2017-02-20 14:11:34,911] DEBUG - wire << "POST /v2/58aaaac8100000b90e4b62ba HTTP/1.1[\r][\n]"
[2017-02-20 14:11:34,911] DEBUG - wire << "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2017-02-20 14:11:34,911] DEBUG - wire << "Accept-Encoding: gzip, deflate[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Postman-Token: f0010840-1ba4-8989-12be-9e0cd29b09c4[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Content-Type: application/json[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Accept: */*[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Cache-Control: no-cache[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Host: www.mocky.io:80[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2017-02-20 14:11:34,912] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2017-02-20 14:11:34,913] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:11:34,913] DEBUG - wire << "17[\r][\n]"
[2017-02-20 14:11:34,913] DEBUG - wire << "{"test":"from postman"}[\r][\n]"
[2017-02-20 14:11:34,913] DEBUG - wire << "0[\r][\n]"
[2017-02-20 14:11:34,913] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:11:35,165] DEBUG - wire >> "HTTP/1.1 500 Internal Server Error[\r][\n]"
[2017-02-20 14:11:35,165] DEBUG - wire >> "Server: Cowboy[\r][\n]"
[2017-02-20 14:11:35,165] DEBUG - wire >> "Connection: close[\r][\n]"
[2017-02-20 14:11:35,165] DEBUG - wire >> "Content-Type: application/json; charset=utf-8[\r][\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "Date: Mon, 20 Feb 2017 08:41:34 GMT[\r][\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "Via: 1.1 vegur[\r][\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "[\r][\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "{[\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "    "status": "INTERNAL PROBLEM",[\n]"
[2017-02-20 14:11:35,166] DEBUG - wire >> "    "errors": [{[\n]"
[2017-02-20 14:11:35,167] DEBUG - wire >> "[0x9][0x9]"error_code": "500123",[\n]"
[2017-02-20 14:11:35,167] DEBUG - wire >> "[0x9][0x9]"error_name": "Custom Error Message",[\n]"
[2017-02-20 14:11:35,167] DEBUG - wire >> "[0x9][0x9]"error_message": "Class not Specified"[\n]"
[2017-02-20 14:11:35,167] DEBUG - wire >> "[0x9]}][\n]"
[2017-02-20 14:11:35,167] DEBUG - wire >> "}"
[2017-02-20 14:11:35,169]  INFO - LogMediator STATUS = -------------------BuilderMediatorCheckProxy OUT Invoked-------------------
[2017-02-20 14:11:35,170]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:9e55fc0b-45f1-4443-bf57-e379780697d8, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">ewogICAgInN0YXR1cyI6ICJJTlRFUk5BTCBQUk9CTEVNIiwKICAgICJlcnJvcnMiOiBbewoJCSJlcnJvcl9jb2RlIjogIjUwMDEyMyIsCgkJImVycm9yX25hbWUiOiAiQ3VzdG9tIEVycm9yIE1lc3NhZ2UiLAoJCSJlcnJvcl9tZXNzYWdlIjogIkNsYXNzIG5vdCBTcGVjaWZpZWQiCgl9XQp9</ns:binary></soapenv:Body></soapenv:Envelope>
[2017-02-20 14:11:35,171] DEBUG - wire << "HTTP/1.1 500 Internal Server Error[\r][\n]"
[2017-02-20 14:11:35,172] DEBUG - wire << "Via: 1.1 vegur[\r][\n]"
[2017-02-20 14:11:35,172] DEBUG - wire << "Content-Type: application/json; charset=utf-8; charset=utf-8[\r][\n]"
[2017-02-20 14:11:35,172] DEBUG - wire << "Date: Mon, 20 Feb 2017 08:41:35 GMT[\r][\n]"
[2017-02-20 14:11:35,172] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "Connection: keep-alive[\r][\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "a5[\r][\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "{[\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "    "status": "INTERNAL PROBLEM",[\n]"
[2017-02-20 14:11:35,173] DEBUG - wire << "    "errors": [{[\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "[0x9][0x9]"error_code": "500123",[\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "[0x9][0x9]"error_name": "Custom Error Message",[\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "[0x9][0x9]"error_message": "Class not Specified"[\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "[0x9]}][\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "}[\r][\n]"
[2017-02-20 14:11:35,174] DEBUG - wire << "0[\r][\n]"
[2017-02-20 14:11:35,175] DEBUG - wire << "[\r][\n]"


Log for Proxy - 2
[2017-02-20 14:08:21,792] DEBUG - wire >> "POST /services/BuilderMediatorCheckProxy HTTP/1.1[\r][\n]"
[2017-02-20 14:08:21,792] DEBUG - wire >> "Host: ajanthan-thinkpad-t440p:8280[\r][\n]"
[2017-02-20 14:08:21,792] DEBUG - wire >> "Connection: keep-alive[\r][\n]"
[2017-02-20 14:08:21,792] DEBUG - wire >> "Content-Length: 23[\r][\n]"
[2017-02-20 14:08:21,792] DEBUG - wire >> "Postman-Token: 0c6f6ce0-73e9-236e-4c01-158a6679d8cf[\r][\n]"
[2017-02-20 14:08:21,792] DEBUG - wire >> "Cache-Control: no-cache[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "Content-Type: application/json[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "Accept: */*[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "Accept-Encoding: gzip, deflate[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "[\r][\n]"
[2017-02-20 14:08:21,793] DEBUG - wire >> "{"test":"from postman"}"
[2017-02-20 14:08:21,795]  INFO - LogMediator STATUS = -------------------BuilderMediatorCheckProxy IN Invoked-------------------
[2017-02-20 14:08:21,795]  INFO - LogMediator To: /services/BuilderMediatorCheckProxy, MessageID: urn:uuid:aa1eb6e8-a889-4ac8-a3a6-fd7bd20ab336, Direction: request, Payload: {"test":"from postman"}
[2017-02-20 14:08:22,133] DEBUG - wire << "POST /v2/58aaaac8100000b90e4b62ba HTTP/1.1[\r][\n]"
[2017-02-20 14:08:22,133] DEBUG - wire << "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2017-02-20 14:08:22,133] DEBUG - wire << "Accept-Encoding: gzip, deflate[\r][\n]"
[2017-02-20 14:08:22,133] DEBUG - wire << "Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Postman-Token: 0c6f6ce0-73e9-236e-4c01-158a6679d8cf[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Content-Type: application/json[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Accept: */*[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Cache-Control: no-cache[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Host: www.mocky.io:80[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:08:22,134] DEBUG - wire << "17[\r][\n]"
[2017-02-20 14:08:22,135] DEBUG - wire << "{"test":"from postman"}[\r][\n]"
[2017-02-20 14:08:22,135] DEBUG - wire << "0[\r][\n]"
[2017-02-20 14:08:22,135] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "HTTP/1.1 500 Internal Server Error[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "Server: Cowboy[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "Connection: close[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "Content-Type: application/json; charset=utf-8[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "Date: Mon, 20 Feb 2017 08:38:22 GMT[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "Via: 1.1 vegur[\r][\n]"
[2017-02-20 14:08:22,397] DEBUG - wire >> "[\r][\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "{[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "    "status": "INTERNAL PROBLEM",[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "    "errors": [{[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "[0x9][0x9]"error_code": "500123",[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "[0x9][0x9]"error_name": "Custom Error Message",[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "[0x9][0x9]"error_message": "Class not Specified"[\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "[0x9]}][\n]"
[2017-02-20 14:08:22,398] DEBUG - wire >> "}"
[2017-02-20 14:08:22,399]  INFO - LogMediator STATUS = -------------------BuilderMediatorCheckProxy OUT Invoked-------------------
[2017-02-20 14:08:22,400]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:7757cf75-1883-443e-8e6b-dbe86d8348b1, Direction: response, Payload: {
    "status": "INTERNAL PROBLEM",
    "errors": [{
  "error_code": "500123",
  "error_name": "Custom Error Message",
  "error_message": "Class not Specified"
 }]
}
[2017-02-20 14:08:22,401] DEBUG - wire << "HTTP/1.1 500 Internal Server Error[\r][\n]"
[2017-02-20 14:08:22,401] DEBUG - wire << "Via: 1.1 vegur[\r][\n]"
[2017-02-20 14:08:22,401] DEBUG - wire << "Content-Type: application/json; charset=utf-8; charset=utf-8[\r][\n]"
[2017-02-20 14:08:22,401] DEBUG - wire << "Date: Mon, 20 Feb 2017 08:38:22 GMT[\r][\n]"
[2017-02-20 14:08:22,401] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2017-02-20 14:08:22,402] DEBUG - wire << "Connection: keep-alive[\r][\n]"
[2017-02-20 14:08:22,402] DEBUG - wire << "[\r][\n]"
[2017-02-20 14:08:22,402] DEBUG - wire << "a5[\r][\n]"
[2017-02-20 14:08:22,402] DEBUG - wire << "{[\n]"
[2017-02-20 14:08:22,402] DEBUG - wire << "    "status": "INTERNAL PROBLEM",[\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "    "errors": [{[\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "[0x9][0x9]"error_code": "500123",[\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "[0x9][0x9]"error_name": "Custom Error Message",[\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "[0x9][0x9]"error_message": "Class not Specified"[\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "[0x9]}][\n]"
[2017-02-20 14:08:22,403] DEBUG - wire << "}[\r][\n]"
[2017-02-20 14:08:22,404] DEBUG - wire << "0[\r][\n]"
[2017-02-20 14:08:22,404] DEBUG - wire << "[\r][\n]"

Saturday, February 18, 2017

WebSocket Communication with WSO2 ESB 5.0.0

Why WebSocket Introduced?


The web has introduced with client-server communication option, which was built with the concept of client always request for data from the server, whenever it needs it. This have a performance issue that, whenever there is a need for data, the client page need to be refreshed or a new submit request need to be made.

To overcome this, there was a need for bi-directional communication, as a first step the AJAX came into picture. Through AJAX, JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object. This helps to retrieve the data without reloading the page or send a new page submission.

The problem encountered during the above is the HTTP headers and Cookies. Whenever we make an HTTP request a bunch of headers and cookie data are transferred to the server. This can add up to a reasonably large amount of data that needs to be transferred, which in turn increases latency.

This introduced the need for WebSocket. WebSockets provide a persistent connection between a client and server that both parties can use to start sending data at any time.



Configuring WSO2 ESB 5.0.0 to support WebSocket Communication


Below diagram illustrates, the basic flow of WebSocket communication through WSO2 ESB.


Setting up the WebSocket client and Server


Here, I have used the code got from
http://www.lookatsrc.com/source/io/netty/example/http/websocketx/client/WebSocketClient.java?a=io.netty:netty-all

You can find the project used in this sample at
https://drive.google.com/file/d/0B-VAIXmh-0yeTURNRE5yQmJTdjQ/view?usp=sharing

By running the WebSocketClient.java and WebSocketServer.java can start the client and the server for the communication.

Configuring the WSO2 ESB


Create the below sequences to use in this implementation.


Created Sequences as below:

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="InDispatchSeq">
   <property name="OUT_ONLY" value="true"/>
   <log level="custom">
<property name="STATUS" value="----------------InDispatchSeq Invoked------------------"/>
</log>
   <send>
         <endpoint>
             <address uri="ws://localhost:8080/websocket"/>
         </endpoint>
     </send>
</sequence>



<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="InDispatchFaultSequence">
   <log level="custom">
      <property name="STATUS"
                value="---------------------InDispatchFaultSequence Invoked---------------------"/>
   </log>
</sequence>


<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="OutDispatchSeq">
   <log level="custom">
      <property name="STATUS"
                value="-----------------OutDispatchSeq Invoked----------------"/>
   </log>
   <respond/>
</sequence>



<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="OutDispatchFaultSequence">
   <log level="custom">
      <property name="STATUS"
                value="---------------------OutDispatchFaultSequence Invoked---------------------"/>
   </log>
</sequence>


Create an Inbound Endpoint as below:

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
                 name="WebSocketInboundEndpoint"
                 sequence="InDispatchSeq"
                 onError="InDispatchFaultSequence"
                 protocol="ws"
                 suspend="false">
   <parameters>
      <parameter name="inbound.ws.port">9091</parameter>
      <parameter name="ws.client.side.broadcast.level">0</parameter>
      <parameter name="ws.outflow.dispatch.sequence">OutDispatchSeq</parameter>
      <parameter name="ws.outflow.dispatch.fault.sequence">OutDispatchFaultSequence</parameter>
   </parameters>
</inboundEndpoint>

Add the below to the axis2.xml:

<transportSender name="ws" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
       <parameter name="ws.outflow.dispatch.sequence" locked="false">OutDispatchSeq</parameter>
       <parameter name="ws.outflow.dispatch.fault.sequence" locked="false">OutDispatchFaultSequence</parameter>       
</transportSender>


Changes Need to be done in WebSocket Java Client and Server


Point the WebSocket Client URL to the Inbound Endpoint's URL.

Check whether you referring the correct port of WebSocket Server.



Now we are ready to test the implementation.

Up the WebSocketClient.java and WebSocketServer.java and in WebSocketClient.java, type some text and enter.

You can observe the below results.



[2017-02-18 18:28:11,995]  INFO - CarbonAuthenticationUtil 'admin@carbon.super [-1234]' logged in at [2017-02-18 18:28:11,975+0530]
[2017-02-18 18:46:00,008]  INFO - LogMediator STATUS = ----------------InDispatchSeq Invoked------------------
[2017-02-18 18:46:00,025]  INFO - LogMediator STATUS = -----------------OutDispatchSeq Invoked----------------
[2017-02-18 18:46:15,044]  INFO - LogMediator STATUS = ----------------InDispatchSeq Invoked------------------
[2017-02-18 18:46:15,048]  INFO - LogMediator STATUS = -----------------OutDispatchSeq Invoked----------------


Here you may observed that even if we specify a log level="full", we can't log the message. To check this modified the sequence as below:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="InDispatchSeq" xmlns="http://ws.apache.org/ns/synapse">
    <property name="OUT_ONLY" value="true"/>
    <log level="custom">
        <property name="STATUS" value="----------------InDispatchSeq Invoked------------------"/>
    </log>
    <log level="full"/>
    <send>
        <endpoint>
            <address uri="ws://localhost:8080/websocket"/>
        </endpoint>
    </send>
</sequence>

The log will appear as below:

[2017-02-18 18:52:27,406]  INFO - LogMediator STATUS = ----------------InDispatchSeq Invoked------------------
[2017-02-18 18:52:27,437]  INFO - LogMediator To: , MessageID: urn:uuid:66025a65-065a-49e3-b415-1c81f0f4d791, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
[2017-02-18 18:52:27,440]  INFO - LogMediator STATUS = -----------------OutDispatchSeq Invoked----------------


Will explain how to log the messages and do the modifications in my next blog.

References

[1] https://docs.wso2.com/display/ESB500/WebSocket+Transport
[2] https://docs.wso2.com/display/ESB500/Sending+a+Message+from+a+WebSocket+Client+to+a+WebSocket+Endpoint


Friday, February 17, 2017

Enabling the Hazelcast Debug logs in WSO2 ESB 4.9.0

To enable the Hazelcast debug logs follow the below:

Go to ESB_HOME/repository/conf/etc/logging-bridge.properties and enable the below:
com.hazelcast.level = DEBUG

Thursday, February 16, 2017

How to browse the default H2 database in WSO2 ESB 4.9.0

1) Go to ESB_HOME/repository/conf/carbon.xml and check for H2DatabaseConfiguration tag and add the below segment.

<H2DatabaseConfiguration>
        <property name="web"/>
        <property name="webPort">8082</property>
        <property name="webAllowOthers"/>        
</H2DatabaseConfiguration>

2) Go to http://localhost:8082/ and provide the below:

JDBC URL: jdbc:h2:/home/ajanthan/wso2esb-4.9.0/repository/database/WSO2CARBON_DB 
User Name: wso2carbon 
Password: wso2carbon