View Javadoc

1   /*
2    * $Id: PreparatorServlet.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }