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
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 String portletId = (String)request.getAttribute(WebKeys.PORTLET_ID);
71
72 PortletRequest portletRequest = (PortletRequest)request.getAttribute(
73 JavaConstants.JAVAX_PORTLET_REQUEST);
74
75 PortletResponse portletResponse = (PortletResponse)request.getAttribute(
76 JavaConstants.JAVAX_PORTLET_RESPONSE);
77
78 String lifecycle = (String)request.getAttribute(
79 PortletRequest.LIFECYCLE_PHASE);
80
81 FilterChain filterChain = (FilterChain)request.getAttribute(
82 PORTLET_SERVLET_FILTER_CHAIN);
83
84 LiferayPortletSession portletSession =
85 (LiferayPortletSession)portletRequest.getPortletSession();
86
87 portletRequest.setAttribute(WebKeys.PORTLET_ID, portletId);
88 portletRequest.setAttribute(PORTLET_SERVLET_CONFIG, getServletConfig());
89 portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
90 portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
91
92 HttpSession session = request.getSession();
93
94 PortletSessionTracker.add(session);
95
96 portletSession.setHttpSession(session);
97
98 try {
99 PortletFilterUtil.doFilter(
100 portletRequest, portletResponse, lifecycle, filterChain);
101 }
102 catch (PortletException pe) {
103 _log.error(pe, pe);
104
105 throw new ServletException(pe);
106 }
107 }
108
109 private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
110
111 }