Camel rest-dsl请求返回404

时间:2016-02-29 13:04:43

标签: rest apache-camel

遵循一个简单的骆驼休息-dsl

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">


<camelContext xmlns="http://camel.apache.org/schema/spring">
    <restConfiguration bindingMode="auto" component="netty4-http" port="8080" host="localhost"/>
    <rest path="/mycontext">
        <get uri="/foo">
            <to uri="direct:fooService"/>
        </get>
    </rest>

    <route>
        <from uri="direct:fooService"/>
        <to uri="netty4-http:http://localhost:9773/services/foo"/>
    </route>

</camelContext>

当我调用curl localhost:8080/mycontext/foo时,它总是返回404,但有以下异常:

org.apache.camel.component.netty4.http.NettyHttpOperationFailedException: Netty HTTP operation failed invoking http://localhost:9773/services/foo with statusCode: 404
at org.apache.camel.component.netty4.http.NettyHttpHelper.populateNettyHttpOperationFailedException(NettyHttpHelper.java:160)
at org.apache.camel.component.netty4.http.NettyHttpProducer$NettyHttpProducerCallback.done(NettyHttpProducer.java:111)
at org.apache.camel.component.netty4.NettyProducer$NettyProducerCallback.done(NettyProducer.java:491)
at org.apache.camel.component.netty4.handlers.ClientChannelHandler.channelRead0(ClientChannelHandler.java:189)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

当我进行数据包捕获时,我发现请求行不正确

GET http://localhost:9773/services/foo HTTP/1.1

但是当我直接点击后端时,请求行是GET /services/foo HTTP/1.1

有人可以帮我解决问题吗

1 个答案:

答案 0 :(得分:0)

您的代码不正确。

<to uri="netty4-http:http://localhost:9773/services/foo"/>

文档中提到的netty组件处理TCP / UDP通信而不是HTTP。无论如何,URI也是错误的。

您可以为TCP编写:

 <from uri="netty4:tcp://localhost:5022?textline=true&amp;sync=true&amp;workerPool=#sharedPool&amp;usingExecutorService=false"/>
  <to uri="log:result"/>

请查看http://camel.apache.org/netty4.html对此的解释。如果您确实想要进行HTTP通信,请使用jetty或Restlet。