Post request response using Camel Netty4 - HTTP operation failed invoking

Viewed 1233

I'm new to Camel and am trying to get a response from a Netty4 route using a POST request. I'd like to send a JSON and return a string extracted from the body.

My rest setup is as follows:

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");
    }
}

Within my Camel route I'd like to send the message back using:


@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");

However I get the following error: org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://0.0.0.0:8080 with statusCode: 500

I'd appreciate some help!

1 Answers

Oh you should not send the message back, this happens automatic when the routing ends, then the message at that point is used as the response message for the rest.

So remove

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