Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyReader


            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


            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

            }
            else
            {
               MediaType contentType = context.getContainerRequest().getMediaType();

               MessageBodyReader entityReader =
                  context.getProviders().getMessageBodyReader(mp.getParameterClass(), mp.getGenericType(),
                     mp.getAnnotations(), contentType);
               if (entityReader == null)
               {
                  List<String> contentLength =
                     context.getContainerRequest().getRequestHeader(HttpHeaders.CONTENT_LENGTH);
                  int length = 0;
                  if (contentLength != null && contentLength.size() > 0)
                  {
                     length = Integer.parseInt(contentLength.get(0));
                  }

                  if (contentType == null && length == 0)
                  {
                     // If both Content-Length and Content-Type is not set
                     // consider there is no content. In this case we not able
                     // to determine reader required for content but
                     // 'Unsupported Media Type' (415) status looks strange if
                     // there is no content at all.
                     p[i++] = null;
                  }
                  else
                  {
                     String msg =
                        "Media type " + contentType + " is not supported. There is no corresponded entity reader.";
                     if (LOG.isDebugEnabled())
                     {
                        LOG.warn(msg);
                     }
                     throw new WebApplicationException(Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity(
                        msg).type(MediaType.TEXT_PLAIN).build());
                  }
               }
               else
               {
                  try
                  {
                     MultivaluedMap<String, String> headers = context.getContainerRequest().getRequestHeaders();
                     p[i++] =
                        entityReader.readFrom(mp.getParameterClass(), mp.getGenericType(), mp.getAnnotations(),
                           contentType, headers, entityStream);
                  }
                  catch (Exception e)
                  {
                     if (LOG.isDebugEnabled())
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

    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

            }
        }
       
        MediaType contentType = getResponseContentType(r);
       
        MessageBodyReader mbr = ProviderFactory.getInstance(outMessage).createMessageBodyReader(
            cls, type, anns, contentType, outMessage);
        if (mbr != null) {
            try {
                return mbr.readFrom(cls, type, anns, contentType,
                       new MetadataMap<String, Object>(r.getMetadata(), true, true), inputStream);
            } catch (Exception ex) {
                reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, contentType, ex, r);
            }
        } else if (cls == Response.class) {
View Full Code Here

                                                  List<MediaType> consumeTypes,
                                                  Message m) throws IOException, WebApplicationException {
       
        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) {
                    throw e;
                } catch (WebApplicationException ex) {
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

   
    @Test
    public void testSchemaLocations() {
        ProviderFactory pf = ProviderFactory.getInstance();
        pf.setSchemaLocations(Collections.singletonList("classpath:/test.xsd"));
        MessageBodyReader customJaxbReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, new MessageImpl());
        assertTrue(customJaxbReader instanceof JAXBElementProvider);
        MessageBodyReader jaxbReader = ProviderFactory.getSharedInstance().createMessageBodyReader(
            (Class<?>)Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
        assertTrue(jaxbReader instanceof JAXBElementProvider);
        assertNotSame(jaxbReader, customJaxbReader);
       
        assertNull(((JAXBElementProvider)jaxbReader).getSchema());
        assertNotNull(((JAXBElementProvider)customJaxbReader).getSchema());
       
        MessageBodyReader customJsonReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                 MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertTrue(customJsonReader instanceof JSONProvider);
        MessageBodyReader jsonReader = ProviderFactory.getSharedInstance().createMessageBodyReader(
            (Class<?>)Book.class, null, null, MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertTrue(jsonReader instanceof JSONProvider);
        assertNotSame(jsonReader, customJsonReader);
        assertNull(((JSONProvider)jsonReader).getSchema());
        assertNotNull(((JSONProvider)customJsonReader).getSchema());
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.