1

我想通过调用 URL 来开始我的路线。我的开始路线还没有准备好,但工作得很好。我的问题是,当我使用调用 start-route 的 rest-route 时收到一条错误消息。

public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        restConfiguration().component("restlet")
                .host("localhost").port("8080");

        rest()
                .get()
                .route()
                .to("direct:start");

        from("direct:start")
                .setHeader(HTTP_METHOD, constant("GET"))
                .to("http4://{host}:{port}/api/v2/data/adapter?authUsername=username&authPassword=pw&authenticationPreemptive=true")
                .process(Utils.javascript("converter.js"))
                .enrich("direct:add", new MyAggregationStrategy())
                //Mapping der JSON zur XML-Konfiguration
                //.to("file:E:\\ApacheServiceMix\\apache-servicemix-7.0.1\\deploy")
                .to("file:C:\\Users\\dwiesemann\\Desktop\\myTestOrdner")
                .log("${body}");


        from("direct:add")
                .setHeader(HTTP_METHOD, constant("GET"))
                .to("http4://{host}:{port}/api/v2/data/application?authUsername=username&authPassword=pw&authenticationPreemptive=true")
                .process(Utils.javascript("converter.js"));

    }
}

我可以启动程序而不会出现任何错误。当我调用 URL ( http://localhost:8080/?restletMethods=GET ) 时发生错误。但是,仅当对 api 的请求(我从中检索 JSON)在启动路由中时才会出现错误。当我将这两行注释掉时,一切都按预期进行,并且我没有收到任何错误消息。否则会弹出以下错误信息:

Jul 23, 2019 3:31:38 PM org.restlet.engine.connector.NetServerHelper$1 rejectedExecution
WARNUNG: Unable to run the following server-side task: sun.net.httpserver.ServerImpl$Exchange@327acd17
4

1 回答 1

0

代码现在正在运行。我必须将“to”更改为“toD”并设置“bridgeEndpoint=true”(在 URL 中),以便 HttpProducer 忽略标头。

public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        restConfiguration().component("restlet")
                .host("localhost").port("8080");

        rest()
                .get()
                .route()
                .to("direct:start");

        from("direct:start")
                .toD("http4://{host}:{port}/api/v2/data/adapter?authUsername=username&authPassword=pw&authenticationPreemptive=true&bridgeEndpoint=true")
                .process(Utils.javascript("converter.js"))
                .enrich("direct:add", new MyAggregationStrategy())
                //Mapping der JSON zur XML-Konfiguration
                //.to("file:E:\\ApacheServiceMix\\apache-servicemix-7.0.1\\deploy")
                .setHeader(Exchange.FILE_NAME, constant("testDok.json"))
                .to("file:C:\\Users\\dwiesemann\\Desktop\\myTestOrdner")
                .log("${body}");


        from("direct:add")
                .toD("http4://{host}:{port}/api/v2/data/application?authUsername=username&authPassword=pw&authenticationPreemptive=true&bridgeEndpoint=true")
                .process(Utils.javascript("converter.js"));


    }
}
于 2019-07-24T08:00:22.850 回答