使用Camel Netty4发布请求响应-HTTP操作调用失败

时间:2019-06-26 11:34:42

标签: java apache-camel

我是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

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

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

所以删除

.to("http4://0.0.0.0:8080?bridgeEndpoint=true");
相关问题