Search in sources :

Example 41 with Interceptor

use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.

the class DefaultInterceptorMapBuilder method build.

protected List<InterceptorMapping> build(InterceptorRef[] interceptors, String actionName, PackageConfig.Builder builder) {
    List<InterceptorMapping> interceptorList = new ArrayList<>(10);
    for (InterceptorRef interceptor : interceptors) {
        LOG.trace("Adding interceptor [{}] to [{}]", interceptor.value(), actionName);
        Map<String, String> params = StringTools.createParameterMap(interceptor.params());
        interceptorList.addAll(buildInterceptorList(builder, interceptor, params));
    }
    return interceptorList;
}
Also used : ArrayList(java.util.ArrayList) InterceptorRef(org.apache.struts2.convention.annotation.InterceptorRef) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping)

Example 42 with Interceptor

use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.

the class SpringObjectFactoryTest method testObtainInterceptorBySpringName.

public void testObtainInterceptorBySpringName() throws Exception {
    sac.registerSingleton("noop-interceptor", NoOpInterceptor.class, new MutablePropertyValues());
    InterceptorConfig iConfig = new InterceptorConfig.Builder("noop", "noop-interceptor").build();
    Interceptor interceptor = objectFactory.buildInterceptor(iConfig, new HashMap<String, String>());
    assertEquals(NoOpInterceptor.class, interceptor.getClass());
}
Also used : InterceptorConfig(com.opensymphony.xwork2.config.entities.InterceptorConfig) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) DebugInterceptor(org.springframework.aop.interceptor.DebugInterceptor) Interceptor(com.opensymphony.xwork2.interceptor.Interceptor) NoOpInterceptor(org.apache.struts2.interceptor.NoOpInterceptor) ModelDrivenInterceptor(com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor)

Example 43 with Interceptor

use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.

the class ActionAutowiringInterceptorTest method testShouldAutowireAction.

public void testShouldAutowireAction() throws Exception {
    StaticWebApplicationContext context = new StaticWebApplicationContext();
    context.getBeanFactory().registerSingleton("bean", new TestBean());
    TestBean bean = (TestBean) context.getBean("bean");
    loadSpringApplicationContextIntoApplication(context);
    SimpleAction action = new SimpleAction();
    ActionInvocation invocation = new TestActionInvocation(action);
    ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
    interceptor.setApplicationContext(context);
    interceptor.init();
    interceptor.intercept(invocation);
    assertEquals(bean, action.getBean());
}
Also used : TestBean(com.opensymphony.xwork2.TestBean) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 44 with Interceptor

use of com.opensymphony.xwork2.interceptor.Interceptor in project entando-core by entando.

the class TestCustomTokenInterceptor method testExecuteValidation_1.

public void testExecuteValidation_1() throws Exception {
    ActionInvocation invocation = this.prepareAction();
    CustomTokenInterceptor interceptor = new CustomTokenInterceptor();
    String result = interceptor.intercept(invocation);
    assertEquals(Action.SUCCESS, result);
    String newResult = interceptor.intercept(invocation);
    assertEquals(CustomTokenInterceptor.INVALID_TOKEN_CODE, newResult);
    ActionSupport action = super.getAction();
    assertEquals(0, action.getActionErrors().size());
    assertEquals(0, action.getActionMessages().size());
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 45 with Interceptor

use of com.opensymphony.xwork2.interceptor.Interceptor in project entando-core by entando.

the class TestCustomTokenInterceptor method testExecuteValidation_2.

public void testExecuteValidation_2() throws Exception {
    ActionInvocation invocation = this.prepareAction();
    CustomTokenInterceptor interceptor = new CustomTokenInterceptor();
    interceptor.setTypeMessages(CustomTokenInterceptor.TYPE_RETURN_ACTION_ERROR_MESSAGE);
    String result = interceptor.intercept(invocation);
    assertEquals(Action.SUCCESS, result);
    String newResult = interceptor.intercept(invocation);
    assertEquals(CustomTokenInterceptor.INVALID_TOKEN_CODE, newResult);
    ActionSupport action = super.getAction();
    assertEquals(1, action.getActionErrors().size());
    assertEquals(0, action.getActionMessages().size());
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Aggregations

ActionInvocation (com.opensymphony.xwork2.ActionInvocation)32 HashMap (java.util.HashMap)28 ActionContext (com.opensymphony.xwork2.ActionContext)20 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)19 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)19 ServletActionContext (org.apache.struts2.ServletActionContext)14 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)13 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)12 LinkedHashMap (java.util.LinkedHashMap)12 Map (java.util.Map)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)10 InterceptorConfig (com.opensymphony.xwork2.config.entities.InterceptorConfig)10 DefaultAcceptedPatternsChecker (com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker)10 DefaultExcludedPatternsChecker (com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker)10 Cookie (javax.servlet.http.Cookie)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Mock (com.mockobjects.dynamic.Mock)8 ActionSupport (com.opensymphony.xwork2.ActionSupport)8