Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyWriter


   
    @Test
    public void testGetBinaryProvider() throws Exception {
        verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
        verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
        MessageBodyWriter writer = ProviderFactory.getInstance()
            .createMessageBodyWriter(File.class, null, null, MediaType.APPLICATION_OCTET_STREAM_TYPE,
                                     new MessageImpl());
        assertTrue(BinaryDataProvider.class == writer.getClass());
    }
View Full Code Here


        MediaType mType = MediaType.valueOf(mediaType);
       
        MessageBodyReader reader = pf.createMessageBodyReader(type, type, null, mType, new MessageImpl());
        assertSame("Unexpected provider found", provider, reader.getClass());
   
        MessageBodyWriter writer = pf.createMessageBodyWriter(type, type, null, mType, new MessageImpl());
        assertTrue("Unexpected provider found", provider == writer.getClass());
    }
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

            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

        if (genericType instanceof TypeVariable) {
            genericType = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),
                                                       (TypeVariable)genericType);
        }
       
        MessageBodyWriter writer = null;
        MediaType responseType = null;
        for (MediaType type : availableContentTypes) {
            writer = ProviderFactory.getInstance(message)
                .createMessageBodyWriter(targetType, genericType,
                      invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                      type,
                      message);
           
            if (writer != null) {
                responseType = type;
                break;
            }
        }
   
        OutputStream outOriginal = message.getContent(OutputStream.class);
        if (writer == null) {
            message.put(Message.CONTENT_TYPE, "text/plain");
            message.put(Message.RESPONSE_CODE, 500);
            writeResponseErrorMessage(outOriginal, "NO_MSG_WRITER", targetType.getSimpleName());
            return;
        }
        boolean enabled = checkBufferingMode(message, writer, firstTry);
        Object entity = getEntity(responseObj);
        try {
            responseType = checkFinalContentType(responseType);
            LOG.fine("Response content type is: " + responseType.toString());
            message.put(Message.CONTENT_TYPE, responseType.toString());
           
            Annotation[] annotations = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
           
            long size = writer.getSize(entity, targetType, genericType, annotations, responseType);
            if (size > 0) {
                LOG.fine("Setting ContentLength to " + size + " as requested by "
                         + writer.getClass().getName());
                responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
            }
           
            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

      {
         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

      addMessageBodyWriter(provider, false);
   }

   public void addMessageBodyWriter(Class<? extends MessageBodyWriter> provider, boolean isBuiltin)
   {
      MessageBodyWriter writer = null;
      try
      {
         writer = provider.newInstance();
      }
      catch (InstantiationException e)
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

      {
         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

         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
      {
         outputHeaders(response);
         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, response.getOutputHeaders(), response
                            .getOutputStream());
         }
         else
         {
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.