diff --git a/core/src/main/java/com/opensymphony/xwork2/factory/DefaultInterceptorFactory.java b/core/src/main/java/com/opensymphony/xwork2/factory/DefaultInterceptorFactory.java index a1d9ee2ce7..580464130e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/factory/DefaultInterceptorFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/factory/DefaultInterceptorFactory.java @@ -70,13 +70,18 @@ public Interceptor buildInterceptor(InterceptorConfig interceptorConfig, Map extraCo Result result = null; if (resultClassName != null) { - result = (Result) objectFactory.buildBean(resultClassName, extraContext); + Object o = objectFactory.buildBean(resultClassName, extraContext); + if (o instanceof Result) { + result = (Result) o; + } else if (o instanceof org.apache.struts2.Result) { + result = Result.adapt((org.apache.struts2.Result) o); + } + if (result == null) { + throw new ConfigurationException("Class [" + resultClassName + "] does not implement Result", resultConfig); + } + Map params = resultConfig.getParams(); if (params != null) { for (Map.Entry paramEntry : params.entrySet()) { diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java index 83c2bcb3e1..0e83f64b2e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java @@ -28,9 +28,32 @@ @Deprecated public interface ConditionalInterceptor extends org.apache.struts2.interceptor.ConditionalInterceptor, Interceptor { + @Override default boolean shouldIntercept(org.apache.struts2.ActionInvocation invocation) { return shouldIntercept(ActionInvocation.adapt(invocation)); } boolean shouldIntercept(ActionInvocation invocation); + + static ConditionalInterceptor adapt(org.apache.struts2.interceptor.ConditionalInterceptor actualInterceptor) { + if (actualInterceptor instanceof ConditionalInterceptor) { + return (ConditionalInterceptor) actualInterceptor; + } + return actualInterceptor != null ? new LegacyAdapter(actualInterceptor) : null; + } + + class LegacyAdapter extends Interceptor.LegacyAdapter implements ConditionalInterceptor { + + private final org.apache.struts2.interceptor.ConditionalInterceptor adaptee; + + private LegacyAdapter(org.apache.struts2.interceptor.ConditionalInterceptor adaptee) { + super(adaptee); + this.adaptee = adaptee; + } + + @Override + public boolean shouldIntercept(ActionInvocation invocation) { + return adaptee.shouldIntercept(invocation); + } + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java index 628dda6f5e..e6ff42998e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java @@ -34,4 +34,38 @@ default String intercept(org.apache.struts2.ActionInvocation invocation) throws } String intercept(ActionInvocation invocation) throws Exception; + + static Interceptor adapt(org.apache.struts2.interceptor.Interceptor actualInterceptor) { + if (actualInterceptor instanceof org.apache.struts2.interceptor.ConditionalInterceptor) { + return ConditionalInterceptor.adapt((org.apache.struts2.interceptor.ConditionalInterceptor) actualInterceptor); + } + if (actualInterceptor instanceof Interceptor) { + return (Interceptor) actualInterceptor; + } + return actualInterceptor != null ? new LegacyAdapter(actualInterceptor) : null; + } + + class LegacyAdapter implements Interceptor { + + private final org.apache.struts2.interceptor.Interceptor adaptee; + + protected LegacyAdapter(org.apache.struts2.interceptor.Interceptor adaptee) { + this.adaptee = adaptee; + } + + @Override + public String intercept(ActionInvocation invocation) throws Exception { + return adaptee.intercept(invocation); + } + + @Override + public void destroy() { + adaptee.destroy(); + } + + @Override + public void init() { + adaptee.init(); + } + } } diff --git a/core/src/main/java/org/apache/struts2/factory/StrutsResultFactory.java b/core/src/main/java/org/apache/struts2/factory/StrutsResultFactory.java index 0a758f2138..2818f33dda 100644 --- a/core/src/main/java/org/apache/struts2/factory/StrutsResultFactory.java +++ b/core/src/main/java/org/apache/struts2/factory/StrutsResultFactory.java @@ -20,13 +20,14 @@ import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.Result; +import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.factory.ResultFactory; import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.result.ParamNameAwareResult; import com.opensymphony.xwork2.util.reflection.ReflectionException; import com.opensymphony.xwork2.util.reflection.ReflectionExceptionHandler; import com.opensymphony.xwork2.util.reflection.ReflectionProvider; -import com.opensymphony.xwork2.result.ParamNameAwareResult; import java.util.Map; @@ -53,7 +54,15 @@ public Result buildResult(ResultConfig resultConfig, Map extraCo Result result = null; if (resultClassName != null) { - result = (Result) objectFactory.buildBean(resultClassName, extraContext); + Object o = objectFactory.buildBean(resultClassName, extraContext); + if (o instanceof Result) { + result = (Result) o; + } else if (o instanceof org.apache.struts2.Result) { + result = Result.adapt((org.apache.struts2.Result) o); + } + if (result == null) { + throw new ConfigurationException("Class [" + resultClassName + "] does not implement Result", resultConfig); + } Map params = resultConfig.getParams(); if (params != null) { setParameters(extraContext, result, params);