Apache Camel: How to rebuild the url based on the old one or the header -
i using route on camel starts server used access point request, re-directions, gateway database, etc. , want redirect request service in server , compose url based on request. have made processor gets header , puts in new url. new url not executed...
here code:
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()
and processor
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() { // can configure route rule java dsl here system.out.println("passed here!"); from("direct:start") .to("http://localhost:8081/functlayer/tool/start/tool/" + head + ""); } }; } }
it not work this. don't try create contexts nor routes in runtime. use recipient list pattern (http://camel.apache.org/recipient-list.html).
your code like:
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()
Comments
Post a Comment