public Client create(final OpenOptions options) { checkNotNull(options); AhcConfig config = new DefaultAhcConfig(); AsyncHttpClientConfig.Builder builder = config.getAsyncHttpClientConfigBuilder(); if (options.getUsername() != null && options.getPassword() != null) { Realm realm = new Realm.RealmBuilder() .setScheme(Realm.AuthScheme.BASIC) .setUsePreemptiveAuth( true) // FIXME: ATM we must configure preemptive auth, to be replaced by session // token .setPrincipal(options.getUsername()) .setPassword(options.getPassword()) .build(); builder.setRealm(realm); } if (options.getProxyHost() != null) { ProxyServer proxyServer = new ProxyServer( ProxyServer.Protocol.HTTP, options.getProxyHost(), options.getProxyPort(), options.getProxyUsername(), options.getProxyPassword()); builder.setProxyServer(proxyServer); } config.getClasses().add(JacksonProvider.class); AhcHttpClient client = AhcHttpClient.create(config, componentProviderFactory); client.setFollowRedirects(options.isFollowRedirects()); // Last filter added is the first filter invoked client.addFilter(new FaultDecodingFilter()); client.addFilter(new LoggingFilter()); return client; }