use of javax.ws.rs.ext.MessageBodyWriter in project jersey by jersey.
the class MessageBodyFactory method addWriters.
private static void addWriters(final List<WriterModel> models, final Set<MessageBodyWriter> writers, final boolean custom) {
for (final MessageBodyWriter provider : writers) {
final List<MediaType> values = MediaTypes.createFrom(provider.getClass().getAnnotation(Produces.class));
models.add(new WriterModel(provider, values, custom));
}
}
use of javax.ws.rs.ext.MessageBodyWriter in project jersey by jersey.
the class MessageBodyFactory method _getMessageBodyWriter.
@SuppressWarnings("unchecked")
private <T> MessageBodyWriter<T> _getMessageBodyWriter(final Class<T> c, final Type t, final Annotation[] as, final MediaType mediaType, final MediaType lookup, final PropertiesDelegate propertiesDelegate) {
final List<MessageBodyWriter> writers = writersCache.get(lookup);
if (writers == null) {
return null;
}
final TracingLogger tracingLogger = TracingLogger.getInstance(propertiesDelegate);
MessageBodyWriter<T> selected = null;
final Iterator<MessageBodyWriter> iterator = writers.iterator();
while (iterator.hasNext()) {
final MessageBodyWriter p = iterator.next();
if (isWriteable(p, c, t, as, mediaType)) {
selected = (MessageBodyWriter<T>) p;
tracingLogger.log(MsgTraceEvent.MBW_SELECTED, selected);
break;
}
tracingLogger.log(MsgTraceEvent.MBW_NOT_WRITEABLE, p);
}
if (tracingLogger.isLogEnabled(MsgTraceEvent.MBW_SKIPPED)) {
while (iterator.hasNext()) {
final MessageBodyWriter p = iterator.next();
tracingLogger.log(MsgTraceEvent.MBW_SKIPPED, p);
}
}
return selected;
}
use of javax.ws.rs.ext.MessageBodyWriter in project jersey by jersey.
the class ProviderBinderTest method testProvidersMbwInstance.
@Test
public void testProvidersMbwInstance() {
InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
ProviderBinder providerBinder = new ProviderBinder(injectionManager);
providerBinder.bindInstances(Collections.singleton(new MyProvider()));
Set<MessageBodyWriter> providers = Providers.getCustomProviders(injectionManager, MessageBodyWriter.class);
assertEquals(instancesOfType(MyProvider.class, providers).size(), 1);
}
use of javax.ws.rs.ext.MessageBodyWriter in project jersey by jersey.
the class ProviderBinderTest method testProvidersMbw.
@Test
public void testProvidersMbw() {
InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
ProviderBinder providerBinder = new ProviderBinder(injectionManager);
providerBinder.bindClasses(Collections.singleton(MyProvider.class));
Set<MessageBodyWriter> providers = Providers.getCustomProviders(injectionManager, MessageBodyWriter.class);
final Collection<MyProvider> myProviders = instancesOfType(MyProvider.class, providers);
assertEquals(1, myProviders.size());
}
use of javax.ws.rs.ext.MessageBodyWriter in project jersey by jersey.
the class ProviderBinderTest method testServicesMbw.
@Test
public void testServicesMbw() {
InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
Set<MessageBodyWriter> providers = Providers.getProviders(injectionManager, MessageBodyWriter.class);
assertTrue(providers.size() > 0);
}
Aggregations