Package javax.ws.rs.ext

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


        MultivaluedMap<String, Object> headers = new MetadataMap<String, Object>();
       
        String eWithAcute = "\u00E9";
        String helloStringUTF16 = "Hello, my name is F" + eWithAcute + "lix Agn" + eWithAcute + "s";
       
        p.writeTo(helloStringUTF16,
                  String.class, String.class, null, MediaType.valueOf("text/plain;charset=ISO-8859-1"),
                  headers, os);
       
        byte[] iso88591bytes = helloStringUTF16.getBytes("ISO-8859-1");
        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
View Full Code Here


    @SuppressWarnings("unchecked")
    @Test
    public void testWriteBoolean() throws Exception {
        MessageBodyWriter p = new PrimitiveTextProvider();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        p.writeTo(Boolean.TRUE, null, null, null, null, null, os);
        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
       
        os = new ByteArrayOutputStream();
       
        final boolean value = true;
View Full Code Here

        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
       
        os = new ByteArrayOutputStream();
       
        final boolean value = true;
        p.writeTo(value, null, null, null, null, null, os);
        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
    }
}
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, null, 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, null, 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, null, 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, null, null, null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
       
        Reader r = new StringReader("hi");
        os = new ByteArrayOutputStream();
        p.writeTo(r, null, null, null, MediaType.valueOf("text/xml"), null, os);
View Full Code Here

        p.writeTo(is, null, null, null, null, null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
       
        Reader r = new StringReader("hi");
        os = new ByteArrayOutputStream();
        p.writeTo(r, null, null, null, MediaType.valueOf("text/xml"), null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
       
        os = new ByteArrayOutputStream();
        p.writeTo(new StreamingOutputImpl(), null, null, null,
                  MediaType.valueOf("text/xml"), null, os);
View Full Code Here

        os = new ByteArrayOutputStream();
        p.writeTo(r, null, null, null, MediaType.valueOf("text/xml"), null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
       
        os = new ByteArrayOutputStream();
        p.writeTo(new StreamingOutputImpl(), null, null, null,
                  MediaType.valueOf("text/xml"), null, os);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
    }

   
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(responseObj, targetType,
                               invoked != null ? invoked.getGenericReturnType() : null,
                               invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                               responseType,
                               response.getMetadata(),
                               message.getContent(OutputStream.class));
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

            if (writer == null) {
                throw new RuntimeException(Messages.getMessage("clientNoWriterForTypeAndMediaType", //$NON-NLS-1$
                                                               String.valueOf(type),
                                                               contentType));
            }
            writer.writeTo(entity,
                           type,
                           genericType,
                           null,
                           contentMediaType,
                           request.getHeaders(),
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.