使用 Apache Camel + Jetty 组件获取请求

GET-Request with Apache Camel + Jetty Component

我目前正在尝试使用 Apache Camel 及其 Jetty 组件从以下 URL 获得 JSON-Response:

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

此时,我有以下片段:

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

我应该怎么做才能得到 JSON-Response?

此问题已在评论中解决。

问题是错误指定的请求方法 header。请求方法应指定为 .setHeader(Exchange.HTTP_METHOD, simple("GET"))。在此更改之后,路线有效。

但是不推荐使用 jetty 组件作为生产者,如 Jetty component documentation. For producer, it is recomended to use HTTP component or HTTP4 component or Netty4 HTTP component 中所述。

使用 HTTP 组件的工作路由:

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