【问题标题】:How to pass value from rest service to camel route?如何将价值从休息服务传递到骆驼路线?
【发布时间】:2018-10-30 13:46:21
【问题描述】:

我已作为服务公开如下

restConfiguration().component("servlet").bindingMode(RestBindingMode.json);
    rest("/batchFile").consumes("application/json").post("/routeStart").type(BatchFileRouteConfig.class).to("startRouteProcessor");

根据休息服务的请求,我将在处理器中启动骆驼路线,如下所示

@Component("startRouteProcessor")
public class StartRouteProcessor implements Processor {


    public void process(Exchange exchange) throws Exception {
        BatchFileRouteConfig config = exchange.getIn().getBody(BatchFileRouteConfig.class);
        String routeId = config.getRouteId();
        String sourceLocation = config.getSourceLocation();
        exchange.getContext().startRoute(routeId);
    }
}

我需要将 sourceLocation 从上面的 bean 传递到下面的路由

@Component
public class FileReaderRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("file:sourceLocation")
       .log("File Reader Route route started");
    }

}

上面是示例代码..请求您帮助我将 sourcelocationStartRouteProcessor 传递到 FileReaderRoute

【问题讨论】:

标签: rest spring-boot apache-camel spring-camel


【解决方案1】:

这是不可能的,因为在您的示例中,FileReaderRoute 在调用 batchFile 端点时已经启动。

你可以用稍微不同的方式来做。

将您的FileReaderRoute 提取到direct。比如:

@Component
public class FileReaderRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("direct:fileReaderCommon")
       .log("File Reader Route route started");
    }
}

然后你可以在运行时创建新路由:

@Component("startRouteProcessor")
public class StartRouteProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        BatchFileRouteConfig config = exchange.getIn().getBody(BatchFileRouteConfig.class);

        exchange.getContext().addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("file:"+config.getSourceLocation())
                    .routeId(config.getRouteId())
                    .to("direct:fileReaderCommon");
            }
        });
    }
}

不要忘记对输入进行足够的清理,因为您允许用户根据用户输入创建文件使用者。在您的方法中,路径遍历攻击的风险很高。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-04
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    相关资源
    最近更新 更多