use of java.lang.reflect.InvocationHandler in project dubbo by alibaba.
the class ProxyTest method testCglibProxy.
@Test
public void testCglibProxy() throws Exception {
ITest test = (ITest) Proxy.getProxy(ITest.class).newInstance(new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println(method.getName());
return null;
}
});
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(test.getClass());
enhancer.setCallback(new MethodInterceptor() {
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return null;
}
});
try {
enhancer.create();
} catch (IllegalArgumentException e) {
e.printStackTrace();
Assert.fail();
}
}
use of java.lang.reflect.InvocationHandler in project tomee by apache.
the class MdbProxy method destroyProxy.
public static void destroyProxy(final Object proxy) {
final InvocationHandler handler = Proxy.getInvocationHandler(proxy);
if (MdbProxy.class.isInstance(handler)) {
final MdbInvocationHandler mdbInvocationHandler = (MdbInvocationHandler) handler;
mdbInvocationHandler.destroy();
}
}
use of java.lang.reflect.InvocationHandler in project jo-client-platform by jo-source.
the class RemotingServiceProviderFactory method getService.
private static Object getService(final IServiceId<?> serviceId, final Object brokerId) {
final Class<?> serviceType = serviceId.getServiceType();
final InvocationHandler invocationHandler = new RemoteMethodInvocationHandler(brokerId, serviceId);
return Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
}
use of java.lang.reflect.InvocationHandler in project kernel by exoplatform.
the class TestContainerUtil method testGetServletContextName.
public void testGetServletContextName() {
final AtomicReference<String> scn = new AtomicReference<String>("myContextName");
final AtomicReference<String> scp = new AtomicReference<String>("/myContextPath");
ServletContext context = (ServletContext) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ServletContext.class }, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("getServletContextName".equals(method.getName()))
return scn.get();
else if ("getContextPath".equals(method.getName()))
return scp.get();
return null;
}
});
assertEquals("myContextName", ContainerUtil.getServletContextName(context));
scn.set(null);
assertEquals("myContextPath", ContainerUtil.getServletContextName(context));
scp.set("");
assertEquals("", ContainerUtil.getServletContextName(context));
scp.set("/a/b");
assertEquals("a", ContainerUtil.getServletContextName(context));
scp.set("/a2/b/");
assertEquals("a2", ContainerUtil.getServletContextName(context));
scp.set("a3/b");
assertEquals("a3", ContainerUtil.getServletContextName(context));
scp.set("a4/b/");
assertEquals("a4", ContainerUtil.getServletContextName(context));
scp.set(null);
assertNull(ContainerUtil.getServletContextName(context));
}
use of java.lang.reflect.InvocationHandler in project jo-client-platform by jo-source.
the class CancelServicesDecoratorProviderImpl method getDecorator.
@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
Assert.paramNotNull(id, "id");
final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
return new IDecorator<SERVICE_TYPE>() {
@SuppressWarnings("unchecked")
@Override
public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
if (services.contains(serviceType)) {
final InvocationHandler invocationHandler = new CancelInvocationHandler(original);
return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
} else {
return original;
}
}
};
}
Aggregations