use of javax.ws.rs.ext.ReaderInterceptor in project jersey by jersey.
the class ReaderInterceptorExecutor method proceed.
/**
* Starts the interceptor chain execution.
*
* @return an entity read from the stream.
*/
@Override
@SuppressWarnings("unchecked")
public Object proceed() throws IOException {
if (!interceptors.hasNext()) {
throw new ProcessingException(LocalizationMessages.ERROR_INTERCEPTOR_READER_PROCEED());
}
final ReaderInterceptor interceptor = interceptors.next();
traceBefore(interceptor, MsgTraceEvent.RI_BEFORE);
try {
return interceptor.aroundReadFrom(this);
} finally {
processedCount++;
traceAfter(interceptor, MsgTraceEvent.RI_AFTER);
}
}
use of javax.ws.rs.ext.ReaderInterceptor in project jersey by jersey.
the class CommonConfigTest method testProviderOrderDifForContracts.
@Test
@SuppressWarnings("unchecked")
public void testProviderOrderDifForContracts() throws Exception {
final Map<Class<?>, Integer> contracts = new IdentityHashMap<Class<?>, Integer>();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 2000);
config.register(MidPriorityProvider.class, contracts);
contracts.clear();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 1000);
config.register(LowPriorityProvider.class, contracts);
contracts.clear();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 3000);
config.register(HighPriorityProvider.class, contracts);
contracts.clear();
final InjectionManager injectionManager = Injections.createInjectionManager();
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> writerInterceptors = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<WriterInterceptor>());
final Iterator<WriterInterceptor> writerIterator = writerInterceptors.iterator();
assertEquals(HighPriorityProvider.class, writerIterator.next().getClass());
assertEquals(MidPriorityProvider.class, writerIterator.next().getClass());
assertEquals(LowPriorityProvider.class, writerIterator.next().getClass());
assertFalse(writerIterator.hasNext());
final Iterable<ReaderInterceptor> readerInterceptors = Providers.getAllProviders(injectionManager, ReaderInterceptor.class, new RankedComparator<ReaderInterceptor>());
final Iterator<ReaderInterceptor> readerIterator = readerInterceptors.iterator();
assertEquals(LowPriorityProvider.class, readerIterator.next().getClass());
assertEquals(MidPriorityProvider.class, readerIterator.next().getClass());
assertEquals(HighPriorityProvider.class, readerIterator.next().getClass());
assertFalse(readerIterator.hasNext());
}
Aggregations