Search in sources :

Example 1 with ReaderInterceptorMBR

use of org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR 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)

Example 2 with ReaderInterceptorMBR

use of org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR in project cxf 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)

Example 3 with ReaderInterceptorMBR

use of org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR in project tomee by apache.

the class JAXRSUtils method readFromMessageBodyReader.

@SuppressWarnings("unchecked")
public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers, Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType mediaType, Message m) throws IOException, WebApplicationException {
    // Verbose but avoids an extra context instantiation for the typical path
    if (readers.size() > 1) {
        ReaderInterceptor first = readers.remove(0);
        ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass, parameterType, parameterAnnotations, is, m, readers);
        return first.aroundReadFrom(context);
    }
    MessageBodyReader<?> provider = ((ReaderInterceptorMBR) readers.get(0)).getMBR();
    @SuppressWarnings("rawtypes") Class cls = targetTypeClass;
    return provider.readFrom(cls, parameterType, parameterAnnotations, mediaType, new HttpHeadersImpl(m).getRequestHeaders(), is);
}
Also used : ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) ReaderInterceptorContextImpl(org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl) ReaderInterceptorMBR(org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR) ReaderInterceptorContext(javax.ws.rs.ext.ReaderInterceptorContext) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 4 with ReaderInterceptorMBR

use of org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR in project cxf by apache.

the class JAXRSUtils method readFromMessageBodyReader.

@SuppressWarnings("unchecked")
public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers, Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType mediaType, Message m) throws IOException, WebApplicationException {
    // Verbose but avoids an extra context instantiation for the typical path
    if (readers.size() > 1) {
        ReaderInterceptor first = readers.remove(0);
        ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass, parameterType, parameterAnnotations, is, m, readers);
        return first.aroundReadFrom(context);
    }
    MessageBodyReader<?> provider = ((ReaderInterceptorMBR) readers.get(0)).getMBR();
    @SuppressWarnings("rawtypes") Class cls = targetTypeClass;
    return provider.readFrom(cls, parameterType, parameterAnnotations, mediaType, new HttpHeadersImpl(m).getRequestHeaders(), is);
}
Also used : ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) ReaderInterceptorContextImpl(org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl) ReaderInterceptorMBR(org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR) ReaderInterceptorContext(javax.ws.rs.ext.ReaderInterceptorContext) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Aggregations

ReaderInterceptor (javax.ws.rs.ext.ReaderInterceptor)4 ReaderInterceptorMBR (org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR)4 ReaderInterceptorContext (javax.ws.rs.ext.ReaderInterceptorContext)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 HttpHeadersImpl (org.apache.cxf.jaxrs.impl.HttpHeadersImpl)2 ReaderInterceptorContextImpl (org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl)2 FilterProviderInfo (org.apache.cxf.jaxrs.model.FilterProviderInfo)2 ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)2