RpcUtils { public static Class<?> getReturnType(Invocation invocation) { try { if (invocation != null && invocation.getInvoker() != null && invocation.getInvoker().getUrl() != null && invocation.getInvoker().getInterface() != GenericService.class && !invocation.getMethodName().startsWith("$")) { String service = invocation.getInvoker().getUrl().getServiceInterface(); if (StringUtils.isNotEmpty(service)) { Method method = getMethodByService(invocation, service); return method.getReturnType(); } } } catch (Throwable t) { logger.warn(t.getMessage(), t); } return null; }  static Class<?> getReturnType(Invocation invocation); static Type[] getReturnTypes(Invocation invocation); static Long getInvocationId(Invocation inv); static void attachInvocationIdIfAsync(URL url, Invocation inv); static String getMethodName(Invocation invocation); static Object[] getArguments(Invocation invocation); static Class<?>[] getParameterTypes(Invocation invocation); static boolean isAsync(URL url, Invocation inv); static boolean isReturnTypeFuture(Invocation inv); static boolean isGenericAsync(Invocation inv); static boolean isGenericCall(String parameterTypesDesc, String method); static boolean isEcho(String parameterTypesDesc, String method); static InvokeMode getInvokeMode(URL url, Invocation inv); static boolean isOneway(URL url, Invocation inv); static long getTimeout(Invocation invocation, long defaultTimeout); static long getTimeout(URL url, String methodName, RpcContext context, long defaultTimeout);  }
@Test public void testGetReturnType() { Class<?> demoServiceClass = DemoService.class; String serviceName = demoServiceClass.getName(); Invoker invoker = mock(Invoker.class); given(invoker.getUrl()).willReturn(URL.valueOf("test: RpcInvocation inv = new RpcInvocation("sayHello", serviceName, "", new Class<?>[]{String.class}, null, null, invoker, null); Class<?> returnType = RpcUtils.getReturnType(inv); Assertions.assertNull(returnType); RpcInvocation inv1 = new RpcInvocation("echo", serviceName, "", new Class<?>[]{String.class}, null, null, invoker, null); Class<?> returnType1 = RpcUtils.getReturnType(inv1); Assertions.assertNotNull(returnType1); Assertions.assertEquals(String.class, returnType1); RpcInvocation inv2 = new RpcInvocation("getSize", serviceName, "", new Class<?>[]{String[].class}, null, null, invoker, null); Class<?> returnType2 = RpcUtils.getReturnType(inv2); Assertions.assertNotNull(returnType2); Assertions.assertEquals(int.class, returnType2); RpcInvocation inv3 = new RpcInvocation("getPerson", serviceName, "", new Class<?>[]{Person.class}, null, null, invoker, null); Class<?> returnType3 = RpcUtils.getReturnType(inv3); Assertions.assertNotNull(returnType3); Assertions.assertEquals(Person.class, returnType3); RpcInvocation inv4 = new RpcInvocation("testReturnType1", serviceName, "", new Class<?>[]{String.class}, null, null, invoker, null); Class<?> returnType4 = RpcUtils.getReturnType(inv4); Assertions.assertNotNull(returnType4); Assertions.assertEquals(List.class, returnType4); }