1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.portlet.context;
19
20 import java.io.IOException;
21
22 import javax.servlet.ServletContext;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts2.StrutsStatics;
31
32 import com.opensymphony.xwork2.ActionContext;
33
34 /***
35 * Since a portlet is not dispatched the same way as a servlet, the
36 * {@link org.apache.struts2.ServletActionContext} is not immediately available, as it
37 * depends on objects from the servlet API. However, the WW2 view implementations require access
38 * to the objects in the {@link org.apache.struts2.ServletActionContext}, and this servlet
39 * makes sure that these are available when the portlet actions are executing the render results.
40 *
41 */
42 public class PreparatorServlet extends HttpServlet implements StrutsStatics {
43
44 private static final long serialVersionUID = 1853399729352984089L;
45
46 private final static Log LOG = LogFactory.getLog(PreparatorServlet.class);
47
48 /***
49 * Prepares the {@link org.apache.struts2.ServletActionContext} with the
50 * {@link ServletContext}, {@link HttpServletRequest} and {@link HttpServletResponse}.
51 */
52 public void service(HttpServletRequest servletRequest,
53 HttpServletResponse servletResponse) throws ServletException,
54 IOException {
55 LOG.debug("Preparing servlet objects for dispatch");
56 ServletContext ctx = getServletContext();
57 ActionContext.getContext().put(SERVLET_CONTEXT, ctx);
58 ActionContext.getContext().put(HTTP_REQUEST, servletRequest);
59 ActionContext.getContext().put(HTTP_RESPONSE, servletResponse);
60 LOG.debug("Preparation complete");
61 }
62
63 }