Search in sources :

Example 51 with Result

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);
}
Also used : HashMap(java.util.HashMap) StrutsMockHttpServletRequest(org.apache.struts2.views.jsp.StrutsMockHttpServletRequest) Result(com.opensymphony.xwork2.Result)

Example 52 with 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);
}
Also used : HashMap(java.util.HashMap) StrutsMockHttpServletRequest(org.apache.struts2.views.jsp.StrutsMockHttpServletRequest) Result(com.opensymphony.xwork2.Result)

Example 53 with 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);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) ActionProxy(com.opensymphony.xwork2.ActionProxy) ValueStack(com.opensymphony.xwork2.util.ValueStack) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) ServletActionContext(org.apache.struts2.ServletActionContext) ServletException(javax.servlet.ServletException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) StrutsException(org.apache.struts2.StrutsException) IOException(java.io.IOException) Result(com.opensymphony.xwork2.Result)

Example 54 with Result

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());
    }
}
Also used : Result(com.opensymphony.xwork2.Result)

Example 55 with Result

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);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) Result(com.walmartlabs.concord.plugins.s3.Result)

Aggregations

Test (org.junit.Test)46 Result (edu.stanford.CVC4.Result)35 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 Rational (edu.stanford.CVC4.Rational)25 Result (com.opensymphony.xwork2.Result)18 List (java.util.List)15 ArrayList (java.util.ArrayList)13 ArrayType (edu.stanford.CVC4.ArrayType)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 TimeUnit (java.util.concurrent.TimeUnit)8 DataSource (jdk.incubator.sql2.DataSource)8 Result (jdk.incubator.sql2.Result)8 Session (jdk.incubator.sql2.Session)8 AfterClass (org.junit.AfterClass)8 BeforeClass (org.junit.BeforeClass)8 BitVectorType (edu.stanford.CVC4.BitVectorType)6 SortType (edu.stanford.CVC4.SortType)6 Type (edu.stanford.CVC4.Type)6