我做出過駱駝 HTTP平衡器保險絲控制檯(安裝JBoss的保險絲befor http://www.jboss.org/products/fuse/download/如何在Spring xml中將轉換添加到Camel http-balancer中?
%fuse_dir%=c:\temp\jboss-fuse-6.2.1.redhat-084
%path%=%path%;%fuse_dir%\bin;
)
git clone https://github.com/mishin/http-balancer-camel.git
cd http-balancer-camel/smx-ws-examples-jboss-fuse-6.2.1
mvn clean install
fuse console
我們寫
JBossFuse:[email protected]> features:addurl mvn:com.fusesource.examples/ws-features/1.0-SNAPSHOT/xml/features
JBossFuse:[email protected]> features:install smx-ws-examples
JBossFuse:[email protected]> list | grep Examples
JBossFuse:[email protected]> log:Display
是開始我們的測試服務 現在我們有3個服務:
http://localhost:9091/greeterProxy?wsdl
http://localhost:9090/greeter?wsdl
http://localhost:9090/greeterImpl?wsdl
所以我們建立均衡
git clone https://github.com/mishin/http-balancer-camel.git
cd http-balancer-camel/camel-gateway
mvn -Djava.net.preferIPv4Stack=true camel:run
<camelContext trace="false" id="greeterGateway" xmlns="http://camel.apache.org/schema/spring">
<route id="proxyRoute">
<from uri="jetty:http://localhost:9092/greeterProxy?matchOnUriPrefix=true"/>
<loadBalance>
<failover>
<exception>java.io.IOException</exception>
</failover>
<to uri="jetty:http://localhost:9090/greeterImpl?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<to uri="jetty:http://localhost:9090/greeter?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<convertBodyTo type="java.lang.String"/>
</loadBalance>
</route>
</camelContext>
我做的故障轉移HTTP平衡器
所以如果我從網頁瀏覽器中調用
http://localhost:9092/greeterProxy?wsdl
比我
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.greeter.examples.fusesource.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns3="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://examples.fusesource.com/greeter" name="ConcreteGreeterService" targetNamespace="http://impl.greeter.examples.fusesource.com/">
<wsdl:import location="http://localhost:9090/greeterImpl?wsdl=Greeter.wsdl" namespace="http://examples.fusesource.com/greeter"></wsdl:import>
<wsdl:binding name="ConcreteGreeterServiceSoapBinding" type="ns1:Greeter">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="greetMe">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="greetMe">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="greetMeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="pingMe">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="pingMe">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="pingMeResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="PingMeFault">
<soap:fault name="PingMeFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="greetMeOneWay">
... 我需要做出轉變 變化
<wsdl:output name="pingMeResponse">
到
<wsdl:output name="pingAnotherResponse">
我TYR它通過 簡單的轉換,例如
<convertBodyTo type="java.lang.String" />
<transform>
<simple>${in.body.replaceAll("greet([A-Z])Response", "bar$1foo")}</simple>
</transform>
完整的代碼:
<camelContext trace="false" id="greeterGateway" xmlns="http://camel.apache.org/schema/spring">
<route id="proxyRoute">
<from uri="jetty:http://localhost:9092/greeterProxy?matchOnUriPrefix=true" />
<loadBalance>
<failover>
<exception>java.io.IOException</exception>
</failover>
<to uri="jetty:http://localhost:9090/greeterImpl?bridgeEndpoint=true&throwExceptionOnFailure=false" />
<to uri="jetty:http://localhost:9090/greeter?bridgeEndpoint=true&throwExceptionOnFailure=false" />
<convertBodyTo type="java.lang.String" />
</loadBalance>
<convertBodyTo type="java.lang.String" />
<transform>
<simple>${in.body.replaceAll("greet([A-Z])Response", "bar$1foo")}</simple>
</transform>
</route>
</camelContext>
但它不會在所有
工作的時候調用http://localhost:9092/greeterProxy?wsdl
它不會取代
<wsdl:output name="pingMeResponse">
爲什麼?