use of io.airlift.http.client.HttpClientConfig in project presto by prestodb.
the class QueryRunner method getHttpClientConfig.
private static HttpClientConfig getHttpClientConfig(Optional<HostAndPort> socksProxy, Optional<String> keystorePath, Optional<String> keystorePassword, Optional<String> truststorePath, Optional<String> truststorePassword, Optional<String> kerberosPrincipal, Optional<String> kerberosRemoteServiceName, boolean authenticationEnabled) {
HttpClientConfig httpClientConfig = new HttpClientConfig().setConnectTimeout(new Duration(5, TimeUnit.SECONDS)).setRequestTimeout(new Duration(5, TimeUnit.SECONDS));
socksProxy.ifPresent(httpClientConfig::setSocksProxy);
httpClientConfig.setAuthenticationEnabled(authenticationEnabled);
keystorePath.ifPresent(httpClientConfig::setKeyStorePath);
keystorePassword.ifPresent(httpClientConfig::setKeyStorePassword);
truststorePath.ifPresent(httpClientConfig::setTrustStorePath);
truststorePassword.ifPresent(httpClientConfig::setTrustStorePassword);
kerberosPrincipal.ifPresent(httpClientConfig::setKerberosPrincipal);
kerberosRemoteServiceName.ifPresent(httpClientConfig::setKerberosRemoteServiceName);
return httpClientConfig;
}
use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.
the class TestHttpServerProvider method testClientCertificate.
@Test
public void testClientCertificate() throws Exception {
HttpServlet servlet = new HttpServlet() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
if ((certs == null) || (certs.length == 0)) {
throw new RuntimeException("No client certificate");
}
if (certs.length > 1) {
throw new RuntimeException("Received multiple client certificates");
}
X509Certificate cert = certs[0];
response.getWriter().write(cert.getSubjectX500Principal().getName());
response.setStatus(HttpServletResponse.SC_OK);
}
};
config.setHttpEnabled(false).setAdminEnabled(false).setHttpsEnabled(true).setHttpsPort(0).setKeystorePath(getResource("clientcert/server.keystore").toString()).setKeystorePassword("airlift");
createAndStartServer(servlet);
HttpClientConfig clientConfig = new HttpClientConfig().setKeyStorePath(getResource("clientcert/client.keystore").toString()).setKeyStorePassword("airlift").setTrustStorePath(getResource("clientcert/client.truststore").toString()).setTrustStorePassword("airlift");
System.out.println(httpServerInfo.getHttpsUri());
try (JettyHttpClient httpClient = new JettyHttpClient(clientConfig)) {
StringResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpsUri()).build(), createStringResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(response.getBody(), "CN=testing,OU=Client,O=Airlift,L=Palo Alto,ST=CA,C=US");
}
}
use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.
the class TestTestingHttpServer method testFilteredRequest.
@Test
public void testFilteredRequest() throws Exception {
DummyServlet servlet = new DummyServlet();
DummyFilter filter = new DummyFilter();
TestingHttpServer server = createTestingHttpServerWithFilter(servlet, ImmutableMap.of(), filter);
try {
server.start();
try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) {
StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(servlet.getCallCount(), 1);
assertEquals(filter.getCallCount(), 1);
}
} finally {
server.stop();
}
}
use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.
the class TestTestingHttpServer method testRequest.
@Test
public void testRequest() throws Exception {
DummyServlet servlet = new DummyServlet();
TestingHttpServer server = createTestingHttpServer(servlet, ImmutableMap.of());
try {
server.start();
try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) {
StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(servlet.getCallCount(), 1);
}
} finally {
server.stop();
}
}
use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.
the class TestHttpEventClient method setup.
@BeforeMethod
public void setup() throws Exception {
httpClient = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(10, SECONDS)));
servlet = new DummyServlet();
server = createServer(servlet);
server.start();
}
Aggregations