Search in sources :

Example 1 with ThreadLocalProviders

use of org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders 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;
}
Also used : ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) ThreadLocalUriInfo(org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo) ThreadLocalInvocationHandler(org.apache.cxf.jaxrs.impl.tl.ThreadLocalInvocationHandler) ThreadLocalRequest(org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest) Request(javax.ws.rs.core.Request) ThreadLocalRequest(org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest) Proxy(java.lang.reflect.Proxy) ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) ThreadLocalProtocolHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProtocolHeaders) ProxyClassLoader(org.apache.cxf.common.util.ProxyClassLoader) ThreadLocalProviders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders) SecurityContext(javax.ws.rs.core.SecurityContext) ThreadLocalSecurityContext(org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext) ThreadLocalMessageContext(org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext) ThreadLocalMessageContext(org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) ThreadLocalSecurityContext(org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext)

Aggregations

Proxy (java.lang.reflect.Proxy)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Request (javax.ws.rs.core.Request)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 ProxyClassLoader (org.apache.cxf.common.util.ProxyClassLoader)1 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)1 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)1 ThreadLocalInvocationHandler (org.apache.cxf.jaxrs.impl.tl.ThreadLocalInvocationHandler)1 ThreadLocalMessageContext (org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext)1 ThreadLocalProtocolHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProtocolHeaders)1 ThreadLocalProviders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders)1 ThreadLocalProxy (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy)1 ThreadLocalRequest (org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest)1 ThreadLocalSecurityContext (org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext)1 ThreadLocalUriInfo (org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo)1