camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Wu(Geckos)" <george...@bleum.com>
Subject AdviceWithRouteBuider issue
Date Fri, 16 Aug 2013 07:09:19 GMT
Hi Camel team folks
I try to try to write code with tests AdviceWithRouteBuilder's explored API base on Camel
2.11 version, but got below error, please kindly help it, thanks  a lot.
I really refer to camel website listed guide line.
http://camel.apache.org/advicewith.html

You can of course combine those in the same advice with:
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
    @Override
    public void configure() throws Exception {
        weaveAddFirst().to("mock:input");
        weaveAddLast().to("mock:output");
    }
});



Source code:
public class TestAdviceRoute extends AdviceWithRouteBuilder {

	
	@Override
	public void configure() throws Exception {

		this.getContext().getRouteDefinitions().get(0).adviceWith(this.getContext(), new AdviceWithRouteBuilder()
{
		    @Override
		    public void configure() throws Exception {
		        weaveAddFirst().to("mock:input").process( new PrintProcessor());
		    }
		});

		
		from("direct:start")
		.routeId("George")
		.process(new PrintProcessor())
		.end()
		;
	}

	private final static class PrintProcessor extends SoSSProcessor{

		@Override
		public void sossProcess(Exchange exchange) throws Exception {
			System.out.println("exchange zdfasfas : "+ exchange);
			
		}
		
	}
	
	public static void main(String[] args) throws Exception{
		CamelContext context = new DefaultCamelContext();
		context.addRoutes(new TestAdviceRoute());
//		AdvicesRouteTest advicesRouteTest = new AdvicesRouteTest();
//		System.out.println(context.getRouteDefinitions().get(0));
//		advicesRouteTest.setOriginalRoute(context.getRouteDefinitions().get(0));
//		context.addRoutes(advicesRouteTest);
		context.start();
	   
		//System.out.println(context.getRouteDefinitions().get(0));
	  
		context.createProducerTemplate().sendBody("direct:start", "asdfasfdsaf");
	}

	
}

Got Exception:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
	at java.util.ArrayList.get(ArrayList.java:322)
	at com.getusroi.soss.route.impl.TestAdviceRoute.configure(TestAdviceRoute.java:20)
	at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
	at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)
	at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)
	at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:649)
	at com.getusroi.soss.route.impl.TestAdviceRoute.main(TestAdviceRoute.java:47)

Best Regards


 
Bleum Incorporated
 
George Wu                                                          
Email:George.Wu@bleum.com                                
  
Cloud-9 Mansion 7F
1118 West Yan'an Road.
Shanghai, P.R.C. 200052

This email may contain confidential information and/or copyright material. This email and
any attachments are solely for the intended recipient.
If you are not the intended recipient, disclosure, copying, use or distribution of the information
included in this message may be unlawful. please advise the sender immediately by using the
reply facility in your email software, and immediately and permanently delete. 
Thank you for your cooperation.


Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message