Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyReader


                                                  List<MediaType> consumeTypes,
                                                  Message m) {
       
        List<MediaType> types = JAXRSUtils.intersectMimeTypes(consumeTypes, contentType);
       
        MessageBodyReader provider = null;
       
        for (MediaType type : types) {
            provider = ProviderFactory.getInstance()
                .createMessageBodyReader(targetTypeClass,
                                         parameterType,
                                         parameterAnnotations,
                                         type,
                                         m);
            // TODO : make the exceptions
            if (provider != null) {
                try {
                    HttpHeaders headers = new HttpHeadersImpl(m);
                    return provider.readFrom(
                              targetTypeClass, parameterType, parameterAnnotations, contentType,
                              headers.getRequestHeaders(), is);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Error deserializing input stream into target class "
View Full Code Here


                                String errorMessage)
        throws Exception {
       
        MediaType mType = MediaType.valueOf(mediaType);
       
        MessageBodyReader reader = ProviderFactory.getInstance()
            .createMessageBodyReader(type, null, null, mType, null);
        assertSame(errorMessage, provider, reader.getClass());
   
        MessageBodyWriter writer = ProviderFactory.getInstance()
            .createMessageBodyWriter(type, null, null, mType, null);
        assertTrue(errorMessage, provider == writer.getClass());
    }
View Full Code Here

            if (providers != null) {
                MediaType mediaType = runtimeContext.getHttpHeaders().getMediaType();
                if (mediaType == null) {
                    mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
                }
                MessageBodyReader mbr =
                    providers.getMessageBodyReader(paramType,
                                                   getGenericType(),
                                                   getAnnotations(),
                                                   mediaType);

                if (mbr != null) {
                    Object read =
                        mbr.readFrom(paramType,
                                     getGenericType(),
                                     getAnnotations(),
                                     mediaType,
                                     runtimeContext.getHttpHeaders().getRequestHeaders(),
                                     runtimeContext.getInputStream());
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    @Test
    public void testReadByte() throws Exception {
        MessageBodyReader p = new PrimitiveTextProvider();
       
        Byte valueRead = (Byte)p.readFrom(byte.class,
                                          null,
                                          null,
                                          null,
                                          null,
                                          new ByteArrayInputStream("1".getBytes()));
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    @Test
    public void testReadBoolean() throws Exception {
        MessageBodyReader p = new PrimitiveTextProvider();
       
        boolean valueRead = (Boolean)p.readFrom(boolean.class,
                                          null,
                                          null,
                                          null,
                                          null,
                                          new ByteArrayInputStream("true".getBytes()));
View Full Code Here

            pf = ProviderFactory.getInstance();
        }
       
        MediaType mType = MediaType.valueOf(mediaType);
       
        MessageBodyReader reader = pf.createMessageBodyReader(type, null, null, mType, new MessageImpl());
        assertSame("Unexpected provider found", provider, reader.getClass());
   
        MessageBodyWriter writer = pf.createMessageBodyWriter(type, null, null, mType, new MessageImpl());
        assertTrue("Unexpected provider found", provider == writer.getClass());
    }
View Full Code Here

            // won't happen at this stage
        }
       
        MediaType contentType = getResponseContentType(r);
       
        MessageBodyReader mbr = ProviderFactory.getInstance(inMessage).createMessageBodyReader(
            cls, type, anns, contentType, inMessage);
        if (mbr == null) {
            ProviderFactory.getInstance().createMessageBodyReader(
                cls, type, anns, contentType, inMessage);
        }
        if (mbr != null) {
            try {
                return mbr.readFrom(cls, type, anns, contentType,
                       new MetadataMap<String, Object>(r.getMetadata(), true, true), conn.getInputStream());
            } catch (Exception ex) {
                throw new WebApplicationException();
            }
            
View Full Code Here

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

                                                  List<MediaType> consumeTypes,
                                                  Message m) {
       
        List<MediaType> types = JAXRSUtils.intersectMimeTypes(consumeTypes, contentType);
       
        MessageBodyReader provider = null;
        for (MediaType type : types) {
            provider = ProviderFactory.getInstance(m)
                .createMessageBodyReader(targetTypeClass,
                                         parameterType,
                                         parameterAnnotations,
                                         type,
                                         m);
            if (provider != null) {
                try {
                    HttpHeaders headers = new HttpHeadersImpl(m);
                    return provider.readFrom(
                              targetTypeClass, parameterType, parameterAnnotations, contentType,
                              headers.getRequestHeaders(), is);
                } catch (IOException e) {
                    String errorMessage = "Error deserializing input stream into target class "
                                          + targetTypeClass.getSimpleName()
View Full Code Here

         contentType = MediaType.APPLICATION_FORM_URLENCODED_TYPE;
      }     

      MultivaluedMap<String, String> form = new MultivaluedMapImpl();     
      try {
         MessageBodyReader reader =
            context.getProviders().getMessageBodyReader(MultivaluedMap.class, formType, null, contentType);
         if (reader != null) {
            form = (MultivaluedMap<String, String>)reader.readFrom(MultivaluedMap.class, formType, null, contentType, context
               .getHttpHeaders().getRequestHeaders(), context.getContainerRequest().getEntityStream());
         }
      } catch (Exception e) {        
      }
     
View Full Code Here

TOP

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

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.