use of jakarta.ws.rs.ext.ReaderInterceptorContext in project resteasy by resteasy.
the class PriorityTest method testReaderInterceptorPriorityOverride.
@Test
public void testReaderInterceptorPriorityOverride() {
Client client = ClientBuilder.newClient();
try {
fakeHttpServer.start();
WebTarget webTarget = client.target("http://" + fakeHttpServer.getHostAndPort());
webTarget.register((ClientResponseFilter) (containerRequestContext, containerResponseContext) -> {
containerResponseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
containerResponseContext.setEntityStream(new ByteArrayInputStream("hello".getBytes()));
});
StringBuilder result = new StringBuilder();
webTarget.register(new ReaderInterceptor() {
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
result.append("K");
return context.proceed();
}
}, 1);
webTarget.register(new ReaderInterceptor() {
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
result.append("O");
return context.proceed();
}
}, 0);
webTarget.request().get().readEntity(String.class);
Assert.assertEquals("OK", result.toString());
} finally {
client.close();
}
}
use of jakarta.ws.rs.ext.ReaderInterceptorContext in project tomee by apache.
the class JAXRSUtils method readFromMessageBodyReader.
@SuppressWarnings("unchecked")
public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers, Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType mediaType, Message m) throws IOException, WebApplicationException {
// Verbose but avoids an extra context instantiation for the typical path
if (readers.size() > 1) {
ReaderInterceptor first = readers.remove(0);
ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass, parameterType, parameterAnnotations, is, m, readers);
return first.aroundReadFrom(context);
}
MessageBodyReader<?> provider = ((ReaderInterceptorMBR) readers.get(0)).getMBR();
@SuppressWarnings("rawtypes") Class cls = targetTypeClass;
return provider.readFrom(cls, parameterType, parameterAnnotations, mediaType, new HttpHeadersImpl(m).getRequestHeaders(), is);
}
Aggregations