1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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_APP =
45          "com.liferay.portal.model.PortletApp";
46  
47      public static final String PORTLET_CLASS_LOADER = "PORTLET_CLASS_LOADER";
48  
49      public static final String PORTLET_SERVLET_CONFIG =
50          "com.liferay.portal.kernel.servlet.PortletServletConfig";
51  
52      public static final String PORTLET_SERVLET_FILTER_CHAIN =
53          "com.liferay.portal.kernel.servlet.PortletServletFilterChain";
54  
55      public static final String PORTLET_SERVLET_REQUEST =
56          "com.liferay.portal.kernel.servlet.PortletServletRequest";
57  
58      public static final String PORTLET_SERVLET_RESPONSE =
59          "com.liferay.portal.kernel.servlet.PortletServletResponse";
60  
61      public void service(
62              HttpServletRequest request, HttpServletResponse response)
63          throws IOException, ServletException {
64  
65          String portletId = (String)request.getAttribute(WebKeys.PORTLET_ID);
66  
67          PortletRequest portletRequest = (PortletRequest)request.getAttribute(
68              JavaConstants.JAVAX_PORTLET_REQUEST);
69  
70          PortletResponse portletResponse = (PortletResponse)request.getAttribute(
71              JavaConstants.JAVAX_PORTLET_RESPONSE);
72  
73          String lifecycle = (String)request.getAttribute(
74              PortletRequest.LIFECYCLE_PHASE);
75  
76          FilterChain filterChain = (FilterChain)request.getAttribute(
77              PORTLET_SERVLET_FILTER_CHAIN);
78  
79          LiferayPortletSession portletSession =
80              (LiferayPortletSession)portletRequest.getPortletSession();
81  
82          portletRequest.setAttribute(WebKeys.PORTLET_ID, portletId);
83          portletRequest.setAttribute(PORTLET_SERVLET_CONFIG, getServletConfig());
84          portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
85          portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
86  
87          HttpSession session = request.getSession();
88  
89          PortletSessionTracker.add(session);
90  
91          portletSession.setHttpSession(session);
92  
93          try {
94              PortletFilterUtil.doFilter(
95                  portletRequest, portletResponse, lifecycle, filterChain);
96          }
97          catch (PortletException pe) {
98              _log.error(pe, pe);
99  
100             throw new ServletException(pe);
101         }
102     }
103 
104     private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
105 
106 }