Tuesday, November 20, 2012

Using Interceptor in Websphere Portal and Spring Portlet 3.0

Spring has come up with Spring Portlets for websphere portal. There are lot of documentation available which talks about integration steps for Spring and websphere portal. But i struggled to find how to use interceptor with spring portlet 3.0.

I have used Spring with J2EE applications and using interceptor was very straight forward. We need to put entry in springContext.xml file and map all the controller who needs to use this interceptor.

For Spring portlet there are different steps which you need to do to configure Interceptor.

  Follow the below steps:

1. Create Interceptor class in your project. check the sample interceptor code below. 

package com.custom.interceptor;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.ModelAndViewDefiningException;
import org.springframework.web.portlet.handler.HandlerInterceptorAdapter; 
public class YourInterceptorImpl extends HandlerInterceptorAdapter {
    @Override
    protected boolean preHandle(PortletRequest request,PortletResponse response, Object handler) throws Exception {
        System.out.println("Inside Prehandle method");
        //business logic
    }
// there are other method which we can use based on when you want to //execute the logic.
} 

2. Locate applicationname-portlet.xml file and below code in the file.

<bean id="customInterceptor" class="com.custom.interceptor.YourInterceptorImpl" />    
<bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
    <list>
        <ref bean="customInterceptor" />
    </list>
</property>
</bean>

3. Restart server and access in via browser.

You should see in console "Inside Prehandle method" message. You can add the business logic which needs to be executed before any logic in controller gets executed.


Components of Big Data - Hadoop System

In this blog i will explain important components which are part of Hadoop System. I will give very brief overview of these components. Be...