【发布时间】:2015-04-08 15:41:11
【问题描述】:
我正在尝试使用克隆和聚合使用天气肥皂和休息 api 在 Wso2 中进行概念验证(wso2 的新手,这是我使用 Wso2 的第三周)。 场景是客户端将发起soap请求,Wso2过滤和克隆请求并发送weather soap和rest API GetCityWeatherByZIP操作,来自两者的响应被聚合收集并发送soap响应给客户端。 我的问题是如何将rest response(jsonObject) 转换为soap 响应并作为子级添加到其他GetCityWeatherByZIP soap 响应并返回给客户端,当客户端收到响应时,soap 主体应该在GetCityWeatherByZIPResponse 中有2GetCityWeatherByZIPResult。
任何帮助将不胜感激。
这是我的代理配置
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CloneAggregateProxy" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
<log level="full">
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/" name="uri.var.zip" expression="/soapenv:Envelope/soapenv:Body/weat:GetCityWeatherByZIP/weat:ZIP"/>
</log>
<filter xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/" xpath="/soapenv:Envelope/soapenv:Body/weat:GetCityWeatherByZIP">
<then>
<property name="uri.var.zip" expression="/soapenv:Envelope/soapenv:Body/weat:GetCityWeatherByZIP/weat:ZIP" scope="default" type="STRING" description=""/>
<log level="full">
<property name="zipCode" expression="get-property('uri.var.zip')"/>
</log>
<clone id="edbIhub">
<target>
<endpoint>
<address uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx"/>
</endpoint>
</target>
<target>
<endpoint>
<http method="get" uri-template="http://api.openweathermap.org/data/2.5/weather?q={uri.var.zip}"/>
</endpoint>
</target>
</clone>
</then>
<else/>
</filter>
</inSequence>
<outSequence>
<property name="messageType" value="application/xml" scope="axis2" type="STRING" description="messageType"/>
<log level="full" description="">
<property name="WSANSWER" value="true"/>
</log>
<aggregate>
<completeCondition timeout="60">
<messageCount min="2" max="2"/>
</completeCondition>
<onComplete xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" expression="/s11:Envelope/s11:Body/child::*[position()=1] | /s12:Envelope/s12:Body/child::*[position()=1]">
<log level="full" description="json">
<property name="json" expression="$body/jsonObject"/>
</log>
<property name="messageType" value="application/xml" scope="axis2"/>
</onComplete>
</aggregate>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
xml 中的休息响应(带有 jsonObject )。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><coord><lon>-96.99</lon><lat>32.87</lat></coord><sys><message>0.0237</message><country>US</country><sunrise>1428408443</sunrise><s
352</sunset></sys><weather><id>800</id><main>Clear</main><description>Sky is Clear</description><icon>01d</icon></weather><base>stations</base><main><temp>301.125</temp><temp_min>301.125</temp_min>
<temp_max>301.125</temp_max><pressure>10e><sea_level>1027.22</sea_level><grnd_level>1003.5</grnd_level>
<humidity>69</humidity></main><wind><speed>8.07</speed><deg>200.504</deg></wind><clouds><all>0</all></clouds>
<dt>1428433031</dt><id>0</id><name>Irving</name><cod>200</cod></j
oapenv:Body></soapenv:Envelope>
SOAP 响应。
<?xml version="1.0"
-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.
/"><GetCityWeatherByZIPResult><Success>true</Success><ResponseText>City Found</ResponseText><State>TX</State><City>Irving</City><WeatherStationCity>Euless</WeatherStationCity>
<WeatherID>14</WeatherID><Description>Cloudy</Description><TemTemperature>
<RelativeHumidity>84</RelativeHumidity><Wind>NE7</Wind><Pressure>29.86S</Pressure><Visibility></Visibility>
<WindChill></WindChill><Remarks></Remarks></GetCityWeatherByZIPResult></GetCityWeatherByZIPResponse></soap:Body>
</soap>
【问题讨论】:
-
这里是完整配置
标签: wso2