首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将转换添加到Spring中的Camel http-平衡器中?

如何将转换添加到Spring中的Camel http-平衡器中?
EN

Stack Overflow用户
提问于 2016-07-01 08:01:18
回答 1查看 117关注 0票数 3

我通过骆驼制作http平衡器(安装JBoss熔断器在http://www.jboss.org/products/fuse/download/之前)

代码语言:javascript
复制
%fuse_dir%=c:\temp\jboss-fuse-6.2.1.redhat-084
%path%=%path%;%fuse_dir%\bin;

)

代码语言:javascript
复制
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

在fuse控制台中我们编写

代码语言:javascript
复制
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项服务:

http://localhost:9091/greeterProxy?wsdl

http://localhost:9090/greeter?wsdl

http://localhost:9090/greeterImpl?wsdl

所以我们建造平衡器

代码语言:javascript
复制
git clone https://github.com/mishin/http-balancer-camel.git
cd http-balancer-camel/camel-gateway
mvn -Djava.net.preferIPv4Stack=true camel:run

所以短代码是

https://github.com/mishin/http-balancer-camel/blob/master/camel-gateway/src/main/resources/META-INF/spring/applicationContext.xml

代码语言:javascript
复制
    <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&amp;throwExceptionOnFailure=false"/>
      <to uri="jetty:http://localhost:9090/greeter?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
      <convertBodyTo type="java.lang.String"/>
    </loadBalance>
  </route>
</camelContext>

我制造故障转移http-平衡器

所以如果我从网页浏览器打电话来

http://localhost:9092/greeterProxy?wsdl

比我得到的

代码语言:javascript
复制
<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">

..。我需要改变一下

代码语言:javascript
复制
<wsdl:output name="pingMeResponse">

代码语言:javascript
复制
<wsdl:output name="pingAnotherResponse">

例如,我通过简单的转换输入它。

代码语言:javascript
复制
    <convertBodyTo type="java.lang.String" />
    <transform>
        <simple>${in.body.replaceAll("greet([A-Z])Response", "bar$1foo")}</simple>
    </transform>

完整的代码是:

代码语言:javascript
复制
<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&amp;throwExceptionOnFailure=false" />
            <to uri="jetty:http://localhost:9090/greeter?bridgeEndpoint=true&amp;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

它代替不了

代码语言:javascript
复制
<wsdl:output name="pingMeResponse">

为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-07 09:02:46

FailOverLoadBalancer使用异步路由引擎,这意味着转换块没有命中响应。尝试使用直接端点并将转换代码放在不同的路由中(从直接->到丢弃->转换)。那会有帮助的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38140139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档