1 5 6 package org.exoplatform.filter; 7 8 import java.io.IOException ; 9 10 import javax.servlet.Filter ; 11 import javax.servlet.FilterChain ; 12 import javax.servlet.FilterConfig ; 13 import javax.servlet.ServletException ; 14 import javax.servlet.ServletRequest ; 15 import javax.servlet.ServletResponse ; 16 17 import org.exoplatform.container.PortalContainer; 18 import org.exoplatform.container.RootContainer; 19 import org.exoplatform.services.database.HibernateServiceContainer; 20 21 22 27 public class AxisFilter implements Filter { 28 29 public static final String WSRP_CONTAINER = "portal"; 30 private HibernateServiceContainer hserviceContainer_; 31 32 public void init(FilterConfig filterConfig) throws ServletException { 33 } 34 35 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) 36 throws IOException , ServletException { 37 PortalContainer pcontainer = RootContainer.getInstance().getPortalContainer(WSRP_CONTAINER); 38 PortalContainer.setInstance(pcontainer); 39 try { 40 filterChain.doFilter(servletRequest, servletResponse); 41 } finally { 42 getHibernateServiceContainer(pcontainer).closeAllSessions() ; 43 } 44 } 45 46 public void destroy() { 47 } 48 49 private HibernateServiceContainer getHibernateServiceContainer(PortalContainer pcontainer){ 50 if(hserviceContainer_ == null){ 51 hserviceContainer_ = (HibernateServiceContainer) pcontainer.getComponentInstanceOfType( 52 HibernateServiceContainer.class) ; 53 } 54 return hserviceContainer_; 55 } 56 57 } 58 | Popular Tags |