Tuesday, January 27, 2015

STRUTS2 UNKNOWN ACTION HANDLER CLASS (UnknownHandler)

struts.xml

<struts>


<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.raj.mv.pd.controller.pkg.UnknownActionController"/>
...
...

</struts>

UNKNOWN ACTION HANDLER

import org.apache.struts2.dispatcher.Dispatcher;

import com.raj.commons.logging.LogManager;
import com.raj.mv.pd.constants.Results;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.UnknownHandler;
import com.opensymphony.xwork2.XWorkException;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;

public class UnknownActionController implements UnknownHandler{
public static final String MODULE = UnknownActionController.class.getSimpleName();

@Override
public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException {

LogManager.getLogger().debug(MODULE,"Method called handleUnknownAction()");

ConfigurationManager configurationManager = Dispatcher.getInstance().getConfigurationManager();
   RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
   ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
   
   if(actionConfig == null) { // invalid url request, and this need to be handled
       actionConfig = runtimeConfiguration.getActionConfig("", "pkg/Pkg/error");
   }
   return actionConfig;
}

@Override
public Object handleUnknownActionMethod(Object arg0, String arg1) throws NoSuchMethodException {
LogManager.getLogger().debug(MODULE,"Method called handleUnknownActionMethod()");
return Results.EXCEPTION;
}

@Override
public Result handleUnknownResult(ActionContext arg0, String arg1, ActionConfig arg2, String arg3) throws XWorkException {
LogManager.getLogger().debug(MODULE,"Method called handleUnknownResult()");
return null;
}

}

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...