Search in sources :

Example 1 with WriterInterceptorContextImpl

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

the class JAXRSUtils method writeMessageBody.

// CHECKSTYLE:OFF
public static void writeMessageBody(List<WriterInterceptor> writers, Object entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Message message) throws WebApplicationException, IOException {
    OutputStream entityStream = message.getContent(OutputStream.class);
    if (writers.size() > 1) {
        WriterInterceptor first = writers.remove(0);
        WriterInterceptorContext context = new WriterInterceptorContextImpl(entity, type, genericType, annotations, entityStream, message, writers);
        first.aroundWriteTo(context);
    } else {
        MessageBodyWriter<Object> writer = ((WriterInterceptorMBW) writers.get(0)).getMBW();
        if (type == byte[].class) {
            long size = writer.getSize(entity, type, genericType, annotations, mediaType);
            if (size != -1) {
                httpHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
            }
        }
        HttpUtils.convertHeaderValuesToString(httpHeaders, true);
        writer.writeTo(entity, type, genericType, annotations, mediaType, httpHeaders, entityStream);
    }
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) WriterInterceptorMBW(org.apache.cxf.jaxrs.impl.WriterInterceptorMBW) OutputStream(java.io.OutputStream) WriterInterceptorContextImpl(org.apache.cxf.jaxrs.impl.WriterInterceptorContextImpl)

Aggregations

OutputStream (java.io.OutputStream)1 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)1 WriterInterceptorContext (javax.ws.rs.ext.WriterInterceptorContext)1 WriterInterceptorContextImpl (org.apache.cxf.jaxrs.impl.WriterInterceptorContextImpl)1 WriterInterceptorMBW (org.apache.cxf.jaxrs.impl.WriterInterceptorMBW)1