2016-08-30 4 views
3

、私はチュートリアルで、以下のシンプルなアプリを書かれているブロックされましたWSO2から:WSO2用WebSocketは+ SockJSクロスオリジン・リクエストはWSO2 5.0は、WebSocketををサポートしているため

<?xml version="1.0" encoding="UTF-8"?> 
<definitions xmlns="http://ws.apache.org/ns/synapse"> 
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"> 
     <parameter name="cachableDuration">15000</parameter> 
    </registry> 
    <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/> 
    <sequence name="fault"> 
     <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE--> 
     <log level="full"> 
      <property name="MESSAGE" value="Executing default 'fault' sequence"/> 
      <property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/> 
      <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/> 
     </log> 
     <!-- Drops the messages by default if there is a fault --> 
     <drop/> 
    </sequence> 
    <sequence name="main"> 
     <in> 
      <!-- Log all messages passing through --> 
      <log level="full"/> 
      <!-- ensure that the default configuration only sends if it is one of samples --> 
      <!-- Otherwise Synapse would be an open proxy by default (BAD!)    --> 
      <filter regex="http://localhost:9000.*" source="get-property('To')"> 
       <!-- Send the messages where they have been sent (i.e. implicit "To" EPR) --> 
       <send/> 
      </filter> 
     </in> 
     <out> 
      <send/> 
     </out> 
     <description>The main sequence for the message mediation</description> 
    </sequence> 
    <sequence name="outDispatchSeq"> 
     <log level="full"/> 
     <respond/> 
    </sequence> 
    <sequence name="dispatchSeq"> 
     <switch 
      source="get-property('websocket.source.handshake.present')" xmlns:ns="http://org.apache.synapse/xsd"> 
      <case regex="true"> 
       <drop/> 
      </case> 
      <default> 
       <call/> 
       <respond/> 
      </default> 
     </switch> 
    </sequence> 
    <!-- 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 --> 
    <inboundEndpoint name="test" onError="fault" protocol="ws" 
     sequence="dispatchSeq" 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">fault</parameter> 
     </parameters> 
    </inboundEndpoint> 
</definitions> 

私はsuccにできましたessfully正味のクライアントでテスト:私はJavaScriptコードからそれをテストしようとした場合

C:\work\servers\netty>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! 

は、しかし、私のようなエラーを取得しています:

enter image description here

あなたは私のコードで間違っているものを知っていますか?

答えて

2

SockJSが内部XMLHttpRequestを使用してURLをロードしようとしているため、この問題は発生しますが、プロトコルは、前述のプロトコルの一つである場合を除きクロームはこの場合、それはws://)である(クロスオリジンのコンテンツにアクセスすることはできません。私は、同様のシナリオを試してみましたFirefoxで、それはこのクローム特定の制限はありませんので、それが正常に動作します。このシナリオでは

WSO2 ESBは、HTTPエンドポイントを呼び出すためのWebSocketインターフェイスを公開するので、次のように、あなたはネイティブHTML5のWebSocketの実装を使用することができます。

var url = 'ws://localhost:9091/websocket'; 
var ws = new WebSocket(url); 

ws.onopen = function() { 
    // todo 
} 

ws.onmessage = function(e) { 
    // todo 
} 
関連する問題