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);
}
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));
}
}
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;
}
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());
}
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());
}
Aggregations