Search in sources :

Example 1 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project tomee by apache.

the class CxfRsHttpListener method fixProviderIfKnown.

private void fixProviderIfKnown() {
    final ServerProviderFactory spf = ServerProviderFactory.class.cast(server.getEndpoint().get(ServerProviderFactory.class.getName()));
    for (final String field : asList("messageWriters", "messageReaders")) {
        final List<ProviderInfo<?>> values = List.class.cast(Reflections.get(spf, field));
        boolean customJsonProvider = false;
        for (final ProviderInfo<?> o : values) {
            // using getName to not suppose any classloader setup
            final String name = o.getResourceClass().getName();
            if ("org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider".equals(name) || "org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider".equals(name) || // contains in case of proxying
            name.contains("com.fasterxml.jackson.jaxrs.json")) {
                customJsonProvider = true;
                // cause we only handle json for now
                break;
            }
        }
        if (customJsonProvider) {
            // remove JohnzonProvider default versions
            final Iterator<ProviderInfo<?>> it = values.iterator();
            while (it.hasNext()) {
                final String name = it.next().getResourceClass().getName();
                if ("org.apache.johnzon.jaxrs.JohnzonProvider".equals(name) || "org.apache.openejb.server.cxf.rs.CxfRSService$TomEEJohnzonProvider".equals(name)) {
                    it.remove();
                    break;
                }
            }
        }
    }
}
Also used : ServerProviderFactory(org.apache.cxf.jaxrs.provider.ServerProviderFactory) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo)

Example 2 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project tomee by apache.

the class JAXRSUtils method runContainerResponseFilters.

public static void runContainerResponseFilters(ServerProviderFactory pf, ResponseImpl r, Message m, OperationResourceInfo ori, Method invoked) throws IOException, Throwable {
    List<ProviderInfo<ContainerResponseFilter>> containerFilters = pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
    if (!containerFilters.isEmpty()) {
        ContainerRequestContext requestContext = new ContainerRequestContextImpl(m.getExchange().getInMessage(), false, true);
        ContainerResponseContext responseContext = new ContainerResponseContextImpl(r, m, ori == null ? null : ori.getClassResourceInfo().getServiceClass(), invoked);
        for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
            InjectionUtils.injectContexts(filter.getProvider(), filter, m);
            filter.getProvider().filter(requestContext, responseContext);
        }
    }
}
Also used : ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestContextImpl(org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) ContainerResponseContextImpl(org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl)

Example 3 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project tomee by apache.

the class JAXRSUtils method createContextValue.

public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
    Message contextMessage = getContextMessage(m);
    Object o = null;
    if (UriInfo.class.isAssignableFrom(clazz)) {
        o = createUriInfo(contextMessage);
    } else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) {
        o = createHttpHeaders(contextMessage, clazz);
    } else if (SecurityContext.class.isAssignableFrom(clazz)) {
        SecurityContext customContext = contextMessage.get(SecurityContext.class);
        o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
    } else if (MessageContext.class.isAssignableFrom(clazz)) {
        o = new MessageContextImpl(m);
    } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
        o = new ResourceInfoImpl(contextMessage);
    } else if (ResourceContext.class.isAssignableFrom(clazz)) {
        OperationResourceInfo operationResourceInfo = contextMessage.getExchange().get(OperationResourceInfo.class);
        if (operationResourceInfo != null) {
            o = new ResourceContextImpl(contextMessage, operationResourceInfo);
        }
    } else if (Request.class.isAssignableFrom(clazz)) {
        o = new RequestImpl(contextMessage);
    } else if (Providers.class.isAssignableFrom(clazz)) {
        o = new ProvidersImpl(contextMessage);
    } else if (ContextResolver.class.isAssignableFrom(clazz)) {
        o = createContextResolver(genericType, contextMessage);
    } else if (Configuration.class.isAssignableFrom(clazz)) {
        o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
    } else if (Application.class.isAssignableFrom(clazz)) {
        ProviderInfo<?> providerInfo = (ProviderInfo<?>) contextMessage.getExchange().getEndpoint().get(Application.class.getName());
        o = providerInfo == null ? null : providerInfo.getProvider();
    } else if (contextMessage != null) {
        ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
        if (provider != null) {
            o = provider.createContext(contextMessage);
        }
    }
    if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
        o = HttpUtils.createServletResourceValue(contextMessage, clazz);
    }
    return clazz.cast(o);
}
Also used : SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) ResourceContext(javax.ws.rs.container.ResourceContext) Message(org.apache.cxf.message.Message) Configuration(javax.ws.rs.core.Configuration) ResourceInfoImpl(org.apache.cxf.jaxrs.impl.ResourceInfoImpl) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) ProvidersImpl(org.apache.cxf.jaxrs.impl.ProvidersImpl) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) SecurityContext(javax.ws.rs.core.SecurityContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) ResourceContextImpl(org.apache.cxf.jaxrs.impl.ResourceContextImpl) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) MessageContextImpl(org.apache.cxf.jaxrs.ext.MessageContextImpl)

Example 4 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project tomee by apache.

the class JAXRSUtils method runContainerRequestFilters.

public static boolean runContainerRequestFilters(ServerProviderFactory pf, Message m, boolean preMatch, Set<String> names) throws IOException {
    List<ProviderInfo<ContainerRequestFilter>> containerFilters = preMatch ? pf.getPreMatchContainerRequestFilters() : pf.getPostMatchContainerRequestFilters(names);
    if (!containerFilters.isEmpty()) {
        ContainerRequestContext context = new ContainerRequestContextImpl(m, preMatch, false);
        for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
            InjectionUtils.injectContexts(filter.getProvider(), filter, m);
            filter.getProvider().filter(context);
            Response response = m.getExchange().get(Response.class);
            if (response != null) {
                setMessageContentType(m, response);
                return true;
            }
        }
    }
    return false;
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestContextImpl(org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter)

Example 5 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project tomee by apache.

the class ProviderFactory method createMessageBodyReaderInterceptor.

public <T> List<ReaderInterceptor> createMessageBodyReaderInterceptor(Class<T> bodyType, Type parameterType, Annotation[] parameterAnnotations, MediaType mediaType, Message m, boolean checkMbrNow, Set<String> names) {
    MessageBodyReader<T> mr = !checkMbrNow ? null : createMessageBodyReader(bodyType, parameterType, parameterAnnotations, mediaType, m);
    int size = readerInterceptors.size();
    if (mr != null || size > 0) {
        ReaderInterceptor mbrReader = new ReaderInterceptorMBR(mr, getResponseMessage(m));
        final List<ReaderInterceptor> interceptors;
        if (size > 0) {
            interceptors = new ArrayList<>(size + 1);
            List<ProviderInfo<ReaderInterceptor>> readers = getBoundFilters(readerInterceptors, names);
            for (ProviderInfo<ReaderInterceptor> p : readers) {
                injectContextValues(p, m);
                interceptors.add(p.getProvider());
            }
            interceptors.add(mbrReader);
        } else {
            interceptors = Collections.singletonList(mbrReader);
        }
        return interceptors;
    }
    return null;
}
Also used : ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) FilterProviderInfo(org.apache.cxf.jaxrs.model.FilterProviderInfo) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ReaderInterceptorMBR(org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR) Endpoint(org.apache.cxf.endpoint.Endpoint)

Aggregations

ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)26 Endpoint (org.apache.cxf.endpoint.Endpoint)9 FilterProviderInfo (org.apache.cxf.jaxrs.model.FilterProviderInfo)7 Response (javax.ws.rs.core.Response)6 Message (org.apache.cxf.message.Message)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Comparator (java.util.Comparator)4 Map (java.util.Map)4 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 List (java.util.List)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)3 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)3 ReaderInterceptor (javax.ws.rs.ext.ReaderInterceptor)3 Bus (org.apache.cxf.Bus)3 ContainerRequestContextImpl (org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl)3 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)3 File (java.io.File)2