mirror of
https://github.com/apache/struts.git
synced 2026-08-07 23:57:03 +00:00
WW-2101 Removed PreparatorServlet - Replaced by mock servlet implementation classes in org.apache.struts2.portlet.servlet
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@564599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
||||
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
<web-app id="StrutsPortlet">
|
||||
|
||||
<!-- Uncomment/comment this if you need/don't need Spring support -->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/applicationContext*.xml</param-value>
|
||||
</context-param>
|
||||
<!-- Uncomment/comment this if you need/don't need Spring support -->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
/WEB-INF/applicationContext*.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
<filter id="filterdispatcher">
|
||||
<filter-name>Struts2</filter-name>
|
||||
@@ -21,28 +18,11 @@
|
||||
<filter-name>Struts2</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<listener>
|
||||
<listener-class> org.springframework.web.context.ContextLoaderListener
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.apache.struts2.portlet.context.ServletContextHolderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet id="preparator">
|
||||
<servlet-name>preparator</servlet-name>
|
||||
<servlet-class>org.apache.struts2.portlet.context.PreparatorServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet id="dwr">
|
||||
<servlet-name>dwr</servlet-name>
|
||||
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>dwr</servlet-name>
|
||||
<url-pattern>/dwr/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
||||
-66
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 + "'");
|
||||
|
||||
+1
-16
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
-12
@@ -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
|
||||
|
||||
-67
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user