mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-4789 WW-3788 ActionContext refactoring
This commit is contained in:
@@ -44,8 +44,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -140,7 +138,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
actionContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
|
||||
initSession(actionContext);
|
||||
// set the action context to the one used by the proxy
|
||||
ActionContext.setContext(actionContext);
|
||||
ActionContext.bound(actionContext);
|
||||
}
|
||||
|
||||
protected void initSession(ActionContext actionContext) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
@@ -48,8 +47,7 @@ public class StrutsRestTestCase<T> extends StrutsJUnit4TestCase<T> {
|
||||
*
|
||||
* @param uri action uri to test
|
||||
* @return execution result
|
||||
*
|
||||
* @throws ServletException in case of servlet errors
|
||||
* @throws ServletException in case of servlet errors
|
||||
* @throws UnsupportedEncodingException in case of unsupported encoding
|
||||
*/
|
||||
@Override
|
||||
@@ -64,10 +62,9 @@ public class StrutsRestTestCase<T> extends StrutsJUnit4TestCase<T> {
|
||||
* FreeMarker, or Velocity (JSPs can be used with the Embedded JSP plugin)
|
||||
*
|
||||
* @param httpMethod HTTP method of request like GET, POST, PUT or DELETE
|
||||
* @param uri action uri to test
|
||||
* @param uri action uri to test
|
||||
* @return execution result
|
||||
*
|
||||
* @throws ServletException in case of servlet errors
|
||||
* @throws ServletException in case of servlet errors
|
||||
* @throws UnsupportedEncodingException in case of unsupported encoding
|
||||
*/
|
||||
protected String executeAction(String httpMethod, String uri) throws ServletException, UnsupportedEncodingException {
|
||||
@@ -81,7 +78,7 @@ public class StrutsRestTestCase<T> extends StrutsJUnit4TestCase<T> {
|
||||
|
||||
if (response.getStatus() != HttpServletResponse.SC_OK)
|
||||
throw new ServletException("Error code [" + response.getStatus() + "], Error: ["
|
||||
+ response.getErrorMessage() + "]");
|
||||
+ response.getErrorMessage() + "]");
|
||||
|
||||
return response.getContentAsString();
|
||||
}
|
||||
@@ -104,41 +101,38 @@ public class StrutsRestTestCase<T> extends StrutsJUnit4TestCase<T> {
|
||||
* parameters. Make sure to set the request parameters in the protected "request" object before calling this method.
|
||||
*
|
||||
* @param httpMethod HTTP method of request like GET, POST, PUT or DELETE
|
||||
* @param uri request uri to test
|
||||
* @param uri request uri to test
|
||||
* @return action proxy found for this request uri
|
||||
*/
|
||||
protected ActionProxy getActionProxy(String httpMethod, String uri) {
|
||||
request.setRequestURI(uri);
|
||||
request.setMethod(httpMethod);
|
||||
request.setRequestURI(uri);
|
||||
request.setMethod(httpMethod);
|
||||
|
||||
ActionMapping mapping = getActionMapping(request);
|
||||
String namespace = mapping.getNamespace();
|
||||
String name = mapping.getName();
|
||||
String method = mapping.getMethod();
|
||||
ActionMapping mapping = getActionMapping(request);
|
||||
String namespace = mapping.getNamespace();
|
||||
String name = mapping.getName();
|
||||
String method = mapping.getMethod();
|
||||
|
||||
Configuration config = configurationManager.getConfiguration();
|
||||
ActionProxy proxy = config.getContainer()
|
||||
.getInstance(ActionProxyFactory.class)
|
||||
.createActionProxy(namespace, name, method, new HashMap<String, Object>(), true, false);
|
||||
Configuration config = configurationManager.getConfiguration();
|
||||
ActionProxy proxy = config.getContainer()
|
||||
.getInstance(ActionProxyFactory.class)
|
||||
.createActionProxy(namespace, name, method, new HashMap<>(), true, false);
|
||||
|
||||
ActionContext invocationContext = proxy.getInvocation().getInvocationContext();
|
||||
invocationContext.getContextMap().put(ServletActionContext.ACTION_MAPPING, mapping);
|
||||
invocationContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
|
||||
// set the action context to the one used by the proxy
|
||||
ActionContext.setContext(invocationContext);
|
||||
|
||||
// set the action context to the one used by the proxy
|
||||
ActionContext.setContext(invocationContext);
|
||||
ActionContext.bound(invocationContext);
|
||||
|
||||
// this is normally done in onSetUp(), but we are using Struts internal
|
||||
// objects (proxy and action invocation)
|
||||
// so we have to hack around so it works
|
||||
ServletActionContext.setServletContext(servletContext);
|
||||
ServletActionContext.setRequest(request);
|
||||
ServletActionContext.setResponse(response);
|
||||
ServletActionContext.setServletContext(servletContext);
|
||||
ServletActionContext.setRequest(request);
|
||||
ServletActionContext.setResponse(response);
|
||||
|
||||
return proxy;
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initServletMockObjects() {
|
||||
|
||||
@@ -39,8 +39,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -124,7 +122,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
initSession(actionContext);
|
||||
applyAdditionalParams(actionContext);
|
||||
// set the action context to the one used by the proxy
|
||||
ActionContext.setContext(actionContext);
|
||||
ActionContext.bound(actionContext);
|
||||
}
|
||||
|
||||
protected void initSession(ActionContext actionContext) {
|
||||
|
||||
Reference in New Issue
Block a user