【问题标题】:Camel rest-dsl request returns 404Camel rest-dsl 请求返回 404
【发布时间】:2016-02-29 13:04:43
【问题描述】:

下面是一个简单的camel rest-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

谁能帮我解决问题

【问题讨论】:

  • 您可以尝试将 URI 设置为预先在 Exchange.HTTP_URI 标头中调用,或者尝试将 &amp;bridgeEndpoint=true 设置为属性。正如documented Camel 将在调用实际 URI 之前删除任何组件属性。不确定这是否能解决您的问题
  • 不幸的是,问题仍然存在:(

标签: rest apache-camel


【解决方案1】:

您的代码不正确。

<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。

【讨论】:

    猜你喜欢
    • 2018-08-07
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多