Hello,

I'm using camel 1.6.3 and would like to configure a route at runtime from a
unit test something like looking the endpoint up in memory by name, and
replacing the file:// by a mock:// ? I know I can override the
createroutebuilder in the unit test but I don't want to do this and also I
can't upgrade at the moment.

The route I'm actually trying to manipulate looks like this:
               Namespaces ns = new Namespaces("cps",
"http://www.bbc.co.uk/schemas/CPS/CPS-API/";);
                                
                from("seda:footballMatchCreateCPSAsset")
                        .setHeader(FileComponent.HEADER_FILE_NAME,
                                        header(FOOTBALL_MATCH_ROOT_PATH_HEADER)
                                        .append("/create_cps_match_asset.xml"))
                        .process(XsltBuilder.xslt(
                                        new
File("xslt/football/match/xml/football_match_create_cps_asset.xml.xslt")))
                        .setBody(constant("payload=")
                        .append(body()))                        
                        .setHeader(HttpMethods.HTTP_METHOD, 
constant(HttpMethods.POST))                 
                        .setHeader("Content-Type", 
constant("application/x-www-form-urlencoded"))
                        .to(ConfigurationManager.getConfiguration().getString(
                                        
"output.cpsapiWebService.createAssetUrl"))
                        .to("seda:footballMatchSaveCPSAssetId");

I want to remove the last two to statements and add a to(mock:test)

I've been playing around with getting the route definitions from the context
but can't quite get it to work.

                List<RouteType> routeTypes =
testSupport.getContext().getRouteDefinitions();
                RouteType rt = routeTypes.get(31); //this is the route for
seda:footballMatchCreateCPSAsset
                
                List<ProcessorType<?>> outputs = rt.getOutputs();
                
                List<ProcessorType<?>> interceptorOutputs = 
outputs.get(0).getOutputs();
                interceptorOutputs.remove(5);
                interceptorOutputs.remove(5);
                //interceptor outputs actually look correct after the next line.
                outputs.get(0).addOutput(new ToType(new
MockEndpoint("mock:test"))); 

                //but rt is still showing the to:file in the pipeline so I did 
this, I'm
not sure what the difference between this and the above is but this adds
another interceptor to rt but doesn't appear to have any affect                 
                outputs.add(new ToType(new MockEndpoint("mock:test")));         
                
                rt.setOutputs(outputs);
                routeTypes.add(31, rt);

                MockEndpoint mock =
testSupport.getContext().getEndpoint("mock:test", MockEndpoint.class);
                mock.expectedMessageCount(1);        

                testSupport.sendBody("seda:footballMatchCreateCPSAsset",
FileUtils.readFileToString(
                new
File("testxml/football/matches/footballmatch_3003485.xml")));
                mock.assertIsSatisfied();

I think I'm going along the right lines although it looks like I need to get
at the recipient list for the route and modify that rather than the outputs?

Any help greatly appreciated.
Jon

-- 
View this message in context: 
http://camel.465427.n5.nabble.com/Configure-Route-Recipients-at-run-time-tp3246440p3246440.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to