Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyWriter.writeTo()


            if (bodyWriter == null) {
                throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBW(bodyClass, mediaType));
            }

            bodyWriter.writeTo(
                    bodyEntity,
                    bodyClass,
                    bodyClass,
                    EMPTY_ANNOTATIONS,
                    bodyMediaType,
View Full Code Here


                logger
                    .error(Messages.getMessage("couldNotFindWriter", getBody().getClass(), //$NON-NLS-1$
                           getContentType()));
                throw new WebApplicationException(500);
            }
            writer.writeTo(getBody(), getBody().getClass(), null, null, MediaType
                .valueOf(getContentType()), getHeaders(), os);
        }
    }

    /**
 
View Full Code Here

        MessageBodyWriter writer =
            providers.getMessageBodyWriter(type, genericType, null, mediaType);
        if (writer == null) {
            return null;
        }
        writer.writeTo(object, type, genericType, new Annotation[0], mediaType, httpHeaders, os);
        String contentString = os.toString(getCharset(mediaType));
        return contentString;
    }

    public static <T> T readFromString(Providers providers,
View Full Code Here

            mbw = ProviderFactory.getInstance().createMessageBodyWriter(
                      cls, type, anns, contentType, m);
        }
        if (mbw != null) {
            try {
                mbw.writeTo(o, cls, type, anns, contentType, headers, os);
                os.flush();
            } catch (Exception ex) {
                throw new WebApplicationException();
            }
            
View Full Code Here

            LOG.fine("Response content type is: " + responseType.toString());
            message.put(Message.CONTENT_TYPE, responseType.toString());
           
            LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
            try {
                writer.writeTo(entity, targetType, genericType,
                               invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                               responseType,
                               responseHeaders,
                               message.getContent(OutputStream.class));
                Object newContentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
View Full Code Here

        ParameterizedType actualGenericType = (ParameterizedType) genericType;

        MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entity.get().getClass(),
                actualGenericType.getActualTypeArguments()[0], annotations, mediaType);
        writer.writeTo(entity.get(), entity.get().getClass(),
                actualGenericType.getActualTypeArguments()[0],
                annotations, mediaType, httpHeaders, entityStream);
    }

}
View Full Code Here

            final MediaType eventMediaType =
                    outboundEvent.getMediaType() == null ? MediaType.TEXT_PLAIN_TYPE : outboundEvent.getMediaType();
            final MessageBodyWriter messageBodyWriter = workersProvider.get().getMessageBodyWriter(outboundEvent.getType(),
                    outboundEvent.getGenericType(), annotations, eventMediaType);
            messageBodyWriter.writeTo(
                    outboundEvent.getData(),
                    outboundEvent.getType(),
                    outboundEvent.getGenericType(),
                    annotations,
                    eventMediaType,
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MessageBodyWriter bodyWriter =
                workers.getMessageBodyWriter(bean.getClass(), bean.getClass(),
                        new Annotation[0], MediaType.APPLICATION_JSON_TYPE);

        bodyWriter.writeTo(bean, bean.getClass(), bean.getClass(),
                new Annotation[0], MediaType.APPLICATION_JSON_TYPE,
                new MultivaluedHashMap<String, Object>(), baos);


        // Use the Jackson 2.x classes to convert both the incoming patch
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testWriteTo() throws Exception {
        MessageBodyWriter p = new BinaryDataProvider();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        p.writeTo(new byte[]{'h', 'i'}, null, null, os);
        assertTrue(Arrays.equals(new String("hi").getBytes(), os.toByteArray()));
        ByteArrayInputStream is = new ByteArrayInputStream("hi".getBytes());
        os = new ByteArrayOutputStream();
        p.writeTo(is, null, null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
View Full Code Here

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        p.writeTo(new byte[]{'h', 'i'}, null, null, os);
        assertTrue(Arrays.equals(new String("hi").getBytes(), os.toByteArray()));
        ByteArrayInputStream is = new ByteArrayInputStream("hi".getBytes());
        os = new ByteArrayOutputStream();
        p.writeTo(is, null, null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
    }

}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.