1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.servlet;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.portlet.LiferayPortletSession;
20  import com.liferay.portal.kernel.portlet.PortletFilterUtil;
21  import com.liferay.portal.kernel.util.JavaConstants;
22  import com.liferay.portal.kernel.util.WebKeys;
23  
24  import java.io.IOException;
25  
26  import javax.portlet.PortletException;
27  import javax.portlet.PortletRequest;
28  import javax.portlet.PortletResponse;
29  import javax.portlet.filter.FilterChain;
30  
31  import javax.servlet.ServletException;
32  import javax.servlet.http.HttpServlet;
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  import javax.servlet.http.HttpSession;
36  
37  /**
38   * <a href="PortletServlet.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class PortletServlet extends HttpServlet {
43  
44      public static final String PORTLET_CLASS_LOADER = "PORTLET_CLASS_LOADER";
45  
46      public static final String PORTLET_SERVLET_CONFIG =
47          "com.liferay.portal.kernel.servlet.PortletServletConfig";
48  
49      public static final String PORTLET_SERVLET_FILTER_CHAIN =
50          "com.liferay.portal.kernel.servlet.PortletServletFilterChain";
51  
52      public static final String PORTLET_SERVLET_REQUEST =
53          "com.liferay.portal.kernel.servlet.PortletServletRequest";
54  
55      public static final String PORTLET_SERVLET_RESPONSE =
56          "com.liferay.portal.kernel.servlet.PortletServletResponse";
57  
58      public void service(
59              HttpServletRequest request, HttpServletResponse response)
60          throws IOException, ServletException {
61  
62          String portletId = (String)request.getAttribute(WebKeys.PORTLET_ID);
63  
64          PortletRequest portletRequest = (PortletRequest)request.getAttribute(
65              JavaConstants.JAVAX_PORTLET_REQUEST);
66  
67          PortletResponse portletResponse = (PortletResponse)request.getAttribute(
68              JavaConstants.JAVAX_PORTLET_RESPONSE);
69  
70          String lifecycle = (String)request.getAttribute(
71              PortletRequest.LIFECYCLE_PHASE);
72  
73          FilterChain filterChain = (FilterChain)request.getAttribute(
74              PORTLET_SERVLET_FILTER_CHAIN);
75  
76          LiferayPortletSession portletSession =
77              (LiferayPortletSession)portletRequest.getPortletSession();
78  
79          portletRequest.setAttribute(WebKeys.PORTLET_ID, portletId);
80          portletRequest.setAttribute(PORTLET_SERVLET_CONFIG, getServletConfig());
81          portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
82          portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
83  
84          HttpSession session = request.getSession();
85  
86          PortletSessionTracker.add(session);
87  
88          portletSession.setHttpSession(session);
89  
90          try {
91              PortletFilterUtil.doFilter(
92                  portletRequest, portletResponse, lifecycle, filterChain);
93          }
94          catch (PortletException pe) {
95              _log.error(pe, pe);
96  
97              throw new ServletException(pe);
98          }
99      }
100 
101     private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
102 
103 }