BlockingInvocationHandlerAdapter extends InvocationHandlerAdapter { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Allow allow = method.getAnnotation(Allow.class); if (allow != null) { for (String domainAllowed : allow.value()) { if (domainAllowed.equals(domain)) { return super.invoke(proxy, method, args); } } } throw new RuntimeException(MessageFormat.format( "Your domain ({0}) is not allowed to run the method {1}.", domain, method.getName())); } BlockingInvocationHandlerAdapter(Object impl, String domain); @Override Object invoke(Object proxy, Method method, Object[] args);  }
@Test public void testHookedAdapter() { InvocationHandlerAdapter handler = new InvocationHandlerAdapter( new TestServiceImpl()) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Integer ret = (Integer) super.invoke(proxy, method, args); ret = ret * 2; return ret; } }; TestService test = handler.createProxy(TestService.class); assertEquals(28, test.sum(5, 9)); }