ApacheCamel:如何基于旧url或标头重建url

ApacheCamel:如何基于旧url或标头重建url,url,apache-camel,Url,Apache Camel,我使用驼峰上的路由启动服务器,该服务器用作请求、重定向、数据库网关等的访问点。 我想将get请求重定向到另一个服务器中的另一个服务,并根据请求合成url。我已经做了一个处理器,它获取标题并输入新的url。但是新的url不会被执行 代码如下: CamelContext context = new DefaultCamelContext(); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://

我使用驼峰上的路由启动服务器,该服务器用作请求、重定向、数据库网关等的访问点。 我想将get请求重定向到另一个服务器中的另一个服务,并根据请求合成url。我已经做了一个处理器,它获取标题并输入新的url。但是新的url不会被执行

代码如下:

CamelContext context = new DefaultCamelContext();

ConnectionFactory connectionFactory =
    new ActiveMQConnectionFactory("vm://localhost?create=false");
context.addComponent("activemq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.start();

Processor Redir = new RedirectProcess();
from("jetty:http://localhost:8080/Middleware")   
    .choice()
    .when(header("redir")).process(Redir)
    .end()
和处理器

public class RedirectProcess implements Processor {
    String value = null;
    String Head;

    public void process(Exchange inExchange) throws Exception {
        Head = inExchange.getIn().getHeader("redir").toString();
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addRoutes(route());
        camelContext.start();
        ProducerTemplate template = camelContext.createProducerTemplate();
        template.sendBody("direct:start", "Hello Camel");
        System.out.println(Head);
    }

    public RouteBuilder route() {
        return new RouteBuilder() {
            public void configure() {
                // you can configure the route rule with Java DSL here
                System.out.println("Passed HERE!");
                from("direct:start")
                    .to("http://localhost:8081/FunctLayer/tool/start/tool/" + Head + "");
            }
        };
    }
}

它不是这样工作的。不要试图在运行时创建上下文或路由。使用收件人列表模式()

您的代码如下所示:

    CamelContext context = new DefaultCamelContext();

    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
                    context.addComponent("activemq",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

    context.start();
from("jetty:http://localhost:8080/Middleware")   
    .choice()
        .when(header("redir"))
            .recipientList(simple("http://localhost:8081/FunctLayer/tool/start/tool/${header.redir}"))
        .end()

谢谢你的帮助。我只需要启用bridgeEndpoint,它就能像一个符咒一样工作。谢谢:-)