use of javax.ws.rs.client.ClientRequestContext in project dropwizard by dropwizard.
the class ConfiguredGZipEncoderTest method contextMayNotBeNull.
@Test(expected = NullPointerException.class)
public void contextMayNotBeNull() throws IOException {
ClientRequestContext context = null;
new ConfiguredGZipEncoder(false).filter(context);
}
use of javax.ws.rs.client.ClientRequestContext in project robozonky by RoboZonky.
the class RoboZonkyFilterTest method response.
@Test
void response() throws IOException {
final String key = UUID.randomUUID().toString();
final String key2 = UUID.randomUUID().toString();
final String value = UUID.randomUUID().toString();
final MultivaluedMap<String, String> map = new MultivaluedMapImpl<>();
map.add(key, value);
map.addAll(key2, Collections.emptyList());
final ClientRequestContext ctx = mock(ClientRequestContext.class);
final ClientResponseContext ctx2 = mock(ClientResponseContext.class);
when(ctx2.getHeaders()).thenReturn(map);
when(ctx2.getStatusInfo()).thenReturn(mock(Response.StatusType.class));
final RoboZonkyFilter filter = new RoboZonkyFilter();
filter.filter(ctx, ctx2);
assertSoftly(softly -> {
softly.assertThat(filter.getLastResponseHeader(key)).contains(value);
softly.assertThat(filter.getLastResponseHeader(key2)).isEmpty();
});
}
use of javax.ws.rs.client.ClientRequestContext in project instrumentation-java by census-instrumentation.
the class JaxrsClientFilterTest method testResponseFilter.
@Test
public void testResponseFilter() throws Exception {
Span span = new FakeSpan(SpanContext.INVALID, null);
TagContext tagContext = mock(TagContext.class);
HttpRequestContext context = createHttpRequestContext(span, tagContext);
ClientRequestContext requestContext = mock(ClientRequestContext.class);
when(requestContext.getProperty("opencensus.context")).thenReturn(context);
ClientResponseContext responseContext = mock(ClientResponseContext.class);
filter.filter(requestContext, responseContext);
verify(requestContext).getProperty("opencensus.context");
verify(responseContext, times(1)).getStatus();
}
use of javax.ws.rs.client.ClientRequestContext in project cxf by apache.
the class ClientResponseFilterInterceptor method handleMessage.
public void handleMessage(Message inMessage) throws Fault {
ClientProviderFactory pf = ClientProviderFactory.getInstance(inMessage);
if (pf == null) {
return;
}
List<ProviderInfo<ClientResponseFilter>> filters = pf.getClientResponseFilters();
if (!filters.isEmpty()) {
final ClientRequestContext reqContext = new ClientRequestContextImpl(inMessage.getExchange().getOutMessage(), true);
final ResponseImpl response = (ResponseImpl) getResponse(inMessage);
final ClientResponseContext respContext = new ClientResponseContextImpl(response, inMessage);
for (ProviderInfo<ClientResponseFilter> filter : filters) {
InjectionUtils.injectContexts(filter.getProvider(), filter, inMessage);
try {
filter.getProvider().filter(reqContext, respContext);
} catch (RuntimeException | IOException ex) {
// would be stuck waiting for the IN chain completion.
if (!inMessage.getExchange().isOneWay()) {
synchronized (inMessage.getExchange()) {
inMessage.getExchange().put("IN_CHAIN_COMPLETE", Boolean.TRUE);
}
}
// a response (4.5.2 Client Runtime).
throw new ResponseProcessingException(response, ex);
}
}
}
}
use of javax.ws.rs.client.ClientRequestContext in project cxf by apache.
the class SpecExamplesTest method getClientRequestContextMock.
private ClientRequestContext getClientRequestContextMock(URI uri, String method, MultivaluedMap<String, Object> requestHeaders) {
ClientRequestContext requestContext = Mockito.mock(ClientRequestContext.class);
Mockito.when(requestContext.getEntity()).thenReturn(null);
Mockito.when(requestContext.getMethod()).thenReturn(method);
Mockito.when(requestContext.getHeaders()).thenReturn(requestHeaders);
Mockito.when(requestContext.getUri()).thenReturn(uri);
return requestContext;
}
Aggregations