SyntaxHighlighter

Saturday, November 29, 2008

FTP Operations In Enterprise applications

As far as my experience in enterprise application domain especially the application having integration kind of nature requires frequent FTP operation.
Recently me too had similar requirement,wherein I need to fetch a file from the remote server....
I was using Mule as integration bus for my application,though Mule provides in built support for FTP transport,It has 1 major drawback in case of FTP operations as listed below
1.Mule FTP Connector has polling nature and it deletes the file once its downloaded from FTP server.
Sometimes its allowed and perfectly acceptable to delete the downloaded file from remote FTP server but not always.
That lead me to apache commons NET project
This project consists of basic client side implementation of transport protocols such as SMTP,FTP,POP..
If you look at these API's these are one of the most simplest way to implement the FTPCleint
FTPClient ftpClient = new FTPClient();
ftpClient.connect("ftp.foo.com", "user01", "pass1234");
ftpClient.download("C:\\Temp\\", "README.txt");
// Eventually other operations here ...
ftpClient.disconnect();

Can you see ,how simple is this code...

Saturday, September 27, 2008

Spring-Quartz Transactions

Its been after a long time I got chance to sit back in summarize....Past 3 months were hectic in terms of work n there was always a race on ,against time.
Recently I came across a excellent feature of Spring framework,Just wanted to share with you all.
You must be aware of scheduling framework Quartz.
Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application.
I was working on a spring application ,all my business services are spring beans ,my transaction manager is "org.springframework.jdbc.datasource.DataSourceTransactionManager" which is local transaction manager,as my application is not in demand of JTA or any distributed transaction.
Now comes a trick ,when I come across following scenario
Suppose I have a business service which does following
  1. Insert a record in DB
  2. Schedules a job in Quartz
  3. Updates some record in DB
Now what I required is
  • If update in step 3 fails ,I want to rollback steps 1,2
  • If Step 2 fails ,I want step 1 to rollback
As mine datasource is a Local transaction manager,It cant work across multiple resources and manage.That was enforcing me to use JTA or similar transaction manager ,which is actually overkill for my application.
As expcted ,Solution to this problem is provided by none other than spring,Thanks to Juergen Hoeller.
Spring comes with
org.springframework.scheduling.quartz.LocalDataSourceJobStore which is extension to Quartz JobStoreCMT
Now you just need to cnfigure your job store as below
org.quartz.jobStore.class =
org.springframework.scheduling.quartz.LocalDataSourceJobStore
Now ,Operations performed by this JobStore will properly participate in any kind of Spring-managed transaction, as it uses Spring's DataSourceUtils connection handling methods that are aware of a current transaction.
How easily spring solves this problem shows ,springs capability to be an enterprise application framework......


Friday, June 20, 2008

My thoughts on developement frameworks...

I have been in the IT industry for past 2 years,which is really a short period.
But still some how I feel ,whatever I have gained so far,I can share...
So started writting....
I have been working on Java and related technlogies and frameworks,I worked on Spring,iBatis,bit of hibernate,struts along with some custom frameworks (Refres to frameworks developed by individual organizations to meet there technical requirement) n toolkits....
When we say its a framework ,its actually a collection of usage patterns combined to hide the complexity from animal called developer or the framework implementor or user.

Whenver these developers (me too still a developer :)) use these frameworks,
Usually framework are made for generic purpose ,so often we need write configuration file
either XML or properties file
The framework must be supported by IDE plugins (Such as Spring IDE for Eclipse for Spring) otherwise writting a XML configuraton according to framework expectation requires expertise and experience on that framework, a begineer will struggle like anything.
Second thing is the exceptions shown by frameworks ,are mostly misleading.... :( ,thats what my experience ,as in If you mis-spelled some attribute in some configuration file but it will show you all other things apart from it.. and now debugging a framework becomes a challenge....
In my career ,I worked on couple of custom framweorks too... the experience with them is also not that satisfactory..., as frameworks I used , which was simple ,but developers need to write more lines of code for developing a functionality which can be devloped in less number of lines without using that framework .
So, I feel a framework must developed keeping in mind that the implementor need to as less LOC possible .One truth is that as many LOC ,that many defects you will inject...
So My idea of good developement framework is..
1.Configurable via XML, with IDE plugin support
2.Good exception handlling,pin point the actual error .....
3.Minimal LOC for implementors or framework users
4.Ease of deugging or catching misconfiguration
5.Clear and comprehensive API documentation

Many of the industry proven developement frameworks do provide support for points 1,3 ,5 but points 2,4 are still very much required for good developement framework...
I have all this in mind from long period, finally was able to free up my mind..
Thats it....m summing up :)