Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public Set<String> getIncludeMethodsSet() {

@Override
public String intercept(ActionInvocation invocation) throws Exception {
if (applyInterceptor(invocation)) {
return doIntercept(invocation);
if (applyInterceptor((org.apache.struts2.ActionInvocation) invocation)) {
Copy link
Member Author

@kusalk kusalk Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little tricky to follow at first, but we call into #applyInterceptor(struts2.ActionInvocation) which itself calls into #applyInterceptor(xwork2.ActionInvocation). Thus an extending class can override either of these methods and it will still have the intended overriding effect.

Thus legacy applications which are still overriding #applyInterceptor(xwork2.ActionInvocation) will continue to work with no changes required. And applications that wish to prepare for Struts 7 can update their override to the new method signature.

return doIntercept((org.apache.struts2.ActionInvocation) invocation);
}
return invocation.invoke();
}
Expand All @@ -114,6 +114,10 @@ protected boolean applyInterceptor(ActionInvocation invocation) {
return applyMethod;
}

protected boolean applyInterceptor(org.apache.struts2.ActionInvocation invocation) {
return applyInterceptor(ActionInvocation.adapt(invocation));
}

/**
* Subclasses must override to implement the interceptor logic.
*
Expand All @@ -123,4 +127,7 @@ protected boolean applyInterceptor(ActionInvocation invocation) {
*/
protected abstract String doIntercept(ActionInvocation invocation) throws Exception;

protected String doIntercept(org.apache.struts2.ActionInvocation invocation) throws Exception {
return doIntercept(ActionInvocation.adapt(invocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,13 @@ protected void doBeforeInvocation(ActionInvocation invocation) throws Exception
}
}

protected void doBeforeInvocation(org.apache.struts2.ActionInvocation invocation) throws Exception {
doBeforeInvocation(ActionInvocation.adapt(invocation));
}

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
doBeforeInvocation(invocation);
doBeforeInvocation((org.apache.struts2.ActionInvocation) invocation);
return invocation.invoke();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void setTextProviderFactory(TextProviderFactory textProviderFactory) {
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
LOG.debug("Intercepting invocation to check for valid transaction token.");
return handleToken(invocation);
return handleToken((org.apache.struts2.ActionInvocation) invocation);
}

protected String handleToken(ActionInvocation invocation) throws Exception {
Expand All @@ -144,22 +144,19 @@ protected String handleToken(ActionInvocation invocation) throws Exception {
HttpSession session = ServletActionContext.getRequest().getSession(true);
synchronized (session.getId().intern()) {
if (!TokenHelper.validToken()) {
return handleInvalidToken(invocation);
return handleInvalidToken((org.apache.struts2.ActionInvocation) invocation);
}
}
return handleValidToken(invocation);
return handleValidToken((org.apache.struts2.ActionInvocation) invocation);
}

protected String handleToken(org.apache.struts2.ActionInvocation invocation) throws Exception {
return handleToken(ActionInvocation.adapt(invocation));
}

/**
* Determines what to do if an invalid token is provided. If the action implements {@link ValidationAware}
*
* @param invocation the action invocation where the invalid token failed
* @return the return code to indicate should be processed
* @throws Exception when any unexpected error occurs.
*/
protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
String errorMessage = getErrorMessage(invocation);
String errorMessage = getErrorMessage((org.apache.struts2.ActionInvocation) invocation);

if (action instanceof ValidationAware) {
((ValidationAware) action).addActionError(errorMessage);
Expand All @@ -170,6 +167,17 @@ protected String handleInvalidToken(ActionInvocation invocation) throws Exceptio
return INVALID_TOKEN_CODE;
}

/**
* Determines what to do if an invalid token is provided. If the action implements {@link ValidationAware}
*
* @param invocation the action invocation where the invalid token failed
* @return the return code to indicate should be processed
* @throws Exception when any unexpected error occurs.
*/
protected String handleInvalidToken(org.apache.struts2.ActionInvocation invocation) throws Exception {
return handleInvalidToken(ActionInvocation.adapt(invocation));
}

protected String getErrorMessage(ActionInvocation invocation) {
Object action = invocation.getAction();
if (action instanceof TextProvider) {
Expand All @@ -178,6 +186,14 @@ protected String getErrorMessage(ActionInvocation invocation) {
return textProvider.getText(INVALID_TOKEN_MESSAGE_KEY, DEFAULT_ERROR_MESSAGE);
}

protected String getErrorMessage(org.apache.struts2.ActionInvocation invocation) {
return getErrorMessage(ActionInvocation.adapt(invocation));
}

protected String handleValidToken(ActionInvocation invocation) throws Exception {
return invocation.invoke();
}

/**
* Called when a valid token is found. This method invokes the action by can be changed to do something more
* interesting.
Expand All @@ -186,8 +202,8 @@ protected String getErrorMessage(ActionInvocation invocation) {
* @return invocation result
* @throws Exception when any unexpected error occurs.
*/
protected String handleValidToken(ActionInvocation invocation) throws Exception {
return invocation.invoke();
protected String handleValidToken(org.apache.struts2.ActionInvocation invocation) throws Exception {
return handleValidToken(ActionInvocation.adapt(invocation));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static ActionInvocation loadInvocation(String key, String token) {
return null;
}

final ActionInvocation savedInvocation = invocationContext.invocation;
final ActionInvocation savedInvocation = ActionInvocation.adapt(invocationContext.invocation);
if (savedInvocation != null) {
// WW-5026 - Preserve the previous PageContext (even if null) and restore it to the
// ActionContext after loading the savedInvocation context. The saved context's PageContext
Expand All @@ -72,6 +72,10 @@ public static ActionInvocation loadInvocation(String key, String token) {
return savedInvocation;
}

public static void storeInvocation(String key, String token, ActionInvocation invocation) {
storeInvocation(key, token, (org.apache.struts2.ActionInvocation) invocation);
}

/**
* Stores the DefaultActionInvocation and ActionContext into the Session using the provided key for loading later using
* {@link #loadInvocation}
Expand All @@ -80,7 +84,7 @@ public static ActionInvocation loadInvocation(String key, String token) {
* @param token token for check
* @param invocation the action invocation
*/
public static void storeInvocation(String key, String token, ActionInvocation invocation) {
public static void storeInvocation(String key, String token, org.apache.struts2.ActionInvocation invocation) {
InvocationContext invocationContext = new InvocationContext(invocation, token);
Map<String, Object> invocationMap = getInvocationMap();
invocationMap.put(key, invocationContext);
Expand Down Expand Up @@ -120,11 +124,11 @@ private static class InvocationContext implements Serializable {
private static final long serialVersionUID = -286697666275777888L;

//WW-4873 transient since 2.5.15
transient ActionInvocation invocation;
transient org.apache.struts2.ActionInvocation invocation;

String token;

public InvocationContext(ActionInvocation invocation, String token) {
public InvocationContext(org.apache.struts2.ActionInvocation invocation, String token) {
this.invocation = invocation;
this.token = token;
}
Expand Down