Search in sources :

Example 21 with Result

use of com.opensymphony.xwork2.Result in project struts-examples by apache.

the class OrderControllerTest method testDelete.

@Test
public void testDelete() throws Exception {
    request.setParameter("request_locale", "en");
    ActionProxy proxy = getActionProxy("DELETE", "/data/order/3.json");
    String result = proxy.execute();
    assertThat(result, nullValue());
    assertThat(ServletActionContext.getResponse().getContentType(), is(equalTo("application/json;charset=UTF-8")));
    String jsonResult = ((MockHttpServletResponse) ServletActionContext.getResponse()).getContentAsString();
    assertThat(JsonPath.read(jsonResult, "$.actionError"), is(equalTo("Delete is currently not supported!")));
    assertThat(ServletActionContext.getResponse().getStatus(), is(equalTo(400)));
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 22 with Result

use of com.opensymphony.xwork2.Result in project struts-examples by apache.

the class IndexAction method execute.

public Result execute() {
    return (Result) invocation -> {
        HttpServletResponse response = ServletActionContext.getResponse();
        response.getWriter().println("Hello!");
    };
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Result(com.opensymphony.xwork2.Result)

Example 23 with Result

use of com.opensymphony.xwork2.Result in project geotoolkit by Geomatys.

the class WPS2Process method fillOutputs.

/**
 * Fill {@link ParameterValueGroup parameters} of the process using the WPS
 * {@link ExecuteResponse response}.
 *
 * @throws ProcessException if data conversion fails.
 */
private void fillOutputs(Object response) throws ProcessException {
    try {
        if (response == null) {
            // request the result from the server
            final GetResultRequest request = registry.getClient().createGetResult(jobId);
            request.setDebug(debug);
            request.setClientSecurity(security);
            response = request.getResponse();
        }
        if (response instanceof Result) {
            final Result result = (Result) response;
            for (DataOutput out : result.getOutput()) {
                fillOutputs(outputParameters, out);
            }
        } else if (response instanceof ExceptionResponse) {
            final ExceptionResponse report = (ExceptionResponse) response;
            throw new ProcessException("Exception when getting process result.", this, report.toException());
        }
    } catch (JAXBException ex) {
        Logger.getLogger(WPS2Process.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(WPS2Process.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) GetResultRequest(org.geotoolkit.wps.client.GetResultRequest) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) ExceptionResponse(org.geotoolkit.ows.xml.ExceptionResponse) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) Result(org.geotoolkit.wps.xml.v200.Result)

Example 24 with Result

use of com.opensymphony.xwork2.Result in project geotoolkit by Geomatys.

the class WPS2Process method execute.

@Override
protected void execute() throws ProcessException {
    final Result result;
    try {
        if (jobId != null) {
            try {
                // It's an already running process we've got here. All we have to do
                // is checking its status, to ensure/wait its completion.
                result = checkResult(getStatus());
            } catch (JAXBException | IOException ex) {
                throw new ProcessException("Cannot get process status", this, ex);
            }
        } else {
            final ExecuteRequest exec = createRequest();
            exec.setDebug(debug);
            exec.setClientSecurity(security);
            result = sendExecuteRequest(exec);
        }
    } catch (InterruptedException e) {
        throw new DismissProcessException("Process interrupted while executing", this, e);
    }
    if (!isDimissed()) {
        fillOutputs(result);
    }
}
Also used : ExecuteRequest(org.geotoolkit.wps.client.ExecuteRequest) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) DismissProcessException(org.geotoolkit.process.DismissProcessException) Result(org.geotoolkit.wps.xml.v200.Result)

Example 25 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class InterceptorBuilder method constructParameterizedInterceptorReferences.

/**
 * Builds a list of interceptors referenced by the refName in the supplied PackageConfig overriding the properties
 * of the referenced interceptor with refParams.
 *
 * @param interceptorLocator interceptor locator
 * @param stackConfig interceptor stack configuration
 * @param refParams The overridden interceptor properties
 * @return list of interceptors referenced by the refName in the supplied PackageConfig overridden with refParams.
 */
private static List<InterceptorMapping> constructParameterizedInterceptorReferences(InterceptorLocator interceptorLocator, InterceptorStackConfig stackConfig, Map<String, String> refParams, ObjectFactory objectFactory) {
    List<InterceptorMapping> result;
    Map<String, Map<String, String>> params = new LinkedHashMap<>();
    /*
         * We strip
         *
         * <interceptor-ref name="someStack">
         *    <param name="interceptor1.param1">someValue</param>
         *    <param name="interceptor1.param2">anotherValue</param>
         * </interceptor-ref>
         *
         * down to map
         *  interceptor1 -> [param1 -> someValue, param2 -> anotherValue]
         *
         * or
         * <interceptor-ref name="someStack">
         *    <param name="interceptorStack1.interceptor1.param1">someValue</param>
         *    <param name="interceptorStack1.interceptor1.param2">anotherValue</param>
         * </interceptor-ref>
         *
         * down to map
         *  interceptorStack1 -> [interceptor1.param1 -> someValue, interceptor1.param2 -> anotherValue]
         *
         */
    for (Map.Entry<String, String> entry : refParams.entrySet()) {
        String key = entry.getKey();
        try {
            String name = key.substring(0, key.indexOf('.'));
            key = key.substring(key.indexOf('.') + 1);
            Map<String, String> map;
            if (params.containsKey(name)) {
                map = params.get(name);
            } else {
                map = new LinkedHashMap<>();
            }
            map.put(key, entry.getValue());
            params.put(name, map);
        } catch (Exception e) {
            LOG.warn("No interceptor found for name = {}", key);
        }
    }
    result = new ArrayList<>(stackConfig.getInterceptors());
    for (Map.Entry<String, Map<String, String>> entry : params.entrySet()) {
        String key = entry.getKey();
        Map<String, String> map = entry.getValue();
        Object interceptorCfgObj = interceptorLocator.getInterceptorConfig(key);
        /*
             * Now we attempt to separate out param that refers to Interceptor
             * and Interceptor stack, eg.
             *
             * <interceptor-ref name="someStack">
             *    <param name="interceptor1.param1">someValue</param>
             *    ...
             * </interceptor-ref>
             *
             *  vs
             *
             *  <interceptor-ref name="someStack">
             *    <param name="interceptorStack1.interceptor1.param1">someValue</param>
             *    ...
             *  </interceptor-ref>
             */
        if (interceptorCfgObj instanceof InterceptorConfig) {
            // interceptor-ref param refer to an interceptor
            InterceptorConfig cfg = (InterceptorConfig) interceptorCfgObj;
            Interceptor interceptor = objectFactory.buildInterceptor(cfg, map);
            InterceptorMapping mapping = new InterceptorMapping(key, interceptor);
            if (result.contains(mapping)) {
                for (int index = 0; index < result.size(); index++) {
                    InterceptorMapping interceptorMapping = result.get(index);
                    if (interceptorMapping.getName().equals(key)) {
                        LOG.debug("Overriding interceptor config [{}] with new mapping {} using new params {}", key, interceptorMapping, map);
                        result.set(index, mapping);
                    }
                }
            } else {
                result.add(mapping);
            }
        } else if (interceptorCfgObj instanceof InterceptorStackConfig) {
            // interceptor-ref param refer to an interceptor stack
            // If its an interceptor-stack, we call this method recursively until,
            // all the params (eg. interceptorStack1.interceptor1.param etc.)
            // are resolved down to a specific interceptor.
            InterceptorStackConfig stackCfg = (InterceptorStackConfig) interceptorCfgObj;
            List<InterceptorMapping> tmpResult = constructParameterizedInterceptorReferences(interceptorLocator, stackCfg, map, objectFactory);
            for (InterceptorMapping tmpInterceptorMapping : tmpResult) {
                if (result.contains(tmpInterceptorMapping)) {
                    int index = result.indexOf(tmpInterceptorMapping);
                    result.set(index, tmpInterceptorMapping);
                } else {
                    result.add(tmpInterceptorMapping);
                }
            }
        }
    }
    return result;
}
Also used : InterceptorConfig(com.opensymphony.xwork2.config.entities.InterceptorConfig) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) LinkedHashMap(java.util.LinkedHashMap) InterceptorStackConfig(com.opensymphony.xwork2.config.entities.InterceptorStackConfig) ArrayList(java.util.ArrayList) List(java.util.List) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Interceptor(com.opensymphony.xwork2.interceptor.Interceptor)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18