Search code examples
javaconfigurationstruts2interceptorwildcard-mapping

Why the interceptor brokes the wildcard in Struts 2?


I have this action with wildcards:

@Namespace("/posts")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SearchPostBeansAction.class); 
    
    @Override
    @Actions({
        @Action(value="/{search1}/{param1}/",results={ 
            @Result(name=ACTION_SUCCESS,location="classic.main.general", type="tiles")})    
    })
    public String execute() throws Exception {
           logger.info("Action: " + getInvocatedURL() );
           String forward = SUCCESS;
           logger.info("getSearch1( " + getSearch1() + " )");
           logger.info("getParam1( " + getParam1() + " )");
           return forward;
    }
}

The result executed:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( category )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( cars )

If I intercept that action:

@InterceptorRef("seoFilter")
@Namespace("/anuncios")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
...
}

The result executed:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( null )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( null) 

Why lost wildcard's parameters?

Here it´s interceptor:

public class SEOFilter implements Interceptor{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SEOFilter.class); 
    
    ActionSupport actionSupport = null;
    
    public String intercept(ActionInvocation invocation) throws Exception {
        actionSupport = (ActionSupport) invocation.getAction();
        actionSupport.execute();
    }
}

Solution

  • I got what I wanted!!! :)

    Many Thanks Boris and Roman.

    I just define a interceptor-stack.

    <interceptors> 
        <interceptor name="seoFilter" class="com.silver.usaditos.admin.SEOFilter"></interceptor>
        <interceptor-stack name="defaultInterceptorStack">
            <interceptor-ref name="defaultStack"/>
            <interceptor-ref name="seoFilter"/>
        </interceptor-stack>
    </interceptors>