Search in sources :

Example 1 with ThreadLocalHttpHeaders

use of org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_GETMethodBodyTest method shouldPassHttpHeadersToRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final HttpHeaders headers = new ThreadLocalHttpHeaders();
    setField(resourceObject, "headers", headers);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject);
    verify(restProcessor).process(anyString(), any(Function.class), anyString(), eq(headers), any(Collection.class));
}
Also used : ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Function(java.util.function.Function) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with ThreadLocalHttpHeaders

use of org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassHttpHeadersToRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final HttpHeaders headers = new ThreadLocalHttpHeaders();
    setField(resourceObject, "headers", headers);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(Optional.class), eq(headers), any(Collection.class));
}
Also used : ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Function(java.util.function.Function) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with ThreadLocalHttpHeaders

use of org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders in project tomee 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<>();
    } 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) {
        ClassLoader loader = proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type });
        if (!canSeeAllClasses(loader, new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type })) {
            LOG.log(Level.FINE, "find a loader from ProxyClassLoader cache," + " but can't see all interfaces");
            LOG.log(Level.FINE, "create a new one with parent  " + Proxy.class.getClassLoader());
            proxyClassLoaderCache.removeStaleProxyClassLoader(type);
            proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type });
        }
        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) 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)

Example 4 with ThreadLocalHttpHeaders

use of org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders 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<>();
    } 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) {
        ClassLoader loader = proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type });
        if (!canSeeAllClasses(loader, new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type })) {
            LOG.log(Level.FINE, "find a loader from ProxyClassLoader cache," + " but can't see all interfaces");
            LOG.log(Level.FINE, "create a new one with parent  " + Proxy.class.getClassLoader());
            proxyClassLoaderCache.removeStaleProxyClassLoader(type);
            proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), new Class<?>[] { Proxy.class, ThreadLocalProxy.class, type });
        }
        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) 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

HttpHeaders (javax.ws.rs.core.HttpHeaders)4 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)4 Method (java.lang.reflect.Method)2 Proxy (java.lang.reflect.Proxy)2 Collection (java.util.Collection)2 Function (java.util.function.Function)2 Request (javax.ws.rs.core.Request)2 SecurityContext (javax.ws.rs.core.SecurityContext)2 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)2 ThreadLocalInvocationHandler (org.apache.cxf.jaxrs.impl.tl.ThreadLocalInvocationHandler)2 ThreadLocalMessageContext (org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext)2 ThreadLocalProtocolHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProtocolHeaders)2 ThreadLocalProviders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders)2 ThreadLocalProxy (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy)2 ThreadLocalRequest (org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest)2 ThreadLocalSecurityContext (org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext)2 ThreadLocalUriInfo (org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo)2 Test (org.junit.Test)2 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)2 Optional (java.util.Optional)1