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)));
}
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!");
};
}
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);
}
}
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);
}
}
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;
}
Aggregations