1 5 package org.exoplatform.services.portletcontainer.impl.portletAPIImp; 6 7 import java.io.IOException ; 8 9 import javax.portlet.PortletException; 10 import javax.portlet.PortletRequestDispatcher; 11 import javax.portlet.RenderRequest; 12 import javax.portlet.RenderResponse; 13 import javax.servlet.RequestDispatcher ; 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServletRequestWrapper ; 16 import javax.servlet.http.HttpServletResponseWrapper ; 17 18 import org.apache.commons.logging.Log; 19 import org.exoplatform.container.PortalContainer; 20 import org.exoplatform.services.log.LogService; 21 import org.exoplatform.services.portletcontainer.impl.PortletContainerConf; 22 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.helpers.CustomRequestWrapper; 23 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.helpers.CustomResponseWrapper; 24 25 32 public class PortletRequestDispatcherImp implements PortletRequestDispatcher { 33 34 private String path; 35 private RequestDispatcher dispatcher; 36 private Log log; 37 38 public PortletRequestDispatcherImp(RequestDispatcher dispatcher, String path) { 39 this.log = ((LogService)PortalContainer.getInstance().getComponentInstanceOfType(LogService.class)). 40 getLog("org.exoplatform.services.portletcontainer"); 41 this.dispatcher = dispatcher; 42 this.path = path; 43 } 44 45 public void include(RenderRequest request, RenderResponse response) 46 throws PortletException, IOException { 47 CustomRequestWrapper requestWrapper = null; 48 PortletContainerConf conf = (PortletContainerConf)PortalContainer.getInstance(). 49 getComponentInstanceOfType(PortletContainerConf.class); 50 boolean isSharedSessionEnable = conf.isSharedSessionEnable(); 51 try { 52 requestWrapper = 53 ((CustomRequestWrapper) ((HttpServletRequestWrapper )request).getRequest()); 54 CustomResponseWrapper responseWrapper = 55 (CustomResponseWrapper) ((HttpServletResponseWrapper )response).getResponse(); 56 57 request.setAttribute("javax.portlet.config",((RenderRequestImp)request).getPortletConfig()); 58 request.setAttribute("javax.portlet.request", request); 59 request.setAttribute("javax.portlet.response", response); 60 responseWrapper.flushBuffer(); 61 requestWrapper.setRedirected(true); 62 requestWrapper.setRedirectedPath(path); 63 if(isSharedSessionEnable){ 64 PortletSessionImp pS = (PortletSessionImp)request.getPortletSession(); 65 requestWrapper.setSharedSession(pS.getSession()); 66 } 67 requestWrapper.setContextPath(request.getContextPath()); 68 dispatcher.include(requestWrapper, responseWrapper); 69 } catch (ServletException e) { 70 log.error("Root cause of the exception", e.getRootCause()); 71 log.error("Problems occur when using PortletDispatcher", e); 72 throw new PortletException("Problems occur when using PortletDispatcher", e); 73 } finally { 74 request.removeAttribute("javax.portlet.config"); 75 request.removeAttribute("javax.portlet.request"); 76 request.removeAttribute("javax.portlet.response"); 77 if(requestWrapper != null) 78 requestWrapper.setRedirected(false); 79 if(isSharedSessionEnable){ 80 requestWrapper.setSharedSession(null); 81 } 82 } 83 } 84 } 85 | Popular Tags |