KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > portletAPIImp > PortletRequestDispatcherImp


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.services.portletcontainer.impl.portletAPIImp;
6
7 import java.io.IOException JavaDoc;
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 JavaDoc;
14 import javax.servlet.ServletException JavaDoc;
15 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
16 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
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 /**
26  * Created by The eXo Platform SARL
27  * Author : Mestrallet Benjamin
28  * benjmestrallet@users.sourceforge.net
29  * Date: Jul 25, 2003
30  * Time: 6:46:52 PM
31  */

32 public class PortletRequestDispatcherImp implements PortletRequestDispatcher {
33
34   private String JavaDoc path;
35   private RequestDispatcher dispatcher;
36   private Log log;
37
38   public PortletRequestDispatcherImp(RequestDispatcher dispatcher, String JavaDoc 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 JavaDoc {
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 JavaDoc)request).getRequest());
54       CustomResponseWrapper responseWrapper =
55         (CustomResponseWrapper) ((HttpServletResponseWrapper JavaDoc)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 JavaDoc 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