You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "George Wu(Geckos)" <ge...@bleum.com> on 2013/08/16 09:09:19 UTC

AdviceWithRouteBuider issue

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.


Re: AdviceWithRouteBuider issue

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Please use the @user mailing list / forum for these kind of questions,
as we say:
http://camel.apache.org/mailing-lists.html

And your problem is that the advice code is inside the configure
method, this is not allowed, you should put the advice code in the
unit test method, eg as documented.

On Fri, Aug 16, 2013 at 9:09 AM, George Wu(Geckos) <ge...@bleum.com> wrote:
> 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.
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen