現在のドキュメントのほとんどはSOAP-to-JSONを参照しています。私は、WSO2ESBを使用してJSON応答オブジェクトをSOAPサービスに変換する際の参考資料やチュートリアルがあるかどうかを期待していました。前もって感謝します。
サンプルサービス: http ://api.statsfc.com/premier-league/table.json?key = free
これは、次のような構成で実現できます。(「messageType」プロパティを「text/xml」に設定して、クライアントに応答するときに SOAP メッセージ ビルダーを使用する必要があります。)
<proxy xmlns="http://ws.apache.org/ns/synapse" name="JSONToSOAPService" transports="https,http">
<target>
<outSequence>
<log level="full"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://api.statsfc.com/premier-league/table.json?key=free"/>
</endpoint>
</target>
<description></description>
</proxy>
しかし、JSON 応答オブジェクトが、提供したサンプル サービスから取得したものとまったく同じである場合 (つまり、匿名オブジェクトの配列である場合)、ESB は応答を切り捨てて、最初の要素 (次の SOAP 応答を参照)。
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<position>1</position>
<team_id>10260</team_id>
<team>Manchester United</team>
<played>21</played>
<won>17</won>
<drawn>1</drawn>
<lost>3</lost>
<for>54</for>
<against>28</against>
<difference>26</difference>
<points>52</points>
<info>championsleague</info>
</soapenv:Body>
</soapenv:Envelope>
ESB 4.5.0 では、次の手順で完全な JSON ペイロードを変換できました。これらの手順には、application/json コンテンツ タイプのメッセージ ビルダーとメッセージ フォーマッターの変更が含まれます。
JSON のメッセージ ビルダー、フォーマッターを変更します。CARBON_HOME/repository/conf/axis2/axis2.xml ファイルで、次の行をコメントアウトして、デフォルトのメッセージ ビルダーとメッセージ フォーマッターを解除します。
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONBuilder"/>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
次の行のコメントを外して、JSONStreamBuilder と JSONStreamFormatter を使用します。
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONStreamFormatter"/>
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONStreamBuilder"/>
新しい XML ペイロードを変換および構築する Javascript 関数を記述します。
function transformRequest(mc) {
var array = mc.getPayloadJSON();
var payload = <games/>;
for (i = 0; i < array.length; ++i) {
var elem = array[i];
payload.game += <game>
<position>{elem.position}</position>
<team_id>{elem.team_id}</team_id>
<team>{elem.team}</team>
<played>{elem.played}</played>
<won>{elem.won}</won>
<drawn>{elem.drawn}</drawn>
<lost>{elem.lost}</lost>
<for>{elem["for"]}</for>
<against>{elem.against}</against>
<difference>{elem.difference}</difference>
<points>{elem.points}</points>
<info>{elem.info}</info>
</game>
}
mc.setPayloadXML(payload);
}
outSequence を変更して、受信 JSON ペイロードで変換を実行します。
<outSequence>
<script language="js" key="conf:/repository/esb/scripts/transformrequest.js" function="transformRequest"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
私の知る限り、json コンテンツを使用して SOAP サービスを呼び出し、json 応答を取得します。それが必要な場合は、このサンプルが役に立ちます。
SOAP クライアントが WSO2ESB を介して REST サービスにアクセスできるようにしたい場合は、それが可能です。このサンプルを見てみましょう: http://docs.wso2.org/wiki/display/ESB451/Sample+152%3A+Switching+Transports+and+Message+Format+from+SOAP+to+REST+POX
できることは、REST サービスの前に配置される SOAP プロキシ サービスを作成することです。次に、このプロキシ サービスは SOAP 要求を受け取り、その要求を REST 要求に変換して、REST サービスに転送します。その後、JSON の REST 応答を SOAP 応答に変換し、SOAP クライアントに返すことができます。