2323import io .grpc .ManagedChannelBuilder ;
2424import io .grpc .stub .ClientCallStreamObserver ;
2525import io .grpc .stub .ClientResponseObserver ;
26+
27+ import java .lang .reflect .Method ;
2628import java .util .Arrays ;
2729import java .util .Iterator ;
2830import java .util .List ;
3537import org .apache .skywalking .apm .testcase .grpc .proto .GreeterGrpc ;
3638import org .apache .skywalking .apm .testcase .grpc .proto .HelloRequest ;
3739import org .apache .skywalking .apm .testcase .grpc .proto .HelloReply ;
40+ import org .springframework .cglib .core .ReflectUtils ;
41+ import org .springframework .util .ReflectionUtils ;
3842import org .springframework .web .bind .annotation .RequestMapping ;
3943import org .springframework .web .bind .annotation .ResponseBody ;
4044import org .springframework .web .bind .annotation .RestController ;
@@ -56,7 +60,17 @@ public class CaseController {
5660
5761 @ PostConstruct
5862 public void up () {
59- channel = ManagedChannelBuilder .forAddress (grpcProviderHost , grpcProviderPort ).usePlaintext (true ).build ();
63+ ManagedChannelBuilder <?> managedChannelBuilder = ManagedChannelBuilder .forAddress (grpcProviderHost , grpcProviderPort );
64+ Method usePlaintext = ReflectionUtils .findMethod (managedChannelBuilder .getClass (), "usePlaintext" );
65+ if (usePlaintext != null ) {
66+ int paramCount = usePlaintext .getParameterCount ();
67+ if (paramCount == 0 ) {// no parame method usePlaintext()
68+ ReflectionUtils .invokeMethod (usePlaintext , managedChannelBuilder );
69+ } else if (paramCount == 1 && usePlaintext .getParameterTypes ()[0 ] == boolean .class ) {// boolean method usePlaintext(true)
70+ ReflectionUtils .invokeMethod (usePlaintext , managedChannelBuilder , true );
71+ }
72+ }
73+ channel = managedChannelBuilder .build ();
6074 greeterStub = GreeterGrpc .newStub (ClientInterceptors .intercept (channel , new ConsumerInterceptor ()));
6175 greeterBlockingStub = GreeterBlockingGrpc .newBlockingStub (ClientInterceptors .intercept (channel , new ConsumerInterceptor ()));
6276 greeterBlockingErrorStub = GreeterBlockingErrorGrpc .newBlockingStub (ClientInterceptors .intercept (channel , new ConsumerInterceptor ()));
0 commit comments