title: WSO2 websocket + SockJS - Cross origin requests blocked
body: <p>Since WSO2 5.0 supports WebSockets, I have written a simple app following by tutorials:</p>
  
  <ul>
  <li><a href="https://docs.wso2.com/display/ESB500/WebSocket+Transport" rel="nofollow noreferrer">WebSocket Transport</a> </li>
  <li><a href="https://docs.wso2.com/display/ESB500/Sending+a+Message+from+a+WebSocket+Client+to+an+HTTP+Endpoint" rel="nofollow noreferrer">Sending a Message from a WebSocket Client to an HTTP Endpoint</a></li>
  </ul>
  
  <p>Here's my source view output from WSO2:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
      &lt;registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"&gt;
          &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
      &lt;/registry&gt;
      &lt;taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/&gt;
      &lt;sequence name="fault"&gt;
          &lt;!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE--&gt;
          &lt;log level="full"&gt;
              &lt;property name="MESSAGE" value="Executing default 'fault' sequence"/&gt;
              &lt;property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/&gt;
              &lt;property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/&gt;
          &lt;/log&gt;
          &lt;!-- Drops the messages by default if there is a fault --&gt;
          &lt;drop/&gt;
      &lt;/sequence&gt;
      &lt;sequence name="main"&gt;
          &lt;in&gt;
              &lt;!-- Log all messages passing through --&gt;
              &lt;log level="full"/&gt;
              &lt;!-- ensure that the default configuration only sends if it is one of samples --&gt;
              &lt;!-- Otherwise Synapse would be an open proxy by default (BAD!)               --&gt;
              &lt;filter regex="http://localhost:9000.*" source="get-property('To')"&gt;
                  &lt;!-- Send the messages where they have been sent (i.e. implicit "To" EPR) --&gt;
                  &lt;send/&gt;
              &lt;/filter&gt;
          &lt;/in&gt;
          &lt;out&gt;
              &lt;send/&gt;
          &lt;/out&gt;
          &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
      &lt;/sequence&gt;
      &lt;sequence name="outDispatchSeq"&gt;
          &lt;log level="full"/&gt;
          &lt;respond/&gt;
      &lt;/sequence&gt;
      &lt;sequence name="dispatchSeq"&gt;
          &lt;switch
              source="get-property('websocket.source.handshake.present')" xmlns:ns="http://org.apache.synapse/xsd"&gt;
              &lt;case regex="true"&gt;
                  &lt;drop/&gt;
              &lt;/case&gt;
              &lt;default&gt;
                  &lt;call/&gt;
                  &lt;respond/&gt;
              &lt;/default&gt;
          &lt;/switch&gt;
      &lt;/sequence&gt;
      &lt;!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do
      *not* want to keep the artifacts in several files --&gt;
      &lt;inboundEndpoint name="test" onError="fault" protocol="ws"
          sequence="dispatchSeq" suspend="false"&gt;
          &lt;parameters&gt;
              &lt;parameter name="inbound.ws.port"&gt;9091&lt;/parameter&gt;
              &lt;parameter name="ws.client.side.broadcast.level"&gt;0&lt;/parameter&gt;
              &lt;parameter name="ws.outflow.dispatch.sequence"&gt;outDispatchSeq&lt;/parameter&gt;
              &lt;parameter name="ws.outflow.dispatch.fault.sequence"&gt;fault&lt;/parameter&gt;
          &lt;/parameters&gt;
      &lt;/inboundEndpoint&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p>I was able to successfully test it with Nett client:</p>
  
  <pre><code>C:\work\servers\netty&gt;java -Durl=ws://localhost:9091/websocket -DsubProtocol="synapse(contentType='application/xml')" -cp netty-example-4.1.4.Final.jar;lib/*;. io.netty.example.http.websocketx.client.WebSocketClient
  WebSocket Client connected!
  </code></pre>
  
  <p>However if I try to test it from JavaScript code I am getting error like:</p>
  
  <p><a href="https://i.stack.imgur.com/Znzli.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Znzli.png" alt="enter image description here"></a></p>
  
  <p>Do you know what is wrong in my code?</p>