Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyReader


    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


    }
   
    private void doTestDefaultJaxbProviderCloned(ProviderFactory pf, String property) {
        Message message = new MessageImpl();
        message.put(Message.QUERY_STRING, "uri=" + property);
        MessageBodyReader customJaxbReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, message);
        assertTrue(customJaxbReader instanceof JAXBElementProvider);
       
        JAXBElementProvider provider = (JAXBElementProvider)customJaxbReader;
        MessageContext mc = provider.getContext();
        assertNotNull(mc);
        UriInfo ui = mc.getUriInfo();
        MultivaluedMap<String, String> queries = ui.getQueryParameters();
        assertEquals(1, queries.size());
        List<String> uriQuery = queries.get("uri");
        assertEquals(1, uriQuery.size());
        assertEquals(property, uriQuery.get(0));
       
        MessageBodyReader customJaxbReader2 = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, message);
        assertSame(customJaxbReader, customJaxbReader2);
        
        MessageBodyWriter customJaxbWriter = pf.createMessageBodyWriter((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, message);
        assertSame(customJaxbReader, customJaxbWriter);
       
        MessageBodyReader jaxbReader = ProviderFactory.getSharedInstance().createMessageBodyReader(
            (Class<?>)Book.class, null, null, MediaType.TEXT_XML_TYPE, message);
        assertTrue(jaxbReader instanceof JAXBElementProvider);
        assertNotSame(jaxbReader, customJaxbReader);
    }
View Full Code Here

    @Test
    public void testCustomJaxbProvider() {
        ProviderFactory pf = ProviderFactory.getInstance();
        JAXBElementProvider provider = new JAXBElementProvider();
        pf.registerUserProvider(provider);
        MessageBodyReader customJaxbReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, new MessageImpl());
        assertSame(customJaxbReader, provider);
       
        MessageBodyWriter customJaxbWriter = pf.createMessageBodyWriter((Class<?>)Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, new MessageImpl());
View Full Code Here

    @Test
    public void testCustomJsonProvider() {
        ProviderFactory pf = ProviderFactory.getInstance();
        JSONProvider provider = new JSONProvider();
        pf.registerUserProvider(provider);
        MessageBodyReader customJsonReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                               MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertSame(customJsonReader, provider);
       
        MessageBodyWriter customJsonWriter = pf.createMessageBodyWriter((Class<?>)Book.class, null, null,
                                               MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
View Full Code Here

    }
   
    @Test
    public void testDefaultJsonProviderCloned() {
        ProviderFactory pf = ProviderFactory.getInstance();
        MessageBodyReader customJsonReader = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertTrue(customJsonReader instanceof JSONProvider);
       
        MessageBodyReader customJsonReader2 = pf.createMessageBodyReader((Class<?>)Book.class, null, null,
                                                MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertSame(customJsonReader, customJsonReader2);
       
        MessageBodyWriter customJsonWriter = pf.createMessageBodyWriter((Class<?>)Book.class, null, null,
                                                MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertSame(customJsonReader, customJsonWriter);
       
        MessageBodyReader jsonReader = ProviderFactory.getSharedInstance().createMessageBodyReader(
            (Class<?>)Book.class, null, null, MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
        assertTrue(jsonReader instanceof JSONProvider);
        assertNotSame(jsonReader, customJsonReader);
    }
View Full Code Here

   
    @Test
    public void testDataSourceReader() {
        ProviderFactory pf = ProviderFactory.getInstance();
        pf.registerUserProvider(new DataSourceProvider());
        MessageBodyReader reader = pf.createMessageBodyReader(
              (Class<?>)DataSource.class, null, null,
              MediaType.valueOf("image/png"), new MessageImpl());
        assertTrue(reader instanceof DataSourceProvider);
        MessageBodyReader reader2 = pf.createMessageBodyReader(
                          (Class<?>)DataHandler.class, null, null,
                          MediaType.valueOf("image/png"), new MessageImpl());
        assertSame(reader, reader2);
    }
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

            pf = ProviderFactory.getInstance();
        }
       
        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

                                                  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

    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

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.