Skip to content

Commit

Permalink
Updates classes to use the new version of Dispatcher's methods withou…
Browse files Browse the repository at this point in the history
…t ServletContext
  • Loading branch information
lukaszlenart committed Feb 17, 2014
1 parent 9ff04d1 commit 4da2ec6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;

import uk.ltd.getahead.dwr.WebContextFactory;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.DefaultActionInvocation;
import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.ValidationAwareSupport;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;

Expand All @@ -69,8 +63,9 @@
* </pre>
*/
public class DWRValidator {

private static final Logger LOG = LoggerFactory.getLogger(DWRValidator.class);

public ValidationAwareSupport doPost(String namespace, String actionName, Map params) throws Exception {
HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
ServletContext servletContext = WebContextFactory.get().getServletContext();
Expand All @@ -91,8 +86,7 @@ public ValidationAwareSupport doPost(String namespace, String actionName, Map pa
session,
application,
req,
res,
servletContext);
res);

try {
ActionProxyFactory actionProxyFactory = du.getContainer().getInstance(ActionProxyFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
private Dispatcher dispatcherUtils;
private ActionMapper actionMapper;
private Container container;
private ServletContext servletContext;

/**
* Initialize the portlet with the init parameters from <tt>portlet.xml</tt>
Expand All @@ -201,7 +202,8 @@ public void init(PortletConfig cfg) throws PortletException {
params.put(name, value);
}

dispatcherUtils = new Dispatcher(new PortletServletContext(cfg.getPortletContext()), params);
servletContext = new PortletServletContext(cfg.getPortletContext());
dispatcherUtils = new Dispatcher(servletContext, params);
dispatcherUtils.init();

// For testability
Expand Down Expand Up @@ -428,11 +430,10 @@ public void serviceAction(PortletRequest request, PortletResponse response, Map<
String actionName = null;
String namespace;
try {
ServletContext servletContext = new PortletServletContext(getPortletContext());
HttpServletRequest servletRequest = new PortletServletRequest(request, getPortletContext());
HttpServletResponse servletResponse = createPortletServletResponse(response);
if (phase.isAction()) {
servletRequest = dispatcherUtils.wrapRequest(servletRequest, servletContext);
servletRequest = dispatcherUtils.wrapRequest(servletRequest);
if (servletRequest instanceof MultiPartRequestWrapper) {
// Multipart request. Request parameters are encoded in the multipart data,
// so we need to manually add them to the parameter map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected void render(Content content, HttpServletRequest request, HttpServletRe
if (ctx == null) {
// ok, one isn't associated with the request, so let's create one using the current Dispatcher
ValueStack vs = Dispatcher.getInstance().getContainer().getInstance(ValueStackFactory.class).createValueStack();
vs.getContext().putAll(Dispatcher.getInstance().createContextMap(request, response, null, servletContext));
vs.getContext().putAll(Dispatcher.getInstance().createContextMap(request, response, null));
ctx = new ActionContext(vs.getContext());
if (ctx.getActionInvocation() == null) {
// put in a dummy ActionSupport so basic functionality still works
Expand Down

0 comments on commit 4da2ec6

Please sign in to comment.