Logo

Who is talking?

Archive

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

about 2 years ago | Subodh Gupta: Subodh's Blog

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 :).

Gear 2 and Gear 2 Neo working with Nexus 5

over 2 years ago | Subodh Gupta: Subodh's Blog

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.

Simplest iterative algorithm Post order traversal

over 3 years ago | Subodh Gupta: Subodh's Blog

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);        }    } }}

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

over 3 years ago | Subodh Gupta: Subodh's Blog

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.

Use recipientList for dynamic routes

almost 4 years ago | Subodh Gupta: Subodh's Blog

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

about 4 years ago | Subodh Gupta: Subodh's Blog

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-AdviceNow 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.

60 days at expedia India

over 4 years ago | Subodh Gupta: Subodh's Blog

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 ;).

Java references in nutshell

over 4 years ago | Subodh Gupta: Subodh's Blog

Java developers struggle to use java references and i don't blame them. The topic seldom covered by text books and even code reviews rarely give emphasis on usage of references. Why the topic is important at all? and if everybody (atleast people i have come across) is coding without it why the hell you need it?Since you are reading this, either you are already aware of them or for the interview. Anyways, knowing references helps you manage memory better because you are able to define the behavior of the object when GC (garbage collector) is run.Type of references:1. Strong Reference: The normal reference in the java code is strong reference and the object referenced by strong reference is eligible for GC as soon as scope ends or reference started pointing to null in the code.E.g. Person p = new Person();                p = null; // will make object initialized above eligible for GC2. Weak Reference: As name suggest these reference are weaker than the strong references.  Their are couple of ways to use them one via WeakReference call which can wrap your object and you can access the object through WeakReference.get API. Get API will be returning null id the object is GCed. (You can also use WeakHashMap)Usage: These objects stay in the memory till the time they are referenced from any strong reference in the memory. In other words as soon as they loose accessibility from strong reference they become eligible for GC.3. Soft Reference: Soft reference is similar to weak reference however weaker than weak references. They put the additional check on there GC eligibility, which is if GC needs space.  So basically they sits in memory still the time memory is available. Use the SoftReference API for this type of references.Usage: These find good usage in building cache because if memory is available they don't discard the object and hence saves you the additional reload.4. Phantom Reference: This type of reference is used to track the object if it has been garbage collected. PhantomReference get API always returns null. Object cannot be obtained from it unlike finalize() API.Usage: So, if your object needs to be freed only when object using it becomes garbage collected than you should be using this API. Another use case is before loading  large object you want to check if the other larger object currently in memory is GCed which will help you avoid the out of memory exception.Hope this helps :)  

CXF-RS adding custom response code

almost 5 years ago | Subodh Gupta: Subodh's Blog

Following snippet show how to return the custom Response code as http response code while returning the response:import javax.ws.rs.Consumes;import javax.ws.rs.POST;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.core.Response;@Path("/")@Consumes("application/xml")@Produces("application/xml")public class Test  { public  Test () { } @POST public Response test() { Response response = Response.status(4xx).entity("Testing").build(); return response; }}

CXF-RS Hiding JAXRS Service Endpoints Listing

almost 5 years ago | Subodh Gupta: Subodh's Blog

You may come across a scenario where you want to stop listing of the exposed service from given endpoint. This can be achieved by setting the property "org.apache.cxf.endpoint.private" to true as shown in following snippet:<jaxrs:server id="serivceId" address="/test">... <jaxrs:properties> <entry key="org.apache.cxf.endpoint.private" value="true"/> </jaxrs:properties></jaxrs:server>This will stop the listing of the service when url http://server:port/test is typed in the browser.

Eclipse Tips

almost 5 years ago | Subodh Gupta: Subodh's Blog

 Escape string while pasting in the editorGo to Window > Preferences, type escape in the search field. Go to Java > Editor > Typing preference page. In last group label "String literals" select the "Escape text when pasting into a string literal".

CXF JSON Generation remove @ prefix

about 5 years ago | Subodh Gupta: Subodh's Blog

Working with CXF-RS if you want to generate the json response along with xml than it becomes pain in cases where your xml is a mixture of attributes and elements. Problem comes because of default jettison json provider which is configured in cxf-rs. The jettison appends the '@' prefix  with the attributes. However, I needed json free from any prefixes. To achieve this i had configure jackson as json provider like this:       <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles></xml><![endif]--><!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]-->         <jaxrs:providers>            <ref bean="jaxbProvider" />            <ref class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>        </jaxrs:providers>                         That's it and you should be free from prefixes.

CXF-RS: Java Code Generation from xml/xsd

about 5 years ago | Subodh Gupta: Subodh's Blog

Cleaner approach is to use xjc like this:Continue to dirty approach below if u need to:When working with CXF-RS services often we start with XML message that will be served. After that we go through endless iteration of generating the right Java POJO's for the XML. The library like apache XMLBeans generate the Java code but the code generated is not what a developer would write and generally tedious to modify and understand.I have come across a work around for generating Java classes from XSD (xml) which is very close to what a developer with decent experience will write. Follow the steps given below to explore the solution:1. Generate the wsdl from from xsd as given in at this link (http://cxf.apache.org/docs/xsd-to-wsdl.html).2. The Java classes can be generated from wsdl from maven plugin entry below find complete details here http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html org.apache.cxf cxf-codegen-plugin ${cxf.version} generate-sources generate-sources ${project.build.directory}/generated/cxf ${basedir}/src/main/wsdl/myService.wsdl wsdl2java Hope this reduce your headache. Happy coding :)

Spring Roo is amazing

about 5 years ago | Subodh Gupta: Subodh's Blog

Developer spend 75% of their time working on boiler-plate code. Spring Roo do amazing job of doing that for you and gets you started really-2 fast. After that you can follow the application curve if writing the business logic. Why Roo?Define the class and its relation it will generate the DB using hibernate you can generate the controller's ( and UI) from the same classes with CURD operation supportedtest code is also gets generated code generated is clean and easy to modifydependency resolution happens through mavenonce you are done projects are eclipse readyeasy to get rid of metadata for production Other tools:I came across Grails but i needed a framework which will generate the java so roo was the better choice for meVideo helped me get started: http://s3.springsource.com/MRKT/roo/2010-01-Five_Minutes_Roo.mov

Netbeans or Eclipse which one to choose

about 5 years ago | Subodh Gupta: Subodh's Blog

There are so many articles on the web discussing this, what i am going to do is just briefly explain pros and cons of each which will help you choose better. Description Netbeans Eclipse Plugins It helps you extent the reach of your IDE to newer technologies without changing the IDE Good Good Code Refactor Reflects the change made in all the references Decent Good Getting Started Time it takes to get going on with your application Good Decent Enterprise Support Usage in big companies, spending effort in eclipse Decent Good Debugging Easy in which you can find a problem Decent Good UI Looks old Decent Good Spell Check Not Present Decent Code Generators Good Good Hope this will help you in making a choice.

First CXF-RS service with Tomcat web-container

about 5 years ago | Subodh Gupta: Subodh's Blog

Looking to get started on CXF-RS, well that was what i was looking for and there are load of articles doing however none of them provide sufficient bullet points to make me understand how the control is following are how to debug the application if something is not working. Well that's what i am going to write here.Following are components you need to get started with first CXF-RS:TomcatEclipse (or some equivalent IDE)SpringCreate a dynamic web project in the eclipse (this is nothing but a simple web project which can deployed and can run when deployed in the web container like Tomcat).Keep your eye on the bold terms featuring in the files...Start will writing the web.xml descriptor file.<!--?xml version="1.0" encoding="ISO-8859-1"?--> <!-- Required for CXF Servlet --> contextConfigLocation WEB-INF/deploy-context.xml org.springframework.web.context.ContextLoaderListener <!-- Required for CXF Servlet initializer --> CXFServlet CXF Servlet org.apache.cxf.transport.servlet.CXFServlet 1 CXFServlet /* Second step is writing the deploy-context.xml and keep it in WEB-INF folder.<!--?xml version="1.0" encoding="UTF-8"?--> Java classes needed for the this:1. com.test.User.javaimport javax.xml.bind.annotation.XmlRootElement;@XmlRootElement(name = "user")public class User {    private Integer id;    private String  name;    public User() {    }    public User(Integer id, String name) {        this.id = id;        this.name = name;    }    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public void setName(String name) {        this.name = name;    }    public String getName() {        return name;    }    @Override    public String toString() {        return String.format("{id=%s,name=%s}", id, name);    }}----------------------------------------------------------------------2. com.test.UserCollection.javaimport java.util.Collection;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlElementWrapper;import javax.xml.bind.annotation.XmlRootElement;@XmlRootElementpublic class UserCollection {    private Collection users;    public UserCollection() {    }    public UserCollection(Collection users) {        this.users = users;    }    @XmlElement(name="user")    @XmlElementWrapper(name="users")    public Collection getUsers() {        return users;    }}------------------------------------------------------------------------------3. com.test.IService.javaimport javax.ws.rs.core.Response;public interface IService {    UserCollection getUsers();    User getCustomer(Integer id);    Response getBadRequest();}-----------------------------------------------------------------------------4. com.test.ServiceImpl import java.util.HashMap;import java.util.Map;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.Response;import javax.ws.rs.core.Response.Status;@Path("/myservice/")@Produces("application/json")public class ServiceImpl implements IService { private static Map users = new HashMap(); static { users.put(1, new User(1, "foo")); users.put(2, new User(2, "bar")); users.put(3, new User(3, "baz")); } public ServiceImpl() { System.out.println("hello"); } @GET @Path("/users") public UserCollection getUsers() { return new UserCollection(users.values()); } @GET @Path("/user/{id}") public User getCustomer(@PathParam("id") Integer id) { return users.get(id); } @GET @Path("/users/bad") public Response getBadRequest() { return Response.status(Status.BAD_REQUEST).build(); }}That's it you are done. Your app structure would look similar to this:App--WEB-INF----lib----classes ----web.xml----deploy-context.xmlDeploy this app in the tomcat server and try hitting following urs:http://localhost:8080/TextCXF/hello/myservice/usershttp://localhost:8080/TextCXF/hello/myservice/user/1

Get Rid of scrollbars on Scroller

over 5 years ago | Subodh Gupta: Subodh's Blog

If you are working on flex mobile project. You would be facing the feature of scrollbars appearing whenever you scroll through the list or widget with-in the scroller component. If these has become a problem for you and you need to get rid of the feature follow the steps mentioned here:Right a new script extending from the scroller Observe vertical and horizontal scrollbars tags which are auto generated modify them and insert the property alpha=0 Include this skin in your scroller and you are done 

New in Dolphin - Java 7

over 5 years ago | Subodh Gupta: Subodh's Blog

With Dolphin java introduced cool new features like:1. Strings in “switch” block     switch(s) {          case “Apple”:          // do something;          case “Orange”:          // do something;          default :     }     2. <> (Diamond) operator – Type inference for generic instance creationE.g List > list = new ArrayList>();vis-à-visList > list = new ArrayList <> ();Empty diamond braces is required and it's not a typo :).     3. Single Catch for multiple Exceptions with "|" operator          try {          // Reflective operations calling Class.forName,          // Class.newInstance, Class.getMethod, Method.invoke, etc.     } catch (final ClassNotFoundException |      InstantiationException | NoSuchMethodException |      InvocationTargetException e) {          log(e)          throw e;     }     4. Also in Java 7, this will work     public void rethrowException(String exceptionName) throws FirstException, SecondException {          try { // ...          } catch (Exception e) {          throw e;     }}     5. Try-with-resources statement – basic objective is to facilitate automatic resource management, simplify coding and highlight pertinent exceptions e.g.     try (InputStream in = new FileInputStream(src);     OutputStream out = new FileOutputStream(dest);) {          byte buf = new byte[8192];          int n;          while ((n = in.read(buf)) >= 0)               out.write(buf, 0, n);          }

Convert XML to ArrayCollection

over 5 years ago | Subodh Gupta: Subodh's Blog

If you have an XML and want to use it in the spark's list component, than you need to first convert it into ArrayCollection and that's what we are doing in this example:Lets assume you have following XML:varstrXML:XML = <blog>       <item>              <title>Blog by Subodh Gupta              <author>Subodh Guptaauthor>      </item> </blog> ;var xml:XML = new XML(strXML);var xmlDoc:XMLDocument = new XMLDocument(xml);var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);var resultObj:Object = decoder.decodeXML(xmlDoc);var ac:ArrayCollection ; if(resultObj.blog.hasOwnProperty("item")) {      if(resultObj.blog.item is ArrayCollection)      {       ac = resultObj.root.element; }} that's it you are done. Cheers.

Divide and Conquer by Java Threads

over 5 years ago | Subodh Gupta: Subodh's Blog

Suppose you have task which collects the data the from various sources and creates a Object containing all this information e.g. information is distributes over various databases, websites and some you need to calculate based on that data. The single threaded application works fine with small amount of data however as data starts growing single threads shows its limitation.There is a interesting property of threads which comes to our rescue. Thread maintains the private copy of object on which it operates called as working copy in which it keeps the local modification which are made to the object. While main memory contains the master copy of every object.After all threads stop executing all the working copies are merged into the master copy. This becomes the curse in case of multiple objects modify the same field in the object because merging back creates the confusion and results in a unpredictable behavior. However if each thread works on the different field of the object merging won't cause a conflict and hence state remains consistent and predictable.This improves the performance many folds and hence application gain scalability which was missing in the single threaded application.Snippet:import java.util.ArrayList;import java.util.List;public class Test {    public static void main(String[] args) {        final List list = new ArrayList();        Person person = null;        for (int i = 0; i < 100; i++) {            person = new Person();            Runnable runnable = createFirstRunnable(person);            Runnable run = createSecondRunnable(person);            Thread thread = new Thread(runnable);            Thread tt = new Thread(run);            thread.start();            tt.start();            list.add(person);        }        for (Person p : list) {            System.out.println("This is " + p.getFirstName() + " " + p.getLastName() + "'s Blog.");        }    }    private static Runnable createSecondRunnable(final Person person) {        Runnable run = new Runnable() {            @Override            public void run() {                person.setLastName("Gupta");            }        };        return run;    }    private static Runnable createFirstRunnable(final Person person) {        Runnable runnable = new Runnable() {            @Override            public void run() {                person.setFirstName("Subodh");            }        };        return runnable;    }    private static class Person {        private String firstName = null;        private String lastName = null;        public Person() {        }        public String getFirstName() {            return firstName;        }        public void setFirstName(String firstName) {            this.firstName = firstName;        }        public String getLastName() {            return lastName;        }        public void setLastName(String lastName) {            this.lastName = lastName;        }    }}

Cool solution for Cross domain

almost 6 years ago | Subodh Gupta: Subodh's Blog

Just follow these steps to make it work:Compose your response as an JSON let say responseObject variable represent this JSON string/object Wrap the JSON response as an argument to a method call e.g. helloMethod(responseObject); where helloMethod is the method name Define this method(helloMethod) which handles this response in the client sideLets take complete working sample:assume JSON Object as str = {"user":{"fname":"subodh","lname":"gupta","type":"blog","category":"tech"}}handleUser(str);function handleUser(str){ alert(str.user.fname);}just to complete the solution look at call below:jQuery.getJSON("http://subodh.blog.com/servlet?user=subodh&responseType=JSON", function(str) {    alert(str.user.fname);});Look at this link for details jQuery.getJSON. http://subodh.blog.com/servlet?user=subodh&responseType=JSON this could be replaced by your service returning JSON response.That's it you are done. :)

Problem/Limitation in using flXHR

almost 6 years ago | Subodh Gupta: Subodh's Blog

I had a cross domain issue and after browsing for a while i came across flXHR which seemed to be promising solution and hence i went ahead with it. It's a flash based cross domain solution which is based on a crossdomain.xml config file (which lists the list of sites from where you can access the services). For more details on flXHR click here.I thought I have the great solution in hand and work with it before I encountered thee major of limitation of flXHR: The location of crossdomain.xml can be specified in configuration of flproxy via loadPolicyURL attribute. Which is supposedly the path flXHR will take to resolve the permission of your domain to access service hosted at that domain.However this is where the problem comes it will not only consider the crossdomain.xml at given location but it will also make a query at the root of the site and hunt gain for crossdomain.xml to see the permission for the client domain to access the service e.g. if you specify loadPolicyURL=www.abc.com/a/crossdomain.xml flXHR lib will still hunt for crossdomain.xml at www.abc.com/crossdomain.xml if your crossdomain is not hosted at this place your call won't be successful.Although this scenario is rare but in case you couldn't host your crossdomain.xml @root or your root redirects somewhere else flXHR won't be of your use.

Prototype and jQuery together…

almost 6 years ago | Subodh Gupta: Subodh's Blog

How to make prototype.js and jquery.js work together….?Answer is in fact very simple and indeed jquery did it all for you already following is the code snippet on how to do it:<script src=”.../prototype.js></script><script src=”.../jquery.js></script><script>jQuery.noConflict();</script> and replace your $ of jQuery with jQuery that it guys you are good to go :)

flXHR and JQuery IE 7 crash

almost 6 years ago | Subodh Gupta: Subodh's Blog

I am using the cross domain flXHR solution with jQuery well initially it was a headache to implement but once done it was on auto pilot seems liked a gem until recently when i got the blocker of IE7 crash on windows XP. The problem seems to be caused by swfobject.js and putting it before jquery declaration will solve the problem:            <script type="text/javascript" src="/flXHR/swfobject.js"/>            <script type="text/javascript" src="/flXHR/flXHR.js"/>

flXHR Error:15, securityError, A security sandbox error occured with the flXHR request.

almost 6 years ago | Subodh Gupta: Subodh's Blog

Error: 15Type: securityErrorDescription: A security sandbox error occured with the flXHR request.Source Object Id: [your object id]I am trying to deploy my application on Tomcat and was continuously facing the issue. The solution to this problem is placing your crossdomain.xml in /webapps/ROOT.Just for reference attaching the sample crossdomain.xml on which I was working trying to workout my PoC: <?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><site-control permitted-cross-domain-policies="master-only"/><allow-access-from domain="*" secure="false"/><allow-http-request-headers-from domain="*" headers="*" secure="false"/></cross-domain-policy>Hope this will help.

CSS common problems

almost 6 years ago | Subodh Gupta: Subodh's Blog

overflow:hidden; doesn't work with span use div insteadfont-weight: Semi-Bold; doesn't work on most browsers use font-weight: 600; instead