Search in sources :

Example 1 with ReaderInterceptor

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);
    }
}
Also used : ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with ReaderInterceptor

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());
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) IdentityHashMap(java.util.IdentityHashMap) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

ReaderInterceptor (javax.ws.rs.ext.ReaderInterceptor)2 IdentityHashMap (java.util.IdentityHashMap)1 ProcessingException (javax.ws.rs.ProcessingException)1 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)1 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)1 Test (org.junit.Test)1