I think I have solution. It seems to work properly. However, I'd like to get some feedback on it from someone smarter than me about the internal workings of Spring. I'm looking for a sanity check to make sure I didn't miss something or maybe there is a better way to accomplish this.
I went with the second option and extended the DelegatingActionProxy and DelegatingTilesRequestProcessor. Here is what I came up with.
this is my action-servlet.xml entries
Code:
<context:component-scan base-package="com.abc.web.struts.action"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
I extended DelegatingActionProxy.
Code:
public class AnnotationActionProxy extends DelegatingActionProxy {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Action delegateAction = null;
WebApplicationContext wac = getWebApplicationContext(getServlet(), mapping
.getModuleConfig());
delegateAction = AnnotationActionUtils.getHandler(request, wac);
if (delegateAction == null) {
String beanName = determineActionBeanName(mapping);
delegateAction = (Action) wac.getBean(beanName, Action.class);
}
return delegateAction.execute(mapping, form, request, response);
}
}
I also extended DelegatingTilesRequestProcessor to test that option.
Code:
public class AnnotationTilesRequestProcessor extends DelegatingTilesRequestProcessor {
@Override
protected Action processActionCreate(
HttpServletRequest request, HttpServletResponse response, ActionMapping mapping)
throws IOException {
Action action = AnnotationActionUtils.getHandler(request, getWebApplicationContext());
if (action == null) {
action = getDelegateAction(mapping);
}
if (action != null) {
return action;
}
return super.processActionCreate(request, response, mapping);
}
}
Here's my utility class shared by both of the above classes.
Code:
public abstract class AnnotationActionUtils {
private static final Log logger = LogFactory.getLog(AnnotationActionUtils.class);
public static Action getHandler(HttpServletRequest request, ApplicationContext context) {
Action action = null;
HandlerExecutionChain handlerChain = null;
Map<String, HandlerMapping> handlerMap = context.getBeansOfType(HandlerMapping.class);
for (HandlerMapping handlerMapping : handlerMap.values()) {
if (logger.isDebugEnabled()) {
logger.debug("Testing handler map [" + handlerMapping + "]");
}
try {
handlerChain = handlerMapping.getHandler(request);
} catch (Exception e) {
throw new RuntimeException(e.toString(), e);
}
if (handlerChain != null) {
action = (Action) handlerChain.getHandler();
if (action != null) {
break;
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Action lookup result [" + action + "]");
}
return action;
}
}