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