Posts

Showing posts from 2013

Simplest iterative algorithm Post order traversal

publicclass POIterateSimple {
publicstaticvoid main(String[] args) {
    pfIterate(PFIterate.NODE);
}
privatestaticvoid pfIterate(Node root) {
    Node prev = null;
    Stack stack = new Stack<>();
    stack.push(root);
    while (!stack.isEmpty()) {
        root = stack.pop();
if (root.left == null && root.right == null) {
            System.out.print(root.data + " ");
            prev = root;
        } elseif (prev == root.left || prev == root.right) {
            System.out.print(root.data + " ");
            prev = root;
        } else {
            stack.push(root);
if (root.right != null)
                stack.push(root.right);
if (root.left != null)
                stack.push(root.left);
        }
    }
 }
}

How to inject multiple endpoint in SEI using Camel's @EndpointInject

By default you can inject annotation on single method of an interface like:

public interface MyListener {

  @EndpointInject(uri="activemq:foo.bar")

    String sayHello(String name);

}
what if you need multiple methods like this with @EndpointInjection happening over them for each endpoint e.g.:

public interface MyListener {

  @EndpointInject(uri="direct:foo")

    String sayHelloFoo(String name);

@EndpointInject(uri="direct:bar")

    String sayHelloBar(String name);

}
The simple solution i have working involved spring's FactoryBean implementation.

It need following steps:

<!-- Define route for which you need injection to happen -->

<bean id="r" class="MyListener" />

<!-- Define producer template having that route  -->  

<camelContext  xmlns="http://camel.apache.org/schema/spring">

        <template id="producerTemplate" />

        <routeBuilder ref="r"/>

    </ca…

Use recipientList for dynamic routes

I was writing the route in which "to" endpoint was need to be configured dynamically with the URL coming in the body.

I was trying to use simple expression language (e.g. ${in.header.test} where test is the property set in the in-message header) also with header method (e.g. header(test)). The routes for the same were:

from("direct:test").to("${in.header.test}");

&

 from("direct:test").to(header("test"));

after literally every thing i could have. I figured out recipientlist can do the trick e.g.

from("direct:test").recipientList("${in.header.test}");

&

 from("direct:test").recipientList(header("test"));

Hope this works for you too.

Spring: implements interface not working in @Controller

Guys,  I had a @Controller in which I was trying to implement an interface. But i was getting the following error message:

PageNotFound WARN  No mapping found for HTTP request with URI [/test/form] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'


where "/test" (at class level) and "/form" (at method level) where my @RequestMapping args.

 The issue is described at following link:

http://forum.springsource.org/showthread.php?92303-Spring-Servlet-MVC-RequestMapping-breaks-with-AOP-Advice




Now you may not find anything wrong with your spring.xml but should check all the xml used by used in the project in out case metrics was causing the problem. 

The aop config was overridden by metrics here:

https://github.com/ryantenney/metrics-spring#xml-config

 By default JDK proxy are created using interface and if controller implements an interface the RequestMapping annotation gets ignored as the targetClass is not being using.

http://static.springsource.org/sp…