001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.portlet.LiferayPortletSession;
020 import com.liferay.portal.kernel.portlet.PortletFilterUtil;
021 import com.liferay.portal.kernel.util.JavaConstants;
022 import com.liferay.portal.kernel.util.WebKeys;
023
024 import java.io.IOException;
025
026 import javax.portlet.PortletException;
027 import javax.portlet.PortletRequest;
028 import javax.portlet.PortletResponse;
029 import javax.portlet.filter.FilterChain;
030
031 import javax.servlet.ServletException;
032 import javax.servlet.http.HttpServlet;
033 import javax.servlet.http.HttpServletRequest;
034 import javax.servlet.http.HttpServletResponse;
035 import javax.servlet.http.HttpSession;
036
037
040 public class PortletServlet extends HttpServlet {
041
042 public static final String PORTLET_APP =
043 "com.liferay.portal.model.PortletApp";
044
045
048 public static final String PORTLET_CLASS_LOADER =
049 PluginContextListener.PLUGIN_CLASS_LOADER;
050
051 public static final String PORTLET_SERVLET_CONFIG =
052 "com.liferay.portal.kernel.servlet.PortletServletConfig";
053
054 public static final String PORTLET_SERVLET_FILTER_CHAIN =
055 "com.liferay.portal.kernel.servlet.PortletServletFilterChain";
056
057 public static final String PORTLET_SERVLET_REQUEST =
058 "com.liferay.portal.kernel.servlet.PortletServletRequest";
059
060 public static final String PORTLET_SERVLET_RESPONSE =
061 "com.liferay.portal.kernel.servlet.PortletServletResponse";
062
063 @Override
064 public void service(
065 HttpServletRequest request, HttpServletResponse response)
066 throws IOException, ServletException {
067
068 if (request.getAttribute(WebKeys.EXTEND_SESSION) != null) {
069 request.removeAttribute(WebKeys.EXTEND_SESSION);
070
071 HttpSession session = request.getSession(false);
072
073 if (session != null) {
074 session.setAttribute(WebKeys.EXTEND_SESSION, Boolean.TRUE);
075
076 session.removeAttribute(WebKeys.EXTEND_SESSION);
077 }
078
079 return;
080 }
081
082 String portletId = (String)request.getAttribute(WebKeys.PORTLET_ID);
083
084 PortletRequest portletRequest = (PortletRequest)request.getAttribute(
085 JavaConstants.JAVAX_PORTLET_REQUEST);
086
087 PortletResponse portletResponse = (PortletResponse)request.getAttribute(
088 JavaConstants.JAVAX_PORTLET_RESPONSE);
089
090 String lifecycle = (String)request.getAttribute(
091 PortletRequest.LIFECYCLE_PHASE);
092
093 FilterChain filterChain = (FilterChain)request.getAttribute(
094 PORTLET_SERVLET_FILTER_CHAIN);
095
096 LiferayPortletSession portletSession =
097 (LiferayPortletSession)portletRequest.getPortletSession();
098
099 portletRequest.setAttribute(WebKeys.PORTLET_ID, portletId);
100 portletRequest.setAttribute(PORTLET_SERVLET_CONFIG, getServletConfig());
101 portletRequest.setAttribute(PORTLET_SERVLET_REQUEST, request);
102 portletRequest.setAttribute(PORTLET_SERVLET_RESPONSE, response);
103
104 HttpSession session = request.getSession();
105
106 PortletSessionTracker.add(session);
107
108 portletSession.setHttpSession(session);
109
110 try {
111 PortletFilterUtil.doFilter(
112 portletRequest, portletResponse, lifecycle, filterChain);
113 }
114 catch (PortletException pe) {
115 _log.error(pe, pe);
116
117 throw new ServletException(pe);
118 }
119 }
120
121 private static Log _log = LogFactoryUtil.getLog(PortletServlet.class);
122
123 }