Archive for the ‘Tips & Tricks’ Category

Clearing formBackingObject data after spring form submit

Friday, February 13th, 2009

It’s all to common for beginners of spring to stumble upon what may look like odd spring problems. Most users think that these are bugs while more often than not they are expected spring behaviour. I myself have stumbled upon my fair share of such problems.

One such problem is clearing the data contained within the formBackingObject (or command object) after a successful (more…)

Automatically redirecting all requests to SSL in web application

Wednesday, February 11th, 2009

More often than not you are required to secure your login pages and certain admin resources using secured socket layer (SSL) or TLS. This can be quite a task if you go around manually redirecting all your http requests to https and then configuring your server. Whats worse is that another team member may forget to secure certain resources thereby exposing them through “un-safe” means.

The best way to secure such resources is to use the (more…)

Transaction management across multiple DAOs in spring

Friday, February 6th, 2009

A question commonly asked on the spring forums is that a service makes calls to multiple DAOs, how can ALL the calls be rolledback if any of the calls throws an exception. The simplest way to do this is to make your service transactional while keeping your DAOs non-transactional.
Example Service :

//imports & package
@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Override
        public void addUser(User user) {
		userDao.doFirstOperation();
		userDao.doSecondOperation();
	}
}

Notice the lack of @Transactional annotation in the DAO below.

public class UserDao {
	public void doFirstOperation() {
		// some stuff
	}

	public void doSecondOperation() {
		// some stuff
	}
}

Remember that your DAO methods MUST through an unchecked or runtime exception for the transaction to rollback on its own. Otherwise you have to declare the rollback in case of a checked exception.

Why ConcurrentHashMap is better than Hashtable and just as good as a HashMap

Thursday, February 5th, 2009

ConcurrentHashMap is a pretty ignored class. Not many people know about it and not many people care to use it. The class offers a very robust and fast (comparatively, we all know java concurrency isn’t the fastest) method of synchronizing a Map collection.

I have read a few comparisons of HashMap and ConcurrentHashMap on the web. Let me just say that they’re totally wrong. There is no way you can compare the two, one offers synchronized methods to access a map while the other offers no synchronization whatsoever. What most of us fail to notice is (more…)

Monitoring spring based applications including hibernate statistics using JMX

Saturday, January 31st, 2009

Spring Framework is by the most versatile framework for java applications. It can be used with any kind of application, be it an applet, a swing app or a web application.

Spring transaction management is one of the most powerful features of spring. It manages your transactions for you with minimal code, infact all you need to do is put a few lines of code in your configuration file and then annotate your classes/methods with the @Transactional annotation. Combining this with ORM tools such as hibernate, what you have is full fledged transaction management running in under 5 minutes.
(more…)

Amazon Web Information Service

Saturday, May 27th, 2006

Everyone knows about the Amazon E-Commerce services and everyone loves it. It’s a simple, too simple really, way of starting your own Amazon affiliate store. Not to mention for gathering information from Amazon. Take a look at Amazon.com and you’ll see why people want that information, they have everything, literally.

Amazon also has another very interesting service, Alexa Web Information Service. Some service highlights:

  • Gather information about Web sites including traffic data, contact info, related links and more.
  • Access an XML-based search index based on Alexa’s Web crawl and incorporate search results into your site or service.
  • Build a Web directory into your site or service using an Alexa enhanced DMOZ-based browse service.
  • Use the Alexa WebMap to gather links-in and links-out information about all pages on the Web and invent wholly new search engine algorithms.

(more…)

Payal IPN and the Sandbox

Tuesday, April 11th, 2006

Paypal’s IPN can be frustrating at times and any programmer who’s worked with the IPN would know what the sandbox is for. It’s truly a wonderful thing. It let’s developers test out the IPN integration without having to spend anything through their own account. (more…)

Amazon E-Commerce Services

Monday, November 21st, 2005

Wonderful is the word.

For those who don’t know what AWS is, it’s the Amazon API for accessing their info. There are hundreds and hundreds of sites out there using this API to power their affiliates stores. Amazon pays the affiliates 10% of all sales generated if the site manages to make a sale for Amazon.

The way it works is that you, the affiliate, place a request through a SOAP client for data pertaining to a particular Item/Group of items. Amazon processes this request and returns the data to you in an XML file. To pass this request to Amazon and get the data I used a class by Calin Uioreanu over at php9 (Thank you!) (more…)

PHP and PDF

Monday, November 21st, 2005

I recently recieved a project from ScriptLance to generate PDF reports from MySQL data using PHP. I hadn’t really experimented with report generation in PHP so I had little idea what I was getting into. So I surfed over to PHP.net and started reading.

A few minutes later I tried out a couple of examples posted on there as well as other PHP-related sites. None worked. So I googled a bit and landed on FPDF.org. I haven’t looked back since and I’ve finished the project. Infact, I’ve recieved one more project to do the same. (more…)