use of com.opensymphony.xwork2.DefaultActionInvocation in project struts by apache.
the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsNull.
public void testUnknownHandlerManagerThatReturnsNull() throws Exception {
// given
DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
container.inject(dai);
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
@Override
public boolean hasUnknownHandlers() {
return true;
}
@Override
public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
return null;
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("notExists");
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
dai.unknownHandlerManager = uhm;
// when
Throwable actual = null;
try {
dai.invokeAction(new SimpleAction(), null);
} catch (Exception e) {
actual = e;
}
// then
assertNotNull(actual);
assertTrue(actual instanceof NoSuchMethodException);
}
use of com.opensymphony.xwork2.DefaultActionInvocation in project struts by apache.
the class ActionChainResult method execute.
/**
* @param invocation the DefaultActionInvocation calling the action call stack
*/
public void execute(ActionInvocation invocation) throws Exception {
if (invocation == null) {
throw new IllegalArgumentException("Invocation cannot be null!");
}
ValueStack stack = invocation.getInvocationContext().getValueStack();
String finalNamespace = this.namespace != null ? TextParseUtil.translateVariables(namespace, stack) : invocation.getProxy().getNamespace();
String finalActionName = TextParseUtil.translateVariables(actionName, stack);
String finalMethodName = this.methodName != null ? TextParseUtil.translateVariables(this.methodName, stack) : null;
if (isInChainHistory(finalNamespace, finalActionName, finalMethodName)) {
addToHistory(finalNamespace, finalActionName, finalMethodName);
throw new StrutsException("Infinite recursion detected: " + ActionChainResult.getChainHistory().toString());
}
if (ActionChainResult.getChainHistory().isEmpty() && invocation.getProxy() != null) {
addToHistory(finalNamespace, invocation.getProxy().getActionName(), invocation.getProxy().getMethod());
}
addToHistory(finalNamespace, finalActionName, finalMethodName);
Map<String, Object> extraContext = ActionContext.of(new HashMap<>()).withValueStack(invocation.getInvocationContext().getValueStack()).withParameters(invocation.getInvocationContext().getParameters()).with(CHAIN_HISTORY, ActionChainResult.getChainHistory()).getContextMap();
LOG.debug("Chaining to action {}", finalActionName);
proxy = actionProxyFactory.createActionProxy(finalNamespace, finalActionName, finalMethodName, extraContext);
proxy.execute();
}
use of com.opensymphony.xwork2.DefaultActionInvocation in project struts by apache.
the class AnnotationValidationConfigurationBuilderTest method createValidationManager.
private AnnotationActionValidatorManager createValidationManager(final Class<? extends ActionSupport> actionClass, Locale locale) throws Exception {
loadConfigurationProviders(new ConfigurationProvider() {
public void destroy() {
}
public void init(Configuration configuration) throws ConfigurationException {
configuration.addPackageConfig("default", new PackageConfig.Builder("default").addActionConfig("annotation", new ActionConfig.Builder("", "annotation", actionClass.getName()).build()).build());
}
public boolean needsReload() {
return false;
}
public void loadPackages() throws ConfigurationException {
}
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.constant(StrutsConstants.STRUTS_DEVMODE, true);
}
});
// ActionContext is destroyed during rebuilding configuration
ActionContext.getContext().withLocale(locale);
ActionInvocation invocation = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), true);
container.inject(invocation);
invocation.init(actionProxyFactory.createActionProxy("", "annotation", null, ActionContext.getContext().getContextMap()));
AnnotationActionValidatorManager manager = new AnnotationActionValidatorManager();
container.inject(manager);
ValidatorFactory vf = container.getInstance(ValidatorFactory.class);
vf.registerValidator("myValidator", MyValidator.class.getName());
return manager;
}
Aggregations