use of com.walmartlabs.concord.plugins.s3.Result in project struts by apache.
the class DefaultActionMapperTest method testRedirectPrefix.
public void testRedirectPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirect:" + "http://www.google.com", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
request.setupGetServletPath("/someServletPath.action");
request.setParameterMap(parameterMap);
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
defaultActionMapper.setContainer(container);
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
Result result = actionMapping.getResult();
assertNull(result);
}
use of com.walmartlabs.concord.plugins.s3.Result in project struts by apache.
the class DefaultActionMapperTest method testUnsafeRedirectPrefix.
public void testUnsafeRedirectPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirect:" + "http://%{3*4}", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
request.setupGetServletPath("/someServletPath.action");
request.setParameterMap(parameterMap);
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
defaultActionMapper.setContainer(container);
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
Result result = actionMapping.getResult();
assertNull(result);
}
use of com.walmartlabs.concord.plugins.s3.Result in project struts by apache.
the class Dispatcher method serviceAction.
/**
* <p>
* Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result.
* </p>
*
* <p>
* This method first creates the action context from the given parameters,
* and then loads an <tt>ActionProxy</tt> from the given action name and namespace.
* After that, the Action method is executed and output channels through the response object.
* Actions not found are sent back to the user via the {@link Dispatcher#sendError} method,
* using the 404 return code.
* All other errors are reported by throwing a ServletException.
* </p>
*
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @param mapping the action mapping object
* @throws ServletException when an unknown error occurs (not a 404, but typically something that
* would end up as a 5xx by the servlet container)
* @since 2.3.17
*/
public void serviceAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
Map<String, Object> extraContext = createContextMap(request, response, mapping);
// If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
boolean nullStack = stack == null;
if (nullStack) {
ActionContext ctx = ActionContext.getContext();
if (ctx != null) {
stack = ctx.getValueStack();
}
}
if (stack != null) {
extraContext = ActionContext.of(extraContext).withValueStack(valueStackFactory.createValueStack(stack)).getContextMap();
}
try {
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();
ActionProxy proxy;
// check if we are probably in an async resuming
ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
if (invocation == null || invocation.isExecuted()) {
proxy = getContainer().getInstance(ActionProxyFactory.class).createActionProxy(namespace, name, method, extraContext, true, false);
} else {
proxy = invocation.getProxy();
}
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());
// if the ActionMapping says to go straight to a result, do it!
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
proxy.execute();
}
// If there was a previous value stack then set it back onto the request
if (!nullStack) {
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
}
} catch (ConfigurationException e) {
logConfigurationException(request, e);
sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
if (handleException || devMode) {
if (devMode) {
LOG.debug("Dispatcher serviceAction failed", e);
}
sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
} else {
throw new ServletException(e);
}
}
}
use of com.walmartlabs.concord.plugins.s3.Result in project struts by apache.
the class JSONResultTest method testPassingNullInvocation.
public void testPassingNullInvocation() throws Exception {
Result result = new JSONResult();
try {
result.execute(null);
fail("Exception should be thrown!");
} catch (IllegalArgumentException e) {
assertEquals("Invocation cannot be null!", e.getMessage());
}
}
use of com.walmartlabs.concord.plugins.s3.Result in project concord-plugins by walmartlabs.
the class S3TaskV2 method execute.
@Override
@SuppressWarnings("unchecked")
public TaskResult execute(Variables input) throws Exception {
Result result = delegate.execute(TaskParams.of(input, context.defaultVariables().toMap()));
ObjectMapper om = new ObjectMapper();
Map<String, Object> r = om.convertValue(result, Map.class);
return TaskResult.of(MapUtils.getBoolean(r, "ok", false), MapUtils.getString(r, "error")).values(r);
}
Aggregations