Showing posts from 2011

Spring Roo is amazing

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 me
Video helped me get started:

Netbeans or Eclipse which one to choose

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.

DescriptionNetbeansEclipsePluginsIt helps you extent the reach of your IDE to newer technologies without changing the IDEGoodGoodCode RefactorReflects the change made in all the references DecentGoodGetting StartedTime it takes to get going on with your applicationGoodDecentEnterprise SupportUsage in big companies, spending effort in eclipse DecentGoodDebuggingEasy in which you can find a problemDecentGoodUILooks oldDecentGoodSpell CheckNot PresentDecentCode GeneratorsGoodGood
Hope this will help you in making a choice.

First CXF-RS service with Tomcat web-container

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)Spring Create 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.



CXF Servlet




Second step is writing the deploy-context.xml and keep it in WEB-INF folder.

Java classes needed for the this:

1. com.…

Get Rid of scrollbars on Scroller

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

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 creation
E.g List > list = new ArrayList>();
List > 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) {
          throw e;

     4. Also in Java 7, this will work
     public void rethrowException(String exceptionName) throws FirstException, SecondException {

Convert XML to ArrayCollection

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>
              <title>Blog by Subodh Gupta
<author>Subodh Guptaauthor>

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("item")) {
      if( is ArrayCollection)
      ac = resultObj.root.element;

that's it you are done. Cheers.

Divide and Conquer by Java Threads

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 mergin…

Cool solution for Cross domain

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:

function(str) {

Look at this link for details jQuery.getJSON. this could be replaced by your service returning JSON respons…

Problem/Limitation in using flXHR

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.a…

Prototype and jQuery together…

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>
and replace your $ of jQuery with jQuery that it guys you are good to go :)

flXHR and JQuery IE 7 crash

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.

Error: 15
Type: securityError
Description: 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 "">
<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

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

Comparison between Firefox 4 and IE 9

Guys I have installed the latest version of both the browsers as an developer my comparison are tabled below. This is what i have experienced and doesn't based on any statics:
IE 9FF4JS running timeIE is definitely better than earlier IE'sFF is much faster than any browser i am using right now (which includes Safari 5, chrome 10) and is comparable to chrome 10 on win 7.Look and FeelIE looks much better and lesser clutteredFF doesn't look badToolbar usage buttons like refresh and Go etc...IE embeds them in the address bar and i find it quite confusing and harder to use (you can customize and move refresh button to the front of address bar but for me result was no different in usage)FF doesn't Change from previous versionsNotifications (Save a file. block script etc.)Notification bar pops up from the bottom of the page which takes time to get use tooFF doesn't Change from previous versionsAddress BarProvides united Address and search bar gives good experienceFF doesn… Connection reset

I am able to fix the problem via setting the following params on the HTTPClient class...client.getParams().setParameter("http.socket.timeout", new Integer(0));
client.getParams().setParameter("http.connection.stalecheck", new Boolean(true)); Connection reset at Source) at Source) at Source) at org.apache.commons.httpclient.HttpParser.readRawLine( at org.apache.commons.httpclient.HttpParser.readLine( at org.apache.commons.httpclient.HttpConnection.readLine( at org.apache.commons.httpclient.HttpMethodBase.readStatusLine( at org.apache.commons.httpclient.HttpMethodBase.readResponse( at org.apache.commons.httpclient.HttpMethodBase.execute(Htt…

Interview at Progress Software

I have given interviews before however this one was special. Lets start from the beginning.

I got the call from Progress Software and i was scheduled for telephonic discussion on the next day.

Next day i got the call from HR and she started with some questions on Java and some basic puzzles (i wasn't very impressed with the thought of so called HR technical interview, anyways) and soon after it i got scheduled for another telephonic technical interview. The interview went well and it was basically on Java, design problems and little bit algos.

After a week i got call from HR for the F2F interviews in hyd and they said they will be sponsoring the trip. This is the first time I googled about Progress Software (but didn't get much of an idea except for the good share price :) ). I said yes for the onsite interviews (more than company hyderabadi biryani was calling me :) ).

Onsite started on the sad note as after delayed flight (because of fog in Delhi) HR introduced to be a guy w…

Java API for Print, Browse, Shutdown from Simple Java Program on Windows OS

I have been working on a app which takes the commands from database and execute on a windows machine (XP,Vista & 7). Commands include browse(given a link), print (given a location) and shutdown the machine. I have utilized the Java Desktop API for solving this problem i have used this post. All you need is following three snippets:

1. Get Desktop instance:

Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop();

2. For Browse/Open file:
      File file = new File("url");;

3. For Print file:         File file = new File("url");          desktop.print(file);
3. For Shutdown file:  Process child = Runtime.getRuntime().exec("shutdown -s");