Category Archives: java

Gone are the days of EJB

I hated EJB. I still hate it and will keep hating it. Perhaps its not just hatred but its apathy. Be it EJB 1.x , 2.x or 3.x.  Frameworks come and frameworks go and I don’t feel EJB has survived with respect to the hype it received. I would discuss some major points which get EJB lagging behind:

Too many diversified versions: For those of you who have been with EJB since 1 or 2 would probably agree how it vagabond the versions were. EJB. I once heard Debu Panda from Oracle saying : EJB 1 was like a Queen Honey Bee – Lot of Hype  but did nothing. EJB 2.x came out like an Elephant: Like a mammoth, It could do a lot many stuff but eating away a lot of resources too! Then came EJB 3.x which is like a COW who is much productive and minimal resources.

But the big question is : You still need to write a lot of code! EJB is just not available in the student community. There are quite a few books, but they are industry oriented or rather useless.

Talk of the industry: When I used to take sessions for EJB for young industry guys. I get bombarded with questions on how I could help them use EJB to solve their problems!

Come on guys, EJB is OK but you don’t have to use EJB all the time!!  Its like old days of 90’s when XML was very popuar and people just used XML with every second application! Give me a break!

Fine lets talk about enterprise now as EJB’s E stands for Enterprise. EJB’s model definitely gives you a lot of stuff for the enterprise framework but it surely takes all your resources – Manpower, Infrastructure and mostly contunity. EJB makes you lame. Once you have implemented a lot of things in EJB its quite difficult to move out of it. I hate you EJB for that.  Many of my blog readers are avid Oracle and EJB fans, but sorry guys but EJB has #FAIL ed.

Competition: With EJB 3.x standing still, we have a lot many competing technologies at our hand. EAI frameworks like WebMethods, TIBCO and Kettle (Open Source) gives you far better implementation and reduce overall costs.
Another such framework which has not got the fame it should get is DWR – Direct Web Remoting. TIBCO sponsors this project and its a MUST try out.

The only thing I like about EJB is the persistence API but when things get complex, not many people can do a great job with it. So eventually they still end up doing more stuff.

Overall, I still hate EJB and feel it should reach its end of life!

html2pdf using jsp and linux

Have you ever thought of downloading the current viewed page as PDF. Here’a  quick program which can read an HTML and convert it to PDF using JSP or Servlet. I am going to call an external linux command called ‘convert’ which does all the magic for me.

All I need is a linux box with ImageMagick setup along with html2ps and ghostscript. I can get this very very easily from my ubuntu’s apt-get install …

So here’s the small snippet which I wrote after setting up.

try
{
Runtime rt = Runtime.getRuntime() ;
Process p = rt.exec(“convert /usr/local/share/pdfformat1.html /usr/local/share/pdfformat.pdf”  ) ;
p.waitFor();   //<– This waits until the operation is over
System.out.println(p.exitValue());  //<– if the output is 0 it means pdf was generated successfully
}
catch (Exception e){
e.printStackTrace();
}

Now this can be quite a good replacement for iText html to pdf conversion which is quite buggy (I am a huge fan of iText, but somehow this HTML needs to be rendered properly I feel)

After having got the file, read the file and reply to your browser by response.setContentType(“application/pdf”);

Please note, ONLY valid HTML tags are allowed. This method doesn’t support CSS. If someone knows of it, please let me know.This method works perfectly well with valid HTML syntax. So if your output pdf isn’t looking as expected, please check your HTML.

You can use this little utility to check your valid HTML #: sudo apt-get install wdg-html-validator and then run #: validate filename.html
This will list out all the invalid HTML tags.

So for all you report building guys out there, here’s a quick tip: Just output your report as HTML <offcourse with data poluated> and then use this utility to generate a PDF out of it!

HeartBeat

I am starting a project called HeartBeat

HeartBeat phase 1 will consist of the following features:

1. Server script configuration
2. Implementation of libtrilead for Java SSH
3. Creation of libheartbeat
4. Basic GUI under Swing

Users will be able to configure almost any service and start and stop it remotely through SSH.

Imagine a single GUI to manage all your servers around the world with a simple click!

Life without Apache : Meritocracy in Action.

I am obsessed with Apache. Yes! I am and I am proud that I am!

I was just wondering how life would be WITHOUT Apache!

  • We would still be doing ASP. Many of us would have gone into ASPX and C#

  • CGI and PHP wouldn’t have come out..

  • Total no. of websites in the world would be less. I don’t know how much % but yes, it would surely be less.

  • There would all be Windows Hosting Services everywhere and the prices would be higher and higher…

  • Who can forget the popular Tomcat. Java wasn’t open source before, other app servers were not that comfortable interms of price, simplicity and ease of use. Every newbie in JSP/Servlet starts with Tomcat. People crib that Tomcat doesn’t have EJB, who needs EJB these days?

  • No Java projects would compile using Make, so Ant came it. Imagine how difficult life would be without ANT scripts.

  • MVC the most popular design pattern: Struts is the name you think of. If it weren’t there, you’d still be writing your own servlets and JSP and controller logic.

  • Almost 80-90% of GOOD Java EE developers would use Apache Commons. I mean who doesn’t use it?

  • Logging your application for debug and support, What would you do without Apache Logging Sevices

  • Forget all programming, there is still no comparision with Xerces for XML. I challenge.

  • Make your code as Webservice? No words about Axis, yet again apache product!

  • You want a middleware java messaging framework for your JMS? Use ActiveMQ

  • Object relation model: Try iBatis, you wont leave it again.


All in all, If there was no Apache, Life wouldn’t have stopped but would have been SO SO damn difficult. My many many thanks to Apache…

Some Javascript Tips

I have been doing a lot of JavaScript these days. Each day I learn newer things and each day I am starting to like it more and more.

I am going to compile a few queries where I broke my head.

Q) If I do window.open(‘anotherPage.html’), How can I change the DOM of the parent window.
This problem arrived when I was trying to add more rows to a table from another window itself.
Problem: Firefox allows it. But IE doesn’t allow.
Solution: Use cloneNode() for FF. For IE , create the row again by attachRow()
Now for each cell, loop through it and do insertCells() and then copy the innerHTML to it.
All this is done in a simple loop through the table.

Q I have 3 frames on a page, I want to submit requests to page 2 and 3 at the same time
Do: document.forms[2].functionName();
yes, its as easy as this…
in your functionName(), you can add code to submit the form.submit();

Q Recursive Ajax calls.
Problem: To keep refreshing content of a page through Ajax.
One might typically use setInterval() but what if setInterval fires while a request from your ajax is coming back?
Solution: Use a global variable called “lock”. Everytime you make a request set this lock, the call back function should release the lock.
When setInterval fires your ajax request function it should exit if its locked.

Q. getElementById(‘idname’). Don’t use it too often, Try to traverse though the DOM by your code.

Q. Always give IDs to your form. Someday you’ll find that this is very useful. You can submit a form from anywhere if you do this by getting the refrence of the form and then yourform.submit()

Q. Try to avoid excess IDs, This will occupy more browser memory interms of DOM parsing.
For example, If you have a table, don’t give ID to each row. instead give the id to the table and then traverse the table.

Q. Do overuse Ajax and submit multiple requests simultaneously. Browser might allow this, but your database will not. Specially when you’re doing connection pooling. In connection pooling , you have the same connection object and multiple execution of sql queries on the same object from different clients will result in failed transactions.

Q. attaching events is a good idea , but beware, IE and FF behaves differently. The API is completely different.

Q. Always use a common Javascript Browser detection Module. Make the detected browser global and then customize your scripts that way.

Q. Often while debugging we use alert(“debug msg here..”); and waste time in commenting and uncommenting it. Instead use a global variable called “debug=true”. And use if (debug) alert(“”);
You wont have to comment or uncomment it all the time.

Q. There are some good Javascript debuggers. Use them. The simplest one is FF error console. But what about IE? Yes, now you can use FF error console to debug IE related Errors too.. Install the FF IE tab plugin and have fun.

Q. Another great FF extension is Firebug. MUST MUST have for all you JS guys….

WebOSS 07: The Event

On 13th October Teknowledge Software conducted the first “Free for All” Open Source Web Technology conference called WebOSS ’07.

The event was the first of its kind to be held in Kolkata. Teknowledge Software, a software house based in Kolkata hosted the event along with WBUT as the venue sponsor.

Volunteers dressed in white T-shirts with WebOSS ’07 logo worked hard to put the event together.

The event started at around 11:30. I was the first one to speak and spoke on RIA: Which technology one should choose? Slides can be found here

I attended the next session by Pradeep on how to build application with AJAX. Pradeep’s presentation can be found here

There was a lunch break after this which contained burgers, cakes, ladoo! and Frooti!

The next session was of Shabbir’s on Speeding up your websites. A great session which included tips and tricks to speed up the sites from network and client browser point of view. Shabbir’s content can be found here

The next session was of Naveen. He really went dirty into the code like Pradeep. It was really a good session and I have started respecting Perl (i’m more a PHP Guy!)

It was a good conference, the jam packed audience was eager to know more and more!

Overall, a fun event like barcamps! Its great to see such events happening in Kolkata! Go ahead Kol!

You can find ALL pictures here:

Hussain on RIA


Pradeed, Naveen and Shabbir

Jam Packed Audience


Pradeep, Naveen and Shabbir again.