@Test public void shouldFailWithLocalClass() throws Exception { class LocalClass { public void localClassMethod() { throw new UnsupportedOperationException(); } } try { new InvocationProxy<LocalClass>(LocalClass.class) { @Override public Object invoke(Method method, Object... args) { methodCalled = method; argsCalled = args; return null; } }.newInstance().localClassMethod(); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertEquals( "classes to be proxied must not be local: net.java.messageapi.adapter.InvocationProxyTest$1LocalClass", e.getMessage()); } }
public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); T newInstance(); abstract Object invoke(Method method, Object... args); }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); T newInstance(); abstract Object invoke(Method method, Object... args);  }