diff --git a/apps/portlet/src/main/webapp/WEB-INF/web.xml b/apps/portlet/src/main/webapp/WEB-INF/web.xml index 69a77575c..9c97aeb61 100644 --- a/apps/portlet/src/main/webapp/WEB-INF/web.xml +++ b/apps/portlet/src/main/webapp/WEB-INF/web.xml @@ -1,16 +1,13 @@ - - - + - - - - contextConfigLocation - /WEB-INF/applicationContext*.xml - + + + contextConfigLocation + + /WEB-INF/applicationContext*.xml + + Struts2 @@ -21,28 +18,11 @@ Struts2 /* + + + org.springframework.web.context.ContextLoaderListener + + - - org.springframework.web.context.ContextLoaderListener - - - - org.apache.struts2.portlet.context.ServletContextHolderListener - - - - preparator - org.apache.struts2.portlet.context.PreparatorServlet - - - - dwr - uk.ltd.getahead.dwr.DWRServlet - - - - dwr - /dwr/* - diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java deleted file mode 100644 index 42a9951a4..000000000 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.struts2.portlet.context; - -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.StrutsStatics; - -import com.opensymphony.xwork2.ActionContext; - -/** - * Since a portlet is not dispatched the same way as a servlet, the - * {@link org.apache.struts2.ServletActionContext} is not immediately available, as it - * depends on objects from the servlet API. However, the WW2 view implementations require access - * to the objects in the {@link org.apache.struts2.ServletActionContext}, and this servlet - * makes sure that these are available when the portlet actions are executing the render results. - * - */ -public class PreparatorServlet extends HttpServlet implements StrutsStatics { - - private static final long serialVersionUID = 1853399729352984089L; - - private final static Log LOG = LogFactory.getLog(PreparatorServlet.class); - - /** - * Prepares the {@link org.apache.struts2.ServletActionContext} with the - * {@link ServletContext}, {@link HttpServletRequest} and {@link HttpServletResponse}. - */ - public void service(HttpServletRequest servletRequest, - HttpServletResponse servletResponse) throws ServletException, - IOException { - LOG.debug("Preparing servlet objects for dispatch"); - ServletContext ctx = getServletContext(); - ActionContext.getContext().put(SERVLET_CONTEXT, ctx); - ActionContext.getContext().put(HTTP_REQUEST, servletRequest); - ActionContext.getContext().put(HTTP_RESPONSE, servletResponse); - LOG.debug("Preparation complete"); - } - -} diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java index 6baf0d5b3..976d3401f 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java @@ -180,20 +180,6 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC res.setTitle(title); } LOG.debug("Location: " + finalLocation); - PortletRequestDispatcher preparator = cfg.getPortletContext() - .getNamedDispatcher("preparator"); - if(preparator == null) { - throw new PortletException("Cannot look up 'preparator' servlet. Make sure that you" + - "have configured it correctly in the web.xml file."); - } - new IncludeTemplate() { - protected void when(PortletException e) { - LOG.error("PortletException while dispatching to 'preparator' servlet", e); - } - protected void when(IOException e) { - LOG.error("IOException while dispatching to 'preparator' servlet", e); - } - }.include(preparator, req, res); PortletRequestDispatcher dispatcher = cfg.getPortletContext().getRequestDispatcher(finalLocation); if(dispatcher == null) { throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'"); diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java index 899f02fe8..7d8f2f8b5 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java @@ -99,7 +99,6 @@ public class PortletVelocityResult extends StrutsResultSupport { private String defaultEncoding; private VelocityManager velocityManager; - public PortletVelocityResult() { super(); } @@ -160,7 +159,6 @@ public class PortletVelocityResult extends StrutsResultSupport { */ public void executeRenderResult(String finalLocation, ActionInvocation invocation) throws Exception { - prepareServletActionContext(); ValueStack stack = ActionContext.getContext().getValueStack(); HttpServletRequest request = ServletActionContext.getRequest(); @@ -192,7 +190,7 @@ public class PortletVelocityResult extends StrutsResultSupport { if (encoding != null) { contentType = contentType + ";charset=" + encoding; } - + response.setContentType(contentType); Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding); @@ -202,8 +200,6 @@ public class PortletVelocityResult extends StrutsResultSupport { Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding); - response.setContentType(contentType); - t.merge(context, writer); // always flush the writer (we used to only flush it if this was a @@ -293,15 +289,4 @@ public class PortletVelocityResult extends StrutsResultSupport { HttpServletResponse response, String location) { return velocityManager.createContext(stack, request, response); } - - /** - * Prepares the servlet action context for this request - */ - private void prepareServletActionContext() throws PortletException, - IOException { - PortletRequestDispatcher disp = PortletActionContext.getPortletConfig() - .getPortletContext().getNamedDispatcher("preparator"); - disp.include(PortletActionContext.getRenderRequest(), - PortletActionContext.getRenderResponse()); - } } diff --git a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java index 5063126b8..844620353 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java @@ -136,7 +136,6 @@ public class PortletFreemarkerResult extends StrutsResultSupport { private void executeRenderResult(String location, ActionInvocation invocation) throws TemplateException, IOException, TemplateModelException, PortletException { - prepareServletActionContext(); this.location = location; this.invocation = invocation; this.configuration = getConfiguration(); @@ -164,17 +163,6 @@ public class PortletFreemarkerResult extends StrutsResultSupport { } } - /** - * - */ - private void prepareServletActionContext() throws PortletException, - IOException { - PortletRequestDispatcher disp = PortletActionContext.getPortletConfig() - .getPortletContext().getNamedDispatcher("preparator"); - disp.include(PortletActionContext.getRenderRequest(), - PortletActionContext.getRenderResponse()); - } - /** * This method is called from {@link #doExecute(String, ActionInvocation)} * to obtain the FreeMarker configuration object that this result will use diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java deleted file mode 100644 index 6aa21eb78..000000000 --- a/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.struts2.portlet.context; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.StrutsTestCase; -import org.easymock.MockControl; - -/** - * - * Test for the {@link PreparatorServletTest} - * - */ -public class PreparatorServletTest extends StrutsTestCase { - - /** - * Test that the service method stores the request, response and servlet context - * in the {@link com.opensymphony.xwork2.ActionContext} - */ - public void testServiceHttpServletRequestHttpServletResponse() throws Exception { - MockControl mockRequest = MockControl.createNiceControl(HttpServletRequest.class); - MockControl mockResponse = MockControl.createNiceControl(HttpServletResponse.class); - MockControl mockContext = MockControl.createNiceControl(ServletContext.class); - MockControl mockConfig = MockControl.createNiceControl(ServletConfig.class); - - HttpServletRequest req = (HttpServletRequest)mockRequest.getMock(); - HttpServletResponse res = (HttpServletResponse)mockResponse.getMock(); - ServletContext context = (ServletContext)mockContext.getMock(); - ServletConfig config = (ServletConfig)mockConfig.getMock(); - - mockConfig.expectAndDefaultReturn(config.getServletContext(), context); - mockConfig.replay(); - - PreparatorServlet servlet = new PreparatorServlet(); - servlet.init(config); - servlet.service(req, res); - assertSame(req, ServletActionContext.getRequest()); - assertSame(res, ServletActionContext.getResponse()); - assertSame(context, ServletActionContext.getServletContext()); - - mockConfig.verify(); - } - -} diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java index da6949c68..9e5c753e6 100644 --- a/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java +++ b/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java @@ -80,7 +80,6 @@ public class PortletResultTest extends MockObjectTestCase implements PortletActi Mock mockRequest = mock(RenderRequest.class); Mock mockResponse = mock(RenderResponse.class); Mock mockRd = mock(PortletRequestDispatcher.class); - Mock mockPrep = mock(PortletRequestDispatcher.class); RenderRequest req = (RenderRequest)mockRequest.proxy(); RenderResponse res = (RenderResponse)mockResponse.proxy(); @@ -91,9 +90,7 @@ public class PortletResultTest extends MockObjectTestCase implements PortletActi Constraint[] params = new Constraint[]{same(req), same(res)}; mockRd.expects(once()).method("include").with(params); - mockPrep.expects(once()).method("include").with(params); mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd)); - mockCtx.expects(once()).method("getNamedDispatcher").with(eq("preparator")).will(returnValue(mockPrep.proxy())); mockResponse.expects(once()).method("setContentType").with(eq("text/html")); mockConfig.expects(once()).method("getPortletContext").will(returnValue(ctx)); @@ -207,7 +204,6 @@ public class PortletResultTest extends MockObjectTestCase implements PortletActi Mock mockRequest = mock(RenderRequest.class); Mock mockResponse = mock(RenderResponse.class); Mock mockRd = mock(PortletRequestDispatcher.class); - Mock mockPrep = mock(PortletRequestDispatcher.class); RenderRequest req = (RenderRequest)mockRequest.proxy(); RenderResponse res = (RenderResponse)mockResponse.proxy(); @@ -217,9 +213,7 @@ public class PortletResultTest extends MockObjectTestCase implements PortletActi Constraint[] params = new Constraint[]{same(req), same(res)}; mockRd.expects(once()).method("include").with(params); - mockPrep.expects(once()).method("include").with(params); mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd)); - mockCtx.expects(once()).method("getNamedDispatcher").with(eq("preparator")).will(returnValue(mockPrep.proxy())); mockConfig.expects(once()).method("getPortletContext").will(returnValue(ctx)); mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));