Package javax.ws.rs.ext

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


            try {
                LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
                MediaType mt = computeFinalContentTypes(availableContentTypes, writer);
                LOG.fine("Response content type is: " + mt.toString());
                message.put(Message.CONTENT_TYPE, mt.toString());
                writer.writeTo(responseObj, mt, null, out);
            } catch (IOException e) {
                e.printStackTrace();
                message.put(Message.RESPONSE_CODE, 500);
                writeResponseErrorMessage(out, "SERIALIZE_ERROR",
                                          responseObj.getClass().getSimpleName());
View Full Code Here


       
        MessageBodyWriter mbw = ProviderFactory.getInstance(outMessage).createMessageBodyWriter(
            cls, type, anns, contentType, outMessage);
        if (mbw != null) {
            try {
                mbw.writeTo(o, cls, type, anns, contentType, headers, os);
                if (os != null) {
                    os.flush();
                }
            } catch (Exception ex) {
                reportMessageHandlerProblem("MSG_WRITER_PROBLEM", cls, contentType, ex, null);
View Full Code Here

            }
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
            }
            try {
                writer.writeTo(entity, targetType, genericType,
                               annotations,
                               responseType,
                               responseHeaders,
                               message.getContent(OutputStream.class));
               
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

                responseType = checkFinalContentType(responseType);
                LOG.fine("Response content type is: " + responseType.toString());
                message.put(Message.CONTENT_TYPE, responseType.toString());
               
                LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
                writer.writeTo(responseObj, targetType, invoked.getGenericReturnType(),
                               invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                               responseType,
                               response.getMetadata(),
                               out);
               
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, MediaType.TEXT_PLAIN_TYPE, 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, MediaType.TEXT_PLAIN_TYPE, null, os);
        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
    }
   
   
    @SuppressWarnings("unchecked")
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.