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
31 import java.io.IOException;
32
33 import javax.portlet.PortletException;
34 import javax.portlet.PortletRequest;
35 import javax.portlet.PortletResponse;
36 import javax.portlet.filter.FilterChain;
37
38 import javax.servlet.ServletException;
39 import javax.servlet.http.HttpServlet;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42 import javax.servlet.http.HttpSession;
43
44
50 public class PortletServlet extends HttpServlet {
51
52 public static final String PORTLET_CLASS_LOADER = "PORTLET_CLASS_LOADER";
53
54 public static final String PORTLET_SERVLET_CONFIG =
55 "com.liferay.portal.kernel.servlet.PortletServletConfig";
56
57 public static final String PORTLET_SERVLET_FILTER_CHAIN =
58 "com.liferay.portal.kernel.servlet.PortletServletFilterChain";
59
60 public static final String PORTLET_SERVLET_REQUEST =
61 "com.liferay.portal.kernel.servlet.PortletServletRequest";
62
63 public static final String PORTLET_SERVLET_RESPONSE =
64 "com.liferay.portal.kernel.servlet.PortletServletResponse";
65
66 public void service(
67 HttpServletRequest request, HttpServletResponse response)
68 throws IOException, ServletException {
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(PORTLET_SERVLET_CONFIG, getServletConfig());
86 portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
87 portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
88
89 HttpSession session = request.getSession();
90
91 PortletSessionTracker.add(session);
92
93 portletSession.setHttpSession(session);
94
95 try {
96 PortletFilterUtil.doFilter(
97 portletRequest, portletResponse, lifecycle, filterChain);
98 }
99 catch (PortletException pe) {
100 _log.error(pe, pe);
101
102 throw new ServletException(pe);
103 }
104 }
105
106 private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
107
108 }