1
19
20 package com.liferay.portal.kernel.servlet;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.portlet.LiferayPortletSession;
25 import com.liferay.portal.kernel.portlet.PortletFilterUtil;
26 import com.liferay.portal.kernel.util.JavaConstants;
27 import com.liferay.portal.kernel.util.WebKeys;
28
29 import java.io.IOException;
30
31 import javax.portlet.PortletException;
32 import javax.portlet.PortletRequest;
33 import javax.portlet.PortletResponse;
34 import javax.portlet.filter.FilterChain;
35
36 import javax.servlet.ServletException;
37 import javax.servlet.http.HttpServlet;
38 import javax.servlet.http.HttpServletRequest;
39 import javax.servlet.http.HttpServletResponse;
40 import javax.servlet.http.HttpSession;
41
42
48 public class PortletServlet extends HttpServlet {
49
50 public static final String PORTLET_CLASS_LOADER = "PORTLET_CLASS_LOADER";
51
52 public static final String PORTLET_SERVLET_CONFIG =
53 "com.liferay.portal.kernel.servlet.PortletServletConfig";
54
55 public static final String PORTLET_SERVLET_FILTER_CHAIN =
56 "com.liferay.portal.kernel.servlet.PortletServletFilterChain";
57
58 public static final String PORTLET_SERVLET_REQUEST =
59 "com.liferay.portal.kernel.servlet.PortletServletRequest";
60
61 public static final String PORTLET_SERVLET_RESPONSE =
62 "com.liferay.portal.kernel.servlet.PortletServletResponse";
63
64 public void service(
65 HttpServletRequest request, HttpServletResponse response)
66 throws IOException, ServletException {
67
68 String portletId = (String)request.getAttribute(WebKeys.PORTLET_ID);
69
70 PortletRequest portletRequest = (PortletRequest)request.getAttribute(
71 JavaConstants.JAVAX_PORTLET_REQUEST);
72
73 PortletResponse portletResponse = (PortletResponse)request.getAttribute(
74 JavaConstants.JAVAX_PORTLET_RESPONSE);
75
76 String lifecycle = (String)request.getAttribute(
77 PortletRequest.LIFECYCLE_PHASE);
78
79 FilterChain filterChain = (FilterChain)request.getAttribute(
80 PORTLET_SERVLET_FILTER_CHAIN);
81
82 LiferayPortletSession portletSession =
83 (LiferayPortletSession)portletRequest.getPortletSession();
84
85 portletRequest.setAttribute(WebKeys.PORTLET_ID, portletId);
86 portletRequest.setAttribute(PORTLET_SERVLET_CONFIG, getServletConfig());
87 portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
88 portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
89
90 HttpSession session = request.getSession();
91
92 PortletSessionTracker.add(session);
93
94 portletSession.setHttpSession(session);
95
96 try {
97 PortletFilterUtil.doFilter(
98 portletRequest, portletResponse, lifecycle, filterChain);
99 }
100 catch (PortletException pe) {
101 _log.error(pe, pe);
102
103 throw new ServletException(pe);
104 }
105 }
106
107 private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
108
109 }