use of org.apache.cxf.common.util.ProxyClassLoader in project cxf by apache.
the class JAXRSClientFactoryBeanTest method testCreateClientCustomLoader.
@Test
public void testCreateClientCustomLoader() throws Exception {
ProxyClassLoader loader = new ProxyClassLoader(BookStore.class.getClassLoader());
loader.addLoader(BookStore.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress("http://bar");
bean.setResourceClass(BookStore.class);
bean.setClassLoader(loader);
BookStore client = (BookStore) bean.createWithValues(BookStore.class);
assertNotNull(client);
assertSame(client.getClass().getClassLoader(), loader);
// tricky to test the loader has been used correctly with Maven
// given that the system loader loads all the test classes
}
use of org.apache.cxf.common.util.ProxyClassLoader in project cxf by apache.
the class InjectionUtils method createThreadLocalProxy.
// TODO : investigate the possibility of using generic proxies only
@SuppressWarnings("unchecked")
public static <T> ThreadLocalProxy<T> createThreadLocalProxy(Class<T> type) {
ThreadLocalProxy<?> proxy = null;
if (UriInfo.class.isAssignableFrom(type)) {
proxy = new ThreadLocalUriInfo();
} else if (HttpHeaders.class.isAssignableFrom(type)) {
proxy = new ThreadLocalHttpHeaders();
} else if (ProtocolHeaders.class.isAssignableFrom(type)) {
proxy = new ThreadLocalProtocolHeaders();
} else if (SecurityContext.class.isAssignableFrom(type)) {
proxy = new ThreadLocalSecurityContext();
} else if (ContextResolver.class.isAssignableFrom(type)) {
proxy = new ThreadLocalContextResolver<Object>();
} else if (Request.class.isAssignableFrom(type)) {
proxy = new ThreadLocalRequest();
} else if (Providers.class.isAssignableFrom(type)) {
proxy = new ThreadLocalProviders();
} else if (MessageContext.class.isAssignableFrom(type)) {
proxy = new ThreadLocalMessageContext();
}
if (proxy == null && isServletApiContext(type.getName())) {
proxy = createThreadLocalServletApiContext(type.getName());
}
if (proxy == null) {
ProxyClassLoader loader = new ProxyClassLoader(Proxy.class.getClassLoader());
loader.addLoader(type.getClassLoader());
loader.addLoader(ThreadLocalProxy.class.getClassLoader());
return (ThreadLocalProxy<T>) Proxy.newProxyInstance(loader, new Class[] { type, ThreadLocalProxy.class }, new ThreadLocalInvocationHandler<T>());
}
return (ThreadLocalProxy<T>) proxy;
}
Aggregations