【问题标题】:Post request response using Camel Netty4 - HTTP operation failed invoking使用 Camel Netty4 发布请求响应 - HTTP 操作调用失败
【发布时间】:2019-06-27 13:56:48
【问题描述】:

我是 Camel 的新手,正在尝试使用 POST 请求从 Netty4 路由获取响应。我想发送一个 JSON 并返回一个从正文中提取的字符串。

我的休息设置如下:

public class Server extends RouteBuilder {

    @Override
    public void configure() {

        String listenAddress = "0.0.0.0";
        int listenPort = 8080;

        restConfiguration()
                .component("netty4-http")
                .scheme("http")
                .host(listenAddress)
                .dataFormatProperty("prettyPrint", "true")
                .bindingMode(RestBindingMode.auto)
                .port(listenPort);

        rest("/")
                .post()
                .consumes("application/json; charset=UTF-8")
                .to("direct:post");
    }
}

在我的骆驼路线中,我想使用以下方式发回消息:


@Component
public class RestRoute extends RouteBuilder {

    @Autowired
    CamelContext context;

    @Override
    public void configure() {

        from("direct:post")
                .log("New Request")
                .streamCaching()

                .setHeader(Exchange.HTTP_METHOD,constant(org.apache.camel.component.http4.HttpMethods.POST))
                .setBody().jsonpath("$.Text") // extract text from JSON
                .to("http4://0.0.0.0:8080?bridgeEndpoint=true");

但是我收到以下错误:org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://0.0.0.0:8080 with statusCode: 500

我将不胜感激!

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    哦,您不应该将消息发回,这会在路由结束时自动发生,然后将此时的消息用作其余部分的响应消息。

    所以删除

    .to("http4://0.0.0.0:8080?bridgeEndpoint=true");
    

    【讨论】:

    • 来自大师本人,这非常有效 - 感谢您的帮助 :)
    猜你喜欢
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多