Support default methods in @HttpExchange interface

Closes gh-28491
This commit is contained in:
rstoyanchev
2022-05-25 09:24:15 +01:00
parent e2798560c7
commit cc56da7735
2 changed files with 19 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.web.service.invoker;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.ArrayList;
@@ -28,6 +29,7 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.ReflectiveMethodInvocation;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.core.MethodIntrospector;
@@ -215,10 +217,19 @@ public final class HttpServiceProxyFactory implements InitializingBean, Embedded
}
@Override
public Object invoke(MethodInvocation invocation) {
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
HttpServiceMethod httpServiceMethod = this.httpServiceMethods.get(method);
return httpServiceMethod.invoke(invocation.getArguments());
if (httpServiceMethod != null) {
return httpServiceMethod.invoke(invocation.getArguments());
}
if (method.isDefault()) {
if (invocation instanceof ReflectiveMethodInvocation reflectiveMethodInvocation) {
Object proxy = reflectiveMethodInvocation.getProxy();
return InvocationHandler.invokeDefault(proxy, method, invocation.getArguments());
}
}
throw new IllegalStateException("Unexpected method invocation: " + method);
}
}