One of the new feature in Spring 3 MVC has been introduction of mvc XML configuration namespace that simplifies the setup of Spring MVC inside the web application.
Spring 3 allows you to intercept the request and response headers without writing the filter explicitly . Spring’s handler mapping mechanism includes handler interceptors.
If you would prefer to write a filter explicitly, it has been covered in Servlet Filter to prevent No Cache.
From Spring MVC docs
Interceptors located in the handler mapping must implement HandlerInterceptor from the org.springframework.web.servlet package. This interface defines three methods: one is called before the actual handler is executed; one is called after the handler is executed; and one is called after the complete request has finished. These three methods should provide enough flexibility to do all kinds of preprocessing and postprocessing
You have an option in which instead of writing your own custom class, you can modify the servlet-Context.xml file to provide no caching feature
Here is what will go inside the file
<mvc:annotation-driven/>
<mvc:interceptors>
<bean id=”webContentInterceptor”>
<property name=”cacheSeconds” value=”0″/>
<property name=”useExpiresHeader” value=”true”/>
<property name=”useCacheControlHeader” value=”true”/>
<property name=”useCacheControlNoStore” value=”true”/>
</bean>
</mvc:interceptors> Read more…
In one of the posts, I had talked about IE caching AJAX calls. To solve this issue , you would have to modify response such that it informs browser not to cache the data coming from this server.
I am explaining it in plain old fashioned way of ServletFilter.
Below is the code for ServletFilter.
public class NoCacheFilter implements Filter {
private FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
public void destroy() {
this.filterConfig = null;
}
/**
* Modifies the response. Sets the appropriate headers
* and invoke the next filter in the chain:
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader(“Cache-Control”, “No-cache”);
httpResponse.setDateHeader(“Expires”, 0);
httpResponse.setHeader(“Pragma”, “No-cache”);
chain.doFilter(request, response);
}
}
This is helpful for browsers like IE which Cache your data by default and do not display fresh data. This is one of the situations when you are working with JSON REST web services in which you might to pull and display fresh data.
Some time you would like to see the header information being returned by your response.
This is really useful when are playing with cache header and response. It was pretty easy in Firefox when you have the firebug installed but in Google Chrome , it is a little tricky.
To view the header in Google Chrome, go to
Developer tools or Ctrl + Shift +I , Click on Resources , select the path on left and then select headers

If you are looking to add comments to your implementing classes in Eclipse, here is the cool technique
Let us say you have class UserDAO and has method getUser()
public interface UserDAO{
public User getUser();
}
To add a comment over the method select getUser or take the cursor before getUser and press ALT + SHIFT + J It will add the comment on top of your method
/*
* @param
* @return User
*/
public User getUser();
Now suppose you want to add non java doc comment in implementing class
public ClassUserDAO{
public User getUser(){
}
}
To add a comment over the method select getUser or take the cursor before getUser and press ALT + SHIFT + J . It will add the non java doc comment on top of your method
/* (non-Javadoc)
* @see com.skg.dao.UsertDAO#getUser()
*/
public User getUser(){
}
If you had been shopping regularly online and looking for good deals, you might have come across priceGrabber or Next Tag. These two sites give an excellent comparison of price across different retailers but then it interferes with your browsing experience .
You will have to copy the name of item , go these sites and then get comparison of prices.
Now this was fine with me until I found PriceBlink.
True to its name , when you’re viewing a specific product, PriceBlink quickly searches over 3,000 merchants for lower prices and lets you know whether you’ve found the best price.
Isn’t that awesome ?
Other day I went to Amazon and found the price of 3D glasses reduced to $94 from $218. It looked to me a pretty good deal until I noticed price blink pointing to another site with these 3D glasses priced at $69 with free shipping.

You can see the priceblink displaying the price on the top.
It saved me some money and I am hoping you will enjoy price blink as well. It is available as Firefox and Chrome Plugin. You can download and install in you browser.
Happy Online Shopping.
In last 2 posts we had been covering asymmetric clustering .
More can be found at
What is asymmetric clustering – Part 1
What is asymmetric clustering – Part 2
What is an appropriate level of granularity for a partition?
That’s very application specific. Customers currently typically use less than 512 partitions. Partitions can be either:
Named partitions for a specific function in the application.
Here the application may need a single thread in the cluster doing database archiving for example or summarizing audit records. This work could be done in a partition and the partitioning facility runtime would make sure it’s always running in one cluster member. These partitions correspond to conventional singletons.
Named partitions for groups of data sets, hashing is an example. All datasets whose key hashes to X run on partition X. An example here is a stock symbol. A partition could correspond to a stock symbol and be responsible for all order matching for that symbol. This partition can cache all symbol related data and then execute the incoming orders/quotes in sequence and write any state changes through to the database to harden them. The goal here is to give each partition exclusive write rights for the subset of the data corresponding to that partition in the database.
Can partitions be used as a conventional singleton?
Yes, a named partition is simply a conventional singleton. HTTP and EJB client requests can be routed to the JVM in the cluster that hosts a specific partition. The application programmer must write an interceptor that is called on the EJB client when a remote method on a specific stateless session bean is invoked. The interceptor then examines the method name and arguments and then returns the name of the partition that the request should be routed to. So, for example, a client can call an EJB method called ‘acceptOrder’ that takes an Order object as a parameter. The interceptor is provided with the method name and argument(s) and the interceptor then returns the String stored in the Order.getCompanyName() method. The client then routes the request to the partition named with the company name. If the JVM with that company crashes or fails then WebSphere automatically fails it over to another cluster member and new requests are now routed there instead.
So the workload management component lives in the client stubs? What about work arriving using messaging?
Applications can also use JMS or non JMS messaging providers such as Tibco Rendevous or Reuters SFC to receive partition related work. When a partition is activated in a JVM then the application can subscribe using JMS or native APIs to queues or Topics for messages for that partition. When the partition is deactivated then the application can unsubscribe from the topic or queue. The async beans feature of WebSphere is critical in providing this kind of flexibility to the application and such an approach is not possible with the J2EE specification. Async beans provides a fully supported threading capability for J2EE application and allows custom threading models for receiving this work. JSR 236 is intended to standardize these APIs and fill this current gap in the J2EE programming model. Read more…
In one of our earlier posts, Synchronous calls with XMLHttp request , we had displayed a code sample on how to make the call.
So why do we chose synchronous over asynchronous ?
There are situations in which you would like to use Synchronous XMLHttprequest because the page rendered depends upon the data received . If we do not have the data we will have wait for the data to come back . hence some user take the route of making synchronous requests.
But when we were reviewing our design decisions, there was some though on Should we be using synchronous XMlHttprequest ?
While going through Mozialla site , I found this
Note: You shouldn’t use synchronous XMLHttpRequests because, due to the inherently asynchronous nature of networking, there are various ways memory and events can leak when using synchronous requests.
Also the AJAX patterns recommend
In practice, XMLHttpRequest calls should almost always be asynchronous. That means the browser and the user can continue working on other things while waiting for a response to come back
Based on this information, I think it would be wise to use asynchronous request. Any suggestion ?
Reference :
https://developer.mozilla.org/en/using_xmlhttprequest
In my last posts I had talked about Cross domain scripting issue with Firefox and how to solve cross domain scripting issues on tomcat
But looks like the issue has not been completely resolved. I have used the CORS filter solution as we are working on tomcat but have some problems in exception scenarios
Problem Statement:
I am trying to make a call to a REST service and trying to catch an 404 or 200 condition returned by REST and show an appropriate message to user based on error code.
My url in browser is http://localhost:8080/myapp/test.html
The code inside is
<html>
<head>
<script type=”text/javascript” charset=”utf-8″ src=”json2.js”></script>
<script type=”text/javascript” charset=”utf-8″ src=”jquery-1.4.4.min.js”></script>
<script>
function invokeFunction()
{
var myService = null;
if (window.XMLHttpRequest) //for mozilla
{
myService = new XMLHttpRequest();
if ( typeof myService.overrideMimeType != ‘undefined’)
myService.overrideMimeType(‘application/json’);
}
else if (window.ActiveXObject) //for IE
{
myService = new ActiveXObject(“Microsoft.XMLHTTP”);
}
var serviceUrl = “http://127.0.0.1:8080/myapp/webresources/user/1111“; Read more…