2121import org .apache .dubbo .rpc .model .StubMethodDescriptor ;
2222
2323import java .lang .reflect .ParameterizedType ;
24+ import java .lang .reflect .Type ;
2425
2526public class MethodMetadata {
2627
@@ -64,18 +65,18 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met
6465 case CLIENT_STREAM :
6566 case BI_STREAM :
6667 actualRequestTypes = new Class <?>[] {
67- ( Class <?>)
68- ((ParameterizedType ) method .getMethod ().getGenericReturnType ()).getActualTypeArguments ()[0 ]
68+ obtainActualTypeInStreamObserver (
69+ ((ParameterizedType ) method .getMethod ().getGenericReturnType ()).getActualTypeArguments ()[0 ])
6970 };
70- actualResponseType =
71- (Class <?>) ( (ParameterizedType ) method .getMethod ().getGenericParameterTypes ()[0 ])
72- .getActualTypeArguments ()[0 ];
71+ actualResponseType = obtainActualTypeInStreamObserver (
72+ ((ParameterizedType ) method .getMethod ().getGenericParameterTypes ()[0 ])
73+ .getActualTypeArguments ()[0 ]) ;
7374 return new MethodMetadata (actualRequestTypes , actualResponseType );
7475 case SERVER_STREAM :
7576 actualRequestTypes = new Class [] {method .getMethod ().getParameterTypes ()[0 ]};
76- actualResponseType =
77- (Class <?>) ( (ParameterizedType ) method .getMethod ().getGenericParameterTypes ()[1 ])
78- .getActualTypeArguments ()[0 ];
77+ actualResponseType = obtainActualTypeInStreamObserver (
78+ ((ParameterizedType ) method .getMethod ().getGenericParameterTypes ()[1 ])
79+ .getActualTypeArguments ()[0 ]) ;
7980 return new MethodMetadata (actualRequestTypes , actualResponseType );
8081 case UNARY :
8182 actualRequestTypes = method .getParameterClasses ();
@@ -84,4 +85,11 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met
8485 }
8586 throw new IllegalStateException ("Can not reach here" );
8687 }
88+
89+ static Class <?> obtainActualTypeInStreamObserver (Type typeInStreamObserver ) {
90+ return (Class <?>)
91+ (typeInStreamObserver instanceof ParameterizedType
92+ ? ((ParameterizedType ) typeInStreamObserver ).getRawType ()
93+ : typeInStreamObserver );
94+ }
8795}
0 commit comments