23 January 2015

Play framework 1.2.x excel export with I18n and custom filename


play-excel is very well written plugin of Play-framework for exporting excel from java objects.

I used this plugin for my requirement of generating the I18n supported xls with custom names. This blog will explain this in details so that I can use it later :).

Line# 4: will basically make the play-excel to take the render functionality in play. (you can also use xlsx instead of "xls")

Line# 5: Will set the exported filename to given name i.e. "downloadUsers.xls"

Line# 6&7: pick up the template from views//users_.xls.

2.  public static void users() {
3.          List users = User.findAll();
4.          request.format = "xls";
5.          renderArgs.put("__FILE_NAME__", "downloadUsers.xls");
6.          String template = "users-" + Lang.get() + ".xls";
7.          renderTemplate(template, users);
8.    }
That's it you are done. Happy coding :).

19 June 2014

Gear 2 and Gear 2 Neo working with Nexus 5

Gear 2 and Gear 2 Neo are working perfectly with Nexus 5. Please go to the following url:

http://forum.xda-developers.com/showthread.php?t=2677686

and download "Galaxy Gear Manager" app on your phone.

Launch gear manager app and select your gear device and you are good to go. For receiving additional notifications, goto Gear Manager and select Notification item and select from the list of apps you want to receive notification from.

30 July 2013

Simplest iterative algorithm Post order traversal

public class POIterateSimple {
public static void main(String[] args) {
    pfIterate(PFIterate.NODE);
}
private static void 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;
        } else if (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);
        }
    }
 }
}

24 July 2013

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"/>

    </camelContext>

 <!-- define FactoryBean for proxy instance --> 

<bean id="definedCamel" class="CamelFactoryBean">

        <constructor-arg index="0" value="MyListener" />

        <constructor-arg index="1" ref="producerTemplate" />

</bean>

The FactoryBean will create instance of custom InvocationHandler and return it which will invoke the endpoint on the ProducerTemplate instance.



27 February 2013

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.

20 February 2013

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/spring/docs/3.2.x/spring-framework-reference/html/aop.html#aop-proxying

 So, fix required i my case is:

proxy-target-class="true" ... />

Hope this helps.

20 September 2012

60 days at expedia India

I am about to complete 60 days in expedia and till now the ride has been fun.

I joined expedia hoping challenging work, participating in building a good team and workplace full of geniuses. To be frank everything is as close to reality as i thought.

The experience is amazing, people are awesome, the new office is great, parties are crazy, but the most important think is freedom to express yourself and asking questions. And people around you listen and have enough patience to make you feel comfortable ;) .

Work wise finishing user stories (part of on-boarding process), building a team by interviewing brightest mind in the industry and ideating about new ideas to make it a better workplace. And to emphasis working on one of the biggest ecommerce platform is not easy. Its a great earning opportunity and even bigger to contributing in one of the fastest growing industry.

I hope this answers whether you should join here or not.

Looking forward to see on board ;).