Search in sources :

Example 26 with ClientRequestContext

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);
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) Test(org.junit.Test)

Example 27 with ClientRequestContext

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();
    });
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 28 with ClientRequestContext

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();
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) TagContext(io.opencensus.tags.TagContext) HttpRequestContext(io.opencensus.contrib.http.HttpRequestContext) Span(io.opencensus.trace.Span) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) Test(org.junit.Test)

Example 29 with ClientRequestContext

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);
            }
        }
    }
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) IOException(java.io.IOException) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) ResponseImpl(org.apache.cxf.jaxrs.impl.ResponseImpl) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ClientResponseFilter(javax.ws.rs.client.ClientResponseFilter) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException)

Example 30 with ClientRequestContext

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;
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext)

Aggregations

ClientRequestContext (javax.ws.rs.client.ClientRequestContext)30 Test (org.junit.Test)15 ClientResponseContext (javax.ws.rs.client.ClientResponseContext)11 Response (javax.ws.rs.core.Response)10 IOException (java.io.IOException)9 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)8 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)7 WebTarget (javax.ws.rs.client.WebTarget)7 Test (org.junit.jupiter.api.Test)7 URI (java.net.URI)6 Client (javax.ws.rs.client.Client)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 Message (org.apache.cxf.message.Message)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ProcessingException (javax.ws.rs.ProcessingException)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)3 VerifySignatureFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureFilter)3 MockAlgorithmProvider (org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider)3