diff --git a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java index 241d0c42bd7..7f87edafbc4 100644 --- a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java +++ b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java @@ -21,6 +21,7 @@ import org.apache.dubbo.rpc.model.StubMethodDescriptor; import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; public class MethodMetadata { @@ -64,18 +65,18 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met case CLIENT_STREAM: case BI_STREAM: actualRequestTypes = new Class[] { - (Class) - ((ParameterizedType) method.getMethod().getGenericReturnType()).getActualTypeArguments()[0] + obtainActualTypeInStreamObserver( + ((ParameterizedType) method.getMethod().getGenericReturnType()).getActualTypeArguments()[0]) }; - actualResponseType = - (Class) ((ParameterizedType) method.getMethod().getGenericParameterTypes()[0]) - .getActualTypeArguments()[0]; + actualResponseType = obtainActualTypeInStreamObserver( + ((ParameterizedType) method.getMethod().getGenericParameterTypes()[0]) + .getActualTypeArguments()[0]); return new MethodMetadata(actualRequestTypes, actualResponseType); case SERVER_STREAM: actualRequestTypes = new Class[] {method.getMethod().getParameterTypes()[0]}; - actualResponseType = - (Class) ((ParameterizedType) method.getMethod().getGenericParameterTypes()[1]) - .getActualTypeArguments()[0]; + actualResponseType = obtainActualTypeInStreamObserver( + ((ParameterizedType) method.getMethod().getGenericParameterTypes()[1]) + .getActualTypeArguments()[0]); return new MethodMetadata(actualRequestTypes, actualResponseType); case UNARY: actualRequestTypes = method.getParameterClasses(); @@ -84,4 +85,11 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met } throw new IllegalStateException("Can not reach here"); } + + static Class obtainActualTypeInStreamObserver(Type typeInStreamObserver) { + return (Class) + (typeInStreamObserver instanceof ParameterizedType + ? ((ParameterizedType) typeInStreamObserver).getRawType() + : typeInStreamObserver); + } }