Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyWriter


   public void doWrite(Object toOutput, Class type, Type genericType,
                       MediaType mediaType, Annotation[] annotations,
                       MultivaluedMap<String, Object> requestHeaders,
                       OutputStream outputStream) throws IOException
   {
      MessageBodyWriter writer = factory.getMessageBodyWriter(type,
              genericType, annotations, mediaType);
      if (writer == null)
         throw createWriterNotFound(genericType, mediaType);

      final Map<String, Object> attributes = new HashMap<String, Object>();
View Full Code Here


      addMessageBodyWriter(provider, false);
   }

   public void addMessageBodyWriter(Class<? extends MessageBodyWriter> provider, boolean isBuiltin)
   {
      MessageBodyWriter writer = getProviderInstance(provider);
      addMessageBodyWriter(writer, isBuiltin);
   }
View Full Code Here

         generic = ge.getType();
         ent = ge.getEntity();
         type = ent.getClass();
      }
      MediaType contentType = resolveContentType();
      MessageBodyWriter writer = providerFactory.getMessageBodyWriter(
              type, generic, annotations, contentType);

      if (writer == null)
      {
         throw new NoMessageBodyWriterFoundFailure(type, contentType);
      }

      try
      {
         response.setStatus(getStatus());
         final HttpResponse theResponse = response;
         CommitHeaderOutputStream.CommitCallback callback = new CommitHeaderOutputStream.CommitCallback()
         {
            private boolean committed;

            @Override
            public void commit()
            {
               if (committed) return;
               committed = true;
               commitHeaders(theResponse);
            }
         };
         OutputStream os = new CommitHeaderOutputStream(response.getOutputStream(), callback);

         long size = writer.getSize(ent, type, generic, annotations, contentType);
         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

      {
         setWriterInterceptors(providerFactory
                 .getClientMessageBodyWriterInterceptorRegistry().bindForList(
                         null, null));
      }
      MessageBodyWriter writer = providerFactory
              .getMessageBodyWriter(bodyType, bodyGenericType,
                      bodyAnnotations, bodyContentType);
      if (writer == null)
      {
         throw new RuntimeException("could not find writer for content-type "
View Full Code Here

   }

   private void verifyPlainWriter(ResteasyProviderFactory factory)
   {
      MessageBodyWriter writer2 = factory.getMessageBodyWriter(Integer.class, null, null, MediaType.TEXT_PLAIN_TYPE);
      Assert.assertNotNull(writer2);
      Assert.assertTrue(writer2 instanceof PlainTextWriter);
   }
View Full Code Here

      Assert.assertTrue(writer2 instanceof PlainTextWriter);
   }

   private void verifyIntegerWriter(ResteasyProviderFactory factory)
   {
      MessageBodyWriter writer2;// Test that type specific template providers take precedence over others
      writer2 = factory.getMessageBodyWriter(Integer.class, null, null, MediaType.TEXT_PLAIN_TYPE);
      Assert.assertNotNull(writer2);
      Assert.assertTrue(writer2.getClass().getName(), writer2 instanceof IntegerPlainTextWriter);
   }
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()));
       
        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);
        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
    }
View Full Code Here

    private static class MessageBodyWriterComparator
        implements Comparator<ProviderInfo<MessageBodyWriter>> {
       
        public int compare(ProviderInfo<MessageBodyWriter> p1,
                           ProviderInfo<MessageBodyWriter> p2) {
            MessageBodyWriter e1 = p1.getProvider();
            MessageBodyWriter e2 = p2.getProvider();
           
            ProduceMime c = e1.getClass().getAnnotation(ProduceMime.class);
            String[] mimeType1 = {"*/*"};
            if (c != null) {
                mimeType1 = c.value();              
            }
           
            ProduceMime c2 = e2.getClass().getAnnotation(ProduceMime.class);
            String[] mimeType2 = {"*/*"};
            if (c2 != null) {
                mimeType2 = c2.value();              
            }
   
View Full Code Here

            return;
        }
       
        MediaType contentType = MediaType.valueOf(headers.getFirst("Content-Type"));
       
        MessageBodyWriter mbw = ProviderFactory.getInstance(outMessage).createMessageBodyWriter(
            cls, type, anns, contentType, outMessage);
        if (mbw == null) {
            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

    private static class MessageBodyWriterComparator
        implements Comparator<ProviderInfo<MessageBodyWriter>> {
       
        public int compare(ProviderInfo<MessageBodyWriter> p1,
                           ProviderInfo<MessageBodyWriter> p2) {
            MessageBodyWriter e1 = p1.getProvider();
            MessageBodyWriter e2 = p2.getProvider();
           
            List<MediaType> types1 =
                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e1));
            List<MediaType> types2 =
                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e2));
View Full Code Here

TOP

Related Classes of javax.ws.rs.ext.MessageBodyWriter

Copyright © 2018 www.massapicom. 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.