Java 如何在SpringXML中向Camel http平衡器添加转换?
我通过Camel实现了http平衡器 (安装JBoss保险丝之前 ) 在fuse控制台中,我们编写Java 如何在SpringXML中向Camel http平衡器添加转换?,java,spring,http,apache-camel,load-balancing,Java,Spring,Http,Apache Camel,Load Balancing,我通过Camel实现了http平衡器 (安装JBoss保险丝之前 ) 在fuse控制台中,我们编写 JBossFuse:karaf@root> features:addurl mvn:com.fusesource.examples/ws-features/1.0-SNAPSHOT/xml/features JBossFuse:karaf@root> features:install smx-ws-examples JBossFuse:karaf@root> list | gr
JBossFuse:karaf@root> features:addurl mvn:com.fusesource.examples/ws-features/1.0-SNAPSHOT/xml/features
JBossFuse:karaf@root> features:install smx-ws-examples
JBossFuse:karaf@root> list | grep Examples
JBossFuse:karaf@root> log:Display
开始我们的测试服务
现在我们有3项服务:所以我们建立了平衡器
git clone https://github.com/mishin/http-balancer-camel.git
cd http-balancer-camel/camel-gateway
mvn -Djava.net.preferIPv4Stack=true camel:run
所以短代码是
java.io.IOException
我使用故障转移http平衡器因此,如果我从web浏览器调用
比我得到的还多
<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">
。。。
我需要转型
改变
到
我坚持到底
例如,简单的转换
<convertBodyTo type="java.lang.String" />
<transform>
<simple>${in.body.replaceAll("greet([A-Z])Response", "bar$1foo")}</simple>
</transform>
${in.body.replaceAll(“问候([A-Z])响应”,“bar$1foo”)}
完整代码为:
<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>
java.io.IOException
${in.body.replaceAll(“问候([A-Z])响应”,“bar$1foo”)}
但它根本不起作用当我调用
它不能代替
<wsdl:output name="pingMeResponse">
为什么?FailOverLoadBalancer使用异步路由引擎,这意味着您的转换块不会命中响应。尝试使用直接端点,并将转换代码放在单独的路由中(从直接->到jetty->转换)。这应该会有帮助
<wsdl:output name="pingMeResponse">
<wsdl:output name="pingAnotherResponse">
<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>
<wsdl:output name="pingMeResponse">