JDKProxy implements Proxy { @Override public <T> T getProxy(Class<T> interfaceClass, Invoker proxyInvoker) { InvocationHandler handler = new JDKInvocationHandler(interfaceClass, proxyInvoker); ClassLoader classLoader = ClassLoaderUtils.getCurrentClassLoader(); T result = (T) java.lang.reflect.Proxy.newProxyInstance(classLoader, new Class[] { interfaceClass }, handler); return result; }  @Override T getProxy(Class<T> interfaceClass, Invoker proxyInvoker); @Override Invoker getInvoker(Object proxyObject); static Invoker parseInvoker(Object proxyObject);  }
@Test public void getProxy() throws Exception { JDKProxy proxy = new JDKProxy(); AbstractTestClass testClass = null; try { testClass = proxy.getProxy(AbstractTestClass.class, new TestInvoker()); } catch (Exception e) { LOGGER.info(e.getMessage()); } Assert.assertNull(testClass); TestInvoker invoker = new TestInvoker(); TestInterface testInterface = proxy.getProxy(TestInterface.class, invoker); Assert.assertNotNull(testInterface); Class clazz = testInterface.getClass().getInterfaces()[0]; Assert.assertEquals(TestInterface.class, clazz); Assert.assertTrue(Proxy.class.isAssignableFrom(testInterface.getClass())); Assert.assertTrue(Proxy.isProxyClass(testInterface.getClass())); Assert.assertEquals(proxy.getInvoker(testInterface).getClass(), TestInvoker.class); Assert.assertEquals(testInterface.toString(), invoker.toString()); Assert.assertEquals(testInterface.hashCode(), invoker.hashCode()); TestInterface another1 = proxy.getProxy(TestInterface.class, invoker); TestInterface another2 = proxy.getProxy(TestInterface.class, new TestInvoker()); Assert.assertFalse(testInterface.equals(invoker)); Assert.assertFalse(testInterface.equals(another2)); Assert.assertEquals(testInterface, another1); Assert.assertEquals(678, another1.sayNum(true)); SofaRequest request = invoker.getRequest(); Assert.assertEquals(TestInterface.class.getCanonicalName(), request.getInterfaceName()); Assert.assertEquals("sayNum", request.getMethodName()); Assert.assertEquals("boolean", request.getMethodArgSigs()[0]); Assert.assertEquals(true, request.getMethodArgs()[0]); Assert.assertNotNull(request.getMethod()); Assert.assertEquals("sayHello", another1.sayHello("xxxx")); another1.sayNoting(); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, another1.sayNums(null, new HashMap())); Assert.assertNull(another1.sayNum2(1.2D)); boolean error = false; try { another1.throwbiz1(); } catch (Throwable e) { error = true; } Assert.assertFalse(error); error = false; try { another1.throwbiz2(); } catch (Throwable e) { error = true; } Assert.assertFalse(error); try { another1.throwRPC(); } catch (Throwable e) { error = true; } Assert.assertTrue(error); }