Search in sources :

Example 1 with BasicListHeaderIterator

use of org.apache.http.message.BasicListHeaderIterator in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesDefaultForNonPersistentConnections.

@Test
public void usesDefaultForNonPersistentConnections() throws Exception {
    configuration.setKeepAlive(Duration.seconds(1));
    assertThat(builder.using(configuration).createClient(apacheBuilder, connectionManager, "test")).isNotNull();
    final Field field = FieldUtils.getField(httpClientBuilderClass, "keepAliveStrategy", true);
    final DefaultConnectionKeepAliveStrategy strategy = (DefaultConnectionKeepAliveStrategy) field.get(apacheBuilder);
    final HttpContext context = mock(HttpContext.class);
    final HttpResponse response = mock(HttpResponse.class);
    final HeaderIterator iterator = new BasicListHeaderIterator(ImmutableList.of(new BasicHeader(HttpHeaders.CONNECTION, "timeout=50")), HttpHeaders.CONNECTION);
    when(response.headerIterator(HTTP.CONN_KEEP_ALIVE)).thenReturn(iterator);
    assertThat(strategy.getKeepAliveDuration(response, context)).isEqualTo(50000);
}
Also used : Field(java.lang.reflect.Field) DefaultConnectionKeepAliveStrategy(org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) BasicListHeaderIterator(org.apache.http.message.BasicListHeaderIterator) HttpResponse(org.apache.http.HttpResponse) HeaderIterator(org.apache.http.HeaderIterator) BasicListHeaderIterator(org.apache.http.message.BasicListHeaderIterator) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 HeaderIterator (org.apache.http.HeaderIterator)1 HttpResponse (org.apache.http.HttpResponse)1 DefaultConnectionKeepAliveStrategy (org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy)1 BasicHeader (org.apache.http.message.BasicHeader)1 BasicListHeaderIterator (org.apache.http.message.BasicListHeaderIterator)1 BasicHttpContext (org.apache.http.protocol.BasicHttpContext)1 HttpContext (org.apache.http.protocol.HttpContext)1 Test (org.junit.Test)1