spacer

 

Wednesday, September 10, 2008

Sitemesh decorator goes berzerk with Spring MultipartResolver

The Issue
This particular blog disscusses a particular issue with Sitemesh when used with Spring Framework. The issue in sitemesh occurs when the size of the uploaded file exceeds the maximum settings set in Spring. A workaround is also provided for those who are seeking for alternatives.
Framework Versions
  • Spring Framework: 1.x
  • Sitemesh: 2.2.1
Given the Following Situation

Given the following multipartResolver in my spring servlet xml config file:

1.) servlet-xml file

<bean id="multipartResolver"
       class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
   <property name="maxUploadSize">
     <value>20000</value>
   </property>
   <property name="maxInMemorySize">
     <value>0</value>
   </property>
</bean>

2.) A multi-part form page that uploads a file.

3.) One or more sitemesh decorators applied to the page (1 main decorator and a few inline decorators).

When Submitting the Form

Upon submitting the form, the request goes to the DispatcherServlet and calls the checkMultipart(request) method. If the size of the file being uploaded exceeds the max, a MultipartException gets thrown but does not get propagated. Spring tries to resolve the view assigned to this exception mapped with SimpleMappingExceptionResolver. The implication to this is that all pages being decorated by sitemesh are showing the default error page assigned.

So if a decorator is used on the menu, header, sidebar, and body of the page then the user will see 4 exception pages.

I've created a workaround for this by extending the DispatcherServlet and overloading the processHandlerException(...) method to rethrow any exceptions of type MultipartException (and not try to resolve the exception page assigned in spring).

Session Timeout Issue of an AJAX Driven Page

I love AJAX and I use it when it's necessary. I use Rico AJAX, dwr, and Yahoo UI Library in particular because it works. The only issue I'm having is I haven't figured out a way to detect session timeouts.

Suppose I have the following page:

  • A view users page.
  • When user clicks on an item (a user) on the list of users, the detailed information about this user is retrieved via AJAX.
  • The user detail response coming back is an XMLResponse and contents of this reponse is processed by the Rico AJAX API and rendered in the user details <div> element.
#################################
# List of Users #               #
#               # [User Detail] #
# user1         #               #
# user2         #               #
# user[n]       #               #
#################################
So what happens when the user session times out?

In a standard web application, the request would then be redirected to the login page, user authenticates, then redirected back to the original URL.

In our AJAX driven User Detail page, the XML Response coming back turns out to be an HTML response, in this case the designated login page. So, the AJAX API (Rico) or any AJAX API will fail to render the <div>. In the frames world, the contents of the User Detail section would be a login page. In our case it is blank.

I think the AJAX API's should somehow detect this and refresh the page itself. Otherwise, what's going to end up happening is that all developers using the AJAX API would end up implementing their own scheme. For instance, I would resolve this by creating a BaseAjaxController class and let that base class handle what happens when a session times out (like refresh the page) so the user would be forced to re-authenticate him/herself.

Popular Posts

Featured Post

Encrypting Properties File Values with Jasypt

Encrypting Properties File Values with Jasypt What's the fuzz all about? Property files are text resources in your standard web applic...