use of javax.ws.rs.ext.WriterInterceptor in project jersey by jersey.
the class CommonConfigTest method testProviderOrderManual.
@Test
public void testProviderOrderManual() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager();
config.register(MidPriorityProvider.class, 500);
config.register(LowPriorityProvider.class, 20);
config.register(HighPriorityProvider.class, 150);
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> allProviders = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<>());
final Iterator<WriterInterceptor> iterator = allProviders.iterator();
assertEquals(LowPriorityProvider.class, iterator.next().getClass());
assertEquals(HighPriorityProvider.class, iterator.next().getClass());
assertEquals(MidPriorityProvider.class, iterator.next().getClass());
assertFalse(iterator.hasNext());
}
use of javax.ws.rs.ext.WriterInterceptor in project ddf by codice.
the class BodyWriter method writeBody.
<T> void writeBody(T o, Message outMessage, Class<?> cls, Type type, Annotation[] anns, OutputStream os) {
if (o == null) {
return;
}
@SuppressWarnings("unchecked") MultivaluedMap<String, Object> headers = (MultivaluedMap<String, Object>) outMessage.get(Message.PROTOCOL_HEADERS);
@SuppressWarnings("unchecked") Class<T> theClass = (Class<T>) cls;
MediaType contentType = JAXRSUtils.toMediaType(headers.getFirst("Content-Type").toString());
List<WriterInterceptor> writers = ClientProviderFactory.getInstance(outMessage).createMessageBodyWriterInterceptor(theClass, type, anns, contentType, outMessage, null);
if (writers != null) {
try {
JAXRSUtils.writeMessageBody(writers, o, theClass, type, anns, contentType, headers, outMessage);
OutputStream realOs = outMessage.get(OutputStream.class);
if (realOs != null) {
realOs.flush();
}
} catch (Exception ex) {
LOGGER.debug("Unable to write message body for final ECP response.");
}
} else {
LOGGER.debug("No writers available for final ECP response");
}
}
use of javax.ws.rs.ext.WriterInterceptor in project jersey by jersey.
the class WriterInterceptorExecutor method proceed.
/**
* Starts the interceptor chain execution.
*/
@Override
@SuppressWarnings("unchecked")
public void proceed() throws IOException {
final WriterInterceptor nextInterceptor = getNextInterceptor();
if (nextInterceptor == null) {
throw new ProcessingException(LocalizationMessages.ERROR_INTERCEPTOR_WRITER_PROCEED());
}
traceBefore(nextInterceptor, MsgTraceEvent.WI_BEFORE);
try {
nextInterceptor.aroundWriteTo(this);
} finally {
processedCount++;
traceAfter(nextInterceptor, MsgTraceEvent.WI_AFTER);
}
}
use of javax.ws.rs.ext.WriterInterceptor in project jersey by jersey.
the class ClientRequestTest method mockThrowing.
private ClientRequest mockThrowing(Exception exception) throws IOException {
JerseyClient client = new JerseyClientBuilder().build();
final ClientRequest request = new ClientRequest(URI.create("http://example.org"), client.getConfiguration(), new MapPropertiesDelegate());
Mockito.doThrow(exception).when(workers).writeTo(any(), same(entityType.getRawType()), same(entityType.getType()), Mockito.<Annotation[]>any(), Mockito.<MediaType>any(), Mockito.<MultivaluedMap<String, Object>>any(), Mockito.<PropertiesDelegate>any(), Mockito.<OutputStream>any(), Mockito.<Iterable<WriterInterceptor>>any());
return request;
}
use of javax.ws.rs.ext.WriterInterceptor in project jersey by jersey.
the class CommonConfigTest method testProviderOrderSemiAutomatic.
@Test
public void testProviderOrderSemiAutomatic() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager();
config.register(MidPriorityProvider.class, 50);
config.register(LowPriorityProvider.class, 2000);
config.register(HighPriorityProvider.class);
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> allProviders = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<>());
final Iterator<WriterInterceptor> iterator = allProviders.iterator();
assertEquals(MidPriorityProvider.class, iterator.next().getClass());
assertEquals(HighPriorityProvider.class, iterator.next().getClass());
assertEquals(LowPriorityProvider.class, iterator.next().getClass());
assertFalse(iterator.hasNext());
}
Aggregations