Package javax.ws.rs.ext

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


         if (size > -1) response.getOutputHeaders().putSingle(HttpHeaderNames.CONTENT_LENGTH, String.valueOf(size));


         if (messageBodyWriterInterceptors == null || messageBodyWriterInterceptors.length == 0)
         {
            writer.writeTo(ent, type, generic, annotations,
                    contentType, getMetadata(), os);
         }
         else
         {
            ServerMessageBodyWriterContext ctx = new ServerMessageBodyWriterContext(messageBodyWriterInterceptors, writer, ent, type, generic,
View Full Code Here


      Class<?> entityType = part.getType();
      Type entityGenericType = part.getGenericType();
      MessageBodyWriter writer = workers.getMessageBodyWriter(entityType, entityGenericType, null, part.getMediaType());
      long size = writer.getSize(entity, entityType, entityGenericType, null, part.getMediaType());
      if (size > -1) headers.putSingle(HttpHeaderNames.CONTENT_LENGTH, Integer.toString((int) size));
      writer.writeTo(entity, entityType, entityGenericType, null, part.getMediaType(), headers, new HeaderFlushedOutputStream(headers, entityStream));
      entityStream.write("\r\n".getBytes());
   }
}
View Full Code Here

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @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

            mbw = ProviderFactory.getInstance().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) {
                throw new WebApplicationException(ex);
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 (writer == null) {
                throw new RuntimeException(String.format("No writer for type %s and media type %s",
                                                         String.valueOf(type),
                                                         contentType));
            }
            writer.writeTo(entity,
                           type,
                           genericType,
                           null,
                           contentMediaType,
                           request.getHeaders(),
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;
        } catch (WebApplicationException e) {
            throw e;
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.