steven35 steven35 - 1 year ago 155
Java Question

Struts2 Infinite recursion detected

I have a struts2 chain result that redirects to itself but it does NOT create an infinite loop because there is a condition that will eventually evaluate to false and then the recursion will stop. I have to use chain instead of redirectAction because I need a POST request which redirectAction cannot do.

This is the exception I'm getting

Could not execute action
Infinite recursion detected: [/view/myAction!myMethod, /view/myAction, /view/myAction] - [unknown location]
at com.opensymphony.xwork2.ActionChainResult.execute(

I have been through the xwork jar where the infinite loop detection is based. It looks at the chain history and if it finds the action name it throws an exception. The maximum recursion is hardcoded to 1.

Is there a way to handle the exception or increase the maximum number of allowed recursions or reset the chain history manually while chaining?

Answer Source

I found a way to manipulate the chain history from an interceptor

    final ActionContext context = invocation.getInvocationContext();
    LinkedList<String> chainHistory = (LinkedList<String>) context.get("CHAIN_HISTORY");
    // context.put("CHAIN_HISTORY", null);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download