0
votes

I'm currently trying to to get the JSON-Response from the following URL using Apache Camel with its Jetty Component:

https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=2.11.0&request=GetFeature&typeName=dwd:RBSN_RR&outputFormat=application%2Fjson

At this point, I have the following snippet:

public void configure() {
    from("direct:dwd")
            .setHeader(Exchange.HTTP_PATH, simple("/geoserver/dwd/ows"))
            .setHeader(Exchange.HTTP_QUERY, simple("service=WFS&version=2.11.0&request=GetFeature&typeName=dwd:RBSN_RR&outputFormat=application%2Fjson"))
            .setHeader(Exchange.HTTP_PATH, simple("GET"))
            .to("jetty:https://maps.dwd.de")
            .log("${body}");
}

What should I do to get the JSON-Response?

1
I am interested. Why you want explicitly use jetty as producer? This is deprecated some time and can be removed in future camel versions. Why not HTTP component?Bedla
I tried it before with the HTTP component, but it did not work out for me either. I have the feeling that I am missing something fundamental, but none of the camel tutorials or answers here on stackoverflow helped me with this. To make it short, I'm fine with whatever works and wasn't aware that the Jetty component is deprecated. So, how do I make it work with the HTTP component?jerrypuchta
OK, this is simple typo. You have used header HTTP_PATH for specifying http method GET. Use Exchange.HTTP_METHOD, simple("GET") instead.Bedla
Wow, okay. Thanks for clearing that! Although I expect to get the JSON Response printed into the Log. At the moment it just gives me the following output: imgur.com/a/DrxeelPjerrypuchta
Direct endpoint must be triggered somehow, it is not pooling consumer. It depends on your requirements, but for testing purposes you can use timer to call route once after context started. Eg from("timer://testDwd?repeatCount=1").to("direct:dwd");Bedla

1 Answers

1
votes

This question was solved in comments.

In question there is incorrectly specified request method header. Request method should be specified with .setHeader(Exchange.HTTP_METHOD, simple("GET")). After this change the route works.

But using jetty component as producer is deprecated, as mentioned in Jetty component documentation. For producer, it is recomended to use HTTP component or HTTP4 component or Netty4 HTTP component.

Working route with HTTP component:

from("direct:dwd")
        .setHeader(Exchange.HTTP_PATH, simple("/geoserver/dwd/ows"))
        .setHeader(Exchange.HTTP_QUERY, simple("service=WFS&version=2.11.0&request=GetFeature&typeName=dwd:RBSN_RR&outputFormat=application%2Fjson"))
        .setHeader(Exchange.HTTP_METHOD, simple("GET"))
        .to("https://maps.dwd.de")
        .log("${body}");