Search in sources :

Example 76 with Message

use of org.apache.cxf.message.Message in project tomee by apache.

the class PojoInvoker method getClassLoader.

private ClassLoader getClassLoader(final Exchange exchange) {
    final Message inMessage = exchange.getInMessage();
    if (inMessage == null) {
        return null;
    }
    final OpenEJBPerRequestPojoResourceProvider requestPojoResourceProvider = inMessage.get(OpenEJBPerRequestPojoResourceProvider.class);
    if (requestPojoResourceProvider != null) {
        return requestPojoResourceProvider.getClassLoader();
    }
    return null;
}
Also used : Message(org.apache.cxf.message.Message)

Example 77 with Message

use of org.apache.cxf.message.Message in project tomee by apache.

the class Contexts method bind.

/**
 * Using a set ensures we don't set the thread local twice or more,
 * there may be super classes with injection points of identical types
 *
 * Also allows us to get context references from other sources such as interceptors
 *
 * @param exchange Exchange
 * @param types    Collection
 */
public static void bind(final Exchange exchange, final Collection<Class<?>> types) {
    // used in lazy mode by RESTResourceFinder if cdi beans uses @Context, === initThreadLocal
    EXCHANGE.set(exchange);
    CdiAppContextsService.pushRequestReleasable(CleanUpThreadLocal.INSTANCE);
    for (final Class<?> type : types) {
        if (Request.class.equals(type)) {
            final Request binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Request.class);
            ThreadLocalContextManager.REQUEST.set(binding);
        } else if (UriInfo.class.equals(type)) {
            final UriInfo binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, UriInfo.class);
            ThreadLocalContextManager.URI_INFO.set(binding);
        } else if (HttpHeaders.class.equals(type)) {
            final HttpHeaders binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpHeaders.class);
            ThreadLocalContextManager.HTTP_HEADERS.set(binding);
        } else if (SecurityContext.class.equals(type)) {
            final SecurityContext binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, SecurityContext.class);
            ThreadLocalContextManager.SECURITY_CONTEXT.set(binding);
        } else if (ContextResolver.class.equals(type)) {
            final ContextResolver<?> binding = JAXRSUtils.createContextValue(exchange.getInMessage(), type, ContextResolver.class);
            ThreadLocalContextManager.CONTEXT_RESOLVER.set(binding);
        } else if (Providers.class.equals(type)) {
            final Providers providers = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Providers.class);
            ThreadLocalContextManager.PROVIDERS.set(providers);
        } else if (ServletRequest.class.equals(type)) {
            ServletRequest servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletRequest.class);
            if (servletRequest == null) {
                // probably the case with CXF
                servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            }
            ThreadLocalContextManager.SERVLET_REQUEST.set(servletRequest);
        } else if (HttpServletRequest.class.equals(type)) {
            final HttpServletRequest httpServletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            ThreadLocalContextManager.HTTP_SERVLET_REQUEST.set(httpServletRequest);
        } else if (HttpServletResponse.class.equals(type)) {
            final HttpServletResponse httpServletResponse = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletResponse.class);
            ThreadLocalContextManager.HTTP_SERVLET_RESPONSE.set(httpServletResponse);
        } else if (ServletConfig.class.equals(type)) {
            final ServletConfig servletConfig = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletConfig.class);
            ThreadLocalContextManager.SERVLET_CONFIG.set(servletConfig);
        } else if (Configuration.class.equals(type)) {
            final Configuration config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Configuration.class);
            ThreadLocalContextManager.CONFIGURATION.set(config);
        } else if (ResourceInfo.class.equals(type)) {
            final ResourceInfo config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceInfo.class);
            ThreadLocalContextManager.RESOURCE_INFO.set(config);
        } else if (ResourceContext.class.equals(type)) {
            final ResourceContext config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceContext.class);
            ThreadLocalContextManager.RESOURCE_CONTEXT.set(config);
        } else if (Application.class.equals(type)) {
            final Application config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Application.class);
            ThreadLocalContextManager.APPLICATION.set(config);
        } else {
            final Message message = exchange.getInMessage();
            final ContextProvider<?> provider = ProviderFactory.getInstance(message).createContextProvider(type, message);
            if (provider != null) {
                final Object value = provider.createContext(message);
                Map<String, Object> map = ThreadLocalContextManager.OTHERS.get();
                if (map == null) {
                    map = new HashMap<>();
                    ThreadLocalContextManager.OTHERS.set(map);
                }
                map.put(type.getName(), value);
            }
        }
    }
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) ResourceInfo(javax.ws.rs.container.ResourceInfo) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ResourceContext(javax.ws.rs.container.ResourceContext) Configuration(javax.ws.rs.core.Configuration) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(javax.ws.rs.core.Request) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityContext(javax.ws.rs.core.SecurityContext) Application(javax.ws.rs.core.Application) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo)

Example 78 with Message

use of org.apache.cxf.message.Message in project tomee by apache.

the class WebClient method finalizeMessage.

// CHECKSTYLE:OFF
private // NOPMD
Message finalizeMessage(// NOPMD
String httpMethod, MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inGenericType, Annotation[] inAnns, Class<?> responseClass, Type outGenericType, Exchange exchange, Map<String, Object> invContext) {
    // CHECKSTYLE:ON
    URI uri = getCurrentURI();
    Message m = createMessage(body, httpMethod, headers, uri, exchange, invContext, false);
    setSupportOnewayResponseProperty(m);
    if (inAnns != null) {
        m.put(Annotation.class.getName(), inAnns);
    }
    Map<String, Object> reqContext = getRequestContext(m);
    reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
    reqContext.put(REQUEST_CLASS, requestClass);
    reqContext.put(REQUEST_TYPE, inGenericType);
    reqContext.put(REQUEST_ANNS, inAnns);
    reqContext.put(RESPONSE_CLASS, responseClass);
    reqContext.put(RESPONSE_TYPE, outGenericType);
    if (body != null) {
        m.put(Type.class, inGenericType);
    }
    m.getInterceptorChain().add(bodyWriter);
    setWebClientOperationProperty(m, httpMethod);
    return m;
}
Also used : Message(org.apache.cxf.message.Message) URI(java.net.URI) Annotation(java.lang.annotation.Annotation)

Example 79 with Message

use of org.apache.cxf.message.Message in project tomee by apache.

the class WebClient method doChainedInvocation.

// CHECKSTYLE:OFF
protected // NOPMD
Response doChainedInvocation(// NOPMD
String httpMethod, MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inType, Annotation[] inAnns, Class<?> respClass, Type outType, Exchange exchange, Map<String, Object> invContext) {
    // CHECKSTYLE:ON
    Bus configuredBus = getConfiguration().getBus();
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
    ClassLoaderHolder origLoader = null;
    try {
        ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType, inAnns, respClass, outType, exchange, invContext);
        doRunInterceptorChain(m);
        return doResponse(m, respClass, outType);
    } finally {
        if (origLoader != null) {
            origLoader.reset();
        }
        if (origBus != configuredBus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Example 80 with Message

use of org.apache.cxf.message.Message in project tomee by apache.

the class MediaTypeHeaderProvider method handleMediaTypeWithoutSubtype.

private static MediaType handleMediaTypeWithoutSubtype(String mType) {
    if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
        String mTypeNext = mType.length() == 1 ? "" : mType.substring(1).trim();
        boolean mTypeNextEmpty = StringUtils.isEmpty(mTypeNext);
        if (mTypeNextEmpty || mTypeNext.startsWith(";")) {
            if (!mTypeNextEmpty) {
                Map<String, String> parameters = new LinkedHashMap<>();
                StringTokenizer st = new StringTokenizer(mType.substring(2).trim(), ";");
                while (st.hasMoreTokens()) {
                    addParameter(parameters, st.nextToken());
                }
                return new MediaType(MediaType.MEDIA_TYPE_WILDCARD, MediaType.MEDIA_TYPE_WILDCARD, parameters);
            }
            return MediaType.WILDCARD_TYPE;
        }
    }
    Message message = PhaseInterceptorChain.getCurrentMessage();
    if (message != null && !MessageUtils.getContextualBoolean(message, STRICT_MEDIA_TYPE_CHECK, false)) {
        final MediaType mt;
        if (mType.equals(MediaType.TEXT_PLAIN_TYPE.getType())) {
            mt = MediaType.TEXT_PLAIN_TYPE;
        } else if (mType.equals(MediaType.APPLICATION_XML_TYPE.getSubtype())) {
            mt = MediaType.APPLICATION_XML_TYPE;
        } else {
            mt = MediaType.WILDCARD_TYPE;
        }
        LOG.fine("Converting a malformed media type '" + mType + "' to '" + typeToString(mt) + "'");
        return mt;
    }
    throw new IllegalArgumentException("Media type separator is missing");
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(org.apache.cxf.message.Message) MediaType(javax.ws.rs.core.MediaType) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Message (org.apache.cxf.message.Message)1002 Test (org.junit.Test)507 MessageImpl (org.apache.cxf.message.MessageImpl)291 Exchange (org.apache.cxf.message.Exchange)199 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)169 Endpoint (org.apache.cxf.endpoint.Endpoint)91 Interceptor (org.apache.cxf.interceptor.Interceptor)87 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)85 ArrayList (java.util.ArrayList)83 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)76 List (java.util.List)75 IOException (java.io.IOException)73 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)73 Method (java.lang.reflect.Method)69 Bus (org.apache.cxf.Bus)69 QName (javax.xml.namespace.QName)62 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)55 HashMap (java.util.HashMap)53 Fault (org.apache.cxf.interceptor.Fault)51 ByteArrayInputStream (java.io.ByteArrayInputStream)49