Search in sources :

Example 6 with MessageBodyReader

use of javax.ws.rs.ext.MessageBodyReader in project jersey by jersey.

the class JaxbStringReaderProviderTest method stringReaderDoesNotReadExternalDtds.

@Test
public void stringReaderDoesNotReadExternalDtds() {
    Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {

        final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));

        @Override
        public SAXParserFactory get() {
            return spf.get();
        }
    };
    JaxbStringReaderProvider.RootElementProvider provider = new JaxbStringReaderProvider.RootElementProvider(saxParserFactoryProvider, new Providers() {

        @Override
        public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
            return null;
        }

        @Override
        public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
            return null;
        }
    });
    String content = "<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>";
    provider.getConverter(RootObject.class, null, null).fromString(content);
}
Also used : CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) Providers(javax.ws.rs.ext.Providers) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) RuntimeType(javax.ws.rs.RuntimeType) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MediaType(javax.ws.rs.core.MediaType) ContextResolver(javax.ws.rs.ext.ContextResolver) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 7 with MessageBodyReader

use of javax.ws.rs.ext.MessageBodyReader in project jersey by jersey.

the class MessageBodyFactory method addReaders.

private static void addReaders(final List<ReaderModel> models, final Set<MessageBodyReader> readers, final boolean custom) {
    for (final MessageBodyReader provider : readers) {
        final List<MediaType> values = MediaTypes.createFrom(provider.getClass().getAnnotation(Consumes.class));
        models.add(new ReaderModel(provider, values, custom));
    }
}
Also used : MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) Consumes(javax.ws.rs.Consumes) MediaType(javax.ws.rs.core.MediaType) ReaderModel(org.glassfish.jersey.message.ReaderModel)

Example 8 with MessageBodyReader

use of javax.ws.rs.ext.MessageBodyReader in project jersey by jersey.

the class MessageBodyFactory method _getMessageBodyReader.

@SuppressWarnings("unchecked")
private <T> MessageBodyReader<T> _getMessageBodyReader(final Class<T> c, final Type t, final Annotation[] as, final MediaType mediaType, final MediaType lookup, final PropertiesDelegate propertiesDelegate) {
    final List<MessageBodyReader> readers = readersCache.get(lookup);
    if (readers == null) {
        return null;
    }
    final TracingLogger tracingLogger = TracingLogger.getInstance(propertiesDelegate);
    MessageBodyReader<T> selected = null;
    final Iterator<MessageBodyReader> iterator = readers.iterator();
    while (iterator.hasNext()) {
        final MessageBodyReader p = iterator.next();
        if (isReadable(p, c, t, as, mediaType)) {
            selected = (MessageBodyReader<T>) p;
            tracingLogger.log(MsgTraceEvent.MBR_SELECTED, selected);
            break;
        }
        tracingLogger.log(MsgTraceEvent.MBR_NOT_READABLE, p);
    }
    if (tracingLogger.isLogEnabled(MsgTraceEvent.MBR_SKIPPED)) {
        while (iterator.hasNext()) {
            final MessageBodyReader p = iterator.next();
            tracingLogger.log(MsgTraceEvent.MBR_SKIPPED, p);
        }
    }
    return selected;
}
Also used : MessageBodyReader(javax.ws.rs.ext.MessageBodyReader)

Example 9 with MessageBodyReader

use of javax.ws.rs.ext.MessageBodyReader in project jersey by jersey.

the class ProviderBinderTest method testProvidersMbr.

@Test
public void testProvidersMbr() {
    InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
    ProviderBinder providerBinder = new ProviderBinder(injectionManager);
    providerBinder.bindClasses(Collections.singleton(MyProvider.class));
    Set<MessageBodyReader> providers = Providers.getCustomProviders(injectionManager, MessageBodyReader.class);
    assertEquals(1, instancesOfType(MyProvider.class, providers).size());
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 10 with MessageBodyReader

use of javax.ws.rs.ext.MessageBodyReader in project jersey by jersey.

the class ProviderBinderTest method testProvidersMbrInstance.

@Test
public void testProvidersMbrInstance() {
    InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
    ProviderBinder providerBinder = new ProviderBinder(injectionManager);
    providerBinder.bindInstances(Collections.singleton(new MyProvider()));
    Set<MessageBodyReader> providers = Providers.getCustomProviders(injectionManager, MessageBodyReader.class);
    assertEquals(1, instancesOfType(MyProvider.class, providers).size());
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)10 Test (org.junit.Test)5 MediaType (javax.ws.rs.core.MediaType)4 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)4 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 Type (java.lang.reflect.Type)2 ProviderBinder (org.glassfish.jersey.internal.inject.ProviderBinder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Provider (javax.inject.Provider)1 Consumes (javax.ws.rs.Consumes)1 RuntimeType (javax.ws.rs.RuntimeType)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 ContextResolver (javax.ws.rs.ext.ContextResolver)1 ExceptionMapper (javax.ws.rs.ext.ExceptionMapper)1