Refine search
@Inject public KillBillOktaRealm(final SecurityConfig securityConfig) { this.securityConfig = securityConfig; this.httpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeout(DEFAULT_TIMEOUT_SECS * 1000).build()); if (securityConfig.getShiroOktaPermissionsByGroup() != null) { final Ini ini = new Ini(); // When passing properties on the command line, \n can be escaped ini.load(securityConfig.getShiroOktaPermissionsByGroup().replace("\\n", "\n")); for (final Section section : ini.getSections()) { for (final String role : section.keySet()) { final Collection<String> permissions = ImmutableList.<String>copyOf(SPLITTER.split(section.get(role))); permissionsByGroup.put(role, permissions); } } } }
public static void main(String[] args) { SecureRandom secureRandom = new SecureRandom(); SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, secureRandom); } catch (Exception e) { e.printStackTrace(); } AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder() .setConnectTimeout(5000) .setSSLContext(sslContext).build(); AsyncHttpClient client = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config); long start = System.currentTimeMillis(); try { client.executeRequest(client.prepareGet("http://www.google.com").build()).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } LOGGER.debug("COMPLETE: " + (System.currentTimeMillis() - start) + "ms"); } }
@Override public void configure(Binder binder) { Multibinder<SingularityAuthenticator> multibinder = Multibinder.newSetBinder(binder, SingularityAuthenticator.class); for (SingularityAuthenticatorClass clazz : getConfiguration().getAuthConfiguration().getAuthenticators()) { multibinder.addBinding().to(clazz.getAuthenticatorClass()); if (clazz == SingularityAuthenticatorClass.WEBHOOK) { AuthConfiguration authConfiguration = getConfiguration().getAuthConfiguration(); AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() .setConnectionTimeoutInMs(authConfiguration.getWebhookAuthConnectTimeoutMs()) .setRequestTimeoutInMs(authConfiguration.getWebhookAuthRequestTimeoutMs()) .setMaxRequestRetry(authConfiguration.getWebhookAuthRetries()) .build(); SingularityAsyncHttpClient webhookAsyncHttpClient = new SingularityAsyncHttpClient(clientConfig); binder.bind(AsyncHttpClient.class).annotatedWith(Names.named(WEBHOOK_AUTH_HTTP_CLIENT)).toInstance(webhookAsyncHttpClient); } } binder.bind(SingularityAuthFeature.class); binder.bind(SingularityMultiMethodAuthenticator.class); binder.bind(SingularityAuthDatastore.class).to(getConfiguration().getAuthConfiguration().getDatastore().getAuthDatastoreClass()); binder.bind(SingularityAuthorizationHelper.class).in(Scopes.SINGLETON); } }
@Test(groups = { "standalone", "default_provider" }) public void testGlobalDefaultPerRequestInfiniteTimeout() throws IOException { try (AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeout(100).build())) { Future<Response> responseFuture = client.prepareGet(getTargetUrl()).setRequestTimeout(-1).execute(); Response response = responseFuture.get(); assertNotNull(response); } catch (InterruptedException e) { fail("Interrupted.", e); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof TimeoutException); checkTimeoutMessage(e.getCause().getMessage()); } }
@Test public void testNoTransferEncoding() throws Exception { String url = "http://localhost:" + port + "/test"; AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder() .setFollowRedirect(false) .setConnectTimeout(15000) .setRequestTimeout(15000) .setAllowPoolingConnections(false) .setDisableUrlEncodingForBoundedRequests(true) .setIOThreadMultiplier(2) // 2 is default .build(); try (AsyncHttpClient client = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config)) { Future<com.ning.http.client.Response> f = client.prepareGet(url).execute(); com.ning.http.client.Response r = f.get(10, TimeUnit.SECONDS); Assert.assertEquals(TEST_MESSAGE, r.getResponseBody()); } } }
public PerfClientCallable(Parameters params, ArrayList<DestToPayload> payloads) { this.params = params; this.asyncHttpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder() .setConnectTimeout(Integer.MAX_VALUE) .setRequestTimeout(Integer.MAX_VALUE) .setAllowPoolingConnections(true) .build()); this.payloads = new ArrayList<>(); for (DestToPayload payload : payloads) { this.payloads.add(asyncHttpClient.preparePost(payload.getDestination()) .addHeader("content-type", "application/json") .addHeader("Accept", "application/xml") .setBody(payload.getPayload()) .setRequestTimeout(Integer.MAX_VALUE) .build()); } executionStrategy = getExecutionStrategy(); }
@Test(groups = { "standalone", "default_provider" }) public void testMaxRetry() throws Throwable { try (AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build())) { client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(); fail(); } catch (Exception t) { assertNotNull(t.getCause()); assertEquals(t.getCause().getClass(), IOException.class); if (t.getCause() != AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION) { fail(); } } } }
@Test(groups = { "standalone", "default_provider" }) public void basicAuthFileNoKeepAliveTest() throws Throwable { try (AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnections(false).build())) { ClassLoader cl = getClass().getClassLoader(); // override system properties URL url = cl.getResource("SimpleTextFile.txt"); File file = new File(url.toURI()); final String fileContent = getFileContent(file); AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); Future<Response> f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), fileContent); } }
@Test(groups = { "online", "default_provider" }) public void testConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException { AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// .setProxyServer(new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1))// .setAcceptAnyCertificate(true)// .setFollowRedirect(true)// .build(); try (AsyncHttpClient client = getAsyncHttpClient(config)) { RequestBuilder rb = new RequestBuilder("GET").setUrl(getTargetUrl2()); Future<Response> responseFuture = client.executeRequest(rb.build(), new AsyncCompletionHandlerBase() { public void onThrowable(Throwable t) { t.printStackTrace(); log.debug(t.getMessage(), t); } @Override public Response onCompleted(Response response) throws Exception { return response; } }); Response r = responseFuture.get(); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Connection"), "keep-alive"); } }
@Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeFile() throws Exception { byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); long repeats = (1024 * 1024 * 100 / bytes.length) + 1; largeFile = createTempFile(bytes, (int) repeats); int timeout = (int) (largeFile.length() / 1000); AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setConnectTimeout(timeout).build(); try (AsyncHttpClient client = getAsyncHttpClient(config)) { BoundRequestBuilder rb = client.preparePut(getTargetUrl()); rb.setBody(largeFile); Response response = rb.execute().get(); Assert.assertEquals(200, response.getStatusCode()); } }
@Test(groups = { "default_provider", "async" }) public void optionsTest() throws Throwable { try (AsyncHttpClient client = getAsyncHttpClient(new Builder().build())) { Response r = client.prepareOptions(getTargetUrl()).execute().get(); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE"); } }
/** * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and * and a AsyncHttpProvider class' name. * * @param config a {@link AsyncHttpClientConfig} * @param providerClass a {@link AsyncHttpProvider} */ public AsyncHttpClient(String providerClass, AsyncHttpClientConfig config) { this.config = new AsyncHttpClientConfig.Builder().build(); this.httpProvider = loadDefaultProvider(providerClass, config); }
/** * Returns raw http client. If client has not been initialized yet * then new client is created with default configuration. * @return raw http client */ public static synchronized AsyncHttpClient getNingClient() { if (_client.get() == null) { initialize(new AsyncHttpClientConfig.Builder().build()); } return _client.get(); }
public SimpleAsyncHttpClient build() { if (realmBuilder != null) { configBuilder.setRealm(realmBuilder.build()); } if (proxyHost != null) { configBuilder.setProxyServer(new ProxyServer(proxyProtocol, proxyHost, proxyPort, proxyPrincipal, proxyPassword)); } configBuilder.addIOExceptionFilter(new ResumableIOExceptionFilter()); SimpleAsyncHttpClient sc = new SimpleAsyncHttpClient(configBuilder.build(), requestBuilder, defaultThrowableHandler, errorDocumentBehaviour, enableResumableDownload, ahc, listener, providerClass); return sc; } }
/** * Create a new HTTP Asynchronous Client using the default {@link AsyncHttpClientConfig} configuration. The * default {@link AsyncHttpProvider} will be used ({@link com.ning.http.client.providers.netty.NettyAsyncHttpProvider} */ public AsyncHttpClient() { this(new AsyncHttpClientConfig.Builder().build()); }
/** * Create a new HTTP Asynchronous Client using an implementation of {@link AsyncHttpProvider} and * the default {@link AsyncHttpClientConfig} configuration. * * @param provider a {@link AsyncHttpProvider} */ public AsyncHttpClient(AsyncHttpProvider provider) { this(provider, new AsyncHttpClientConfig.Builder().build()); }
/** * Set the number of time a request will be retried when an {@link java.io.IOException} occurs because of a Network exception. * * @param maxRequestRetry the number of time a request will be retried * @return this */ public Builder setMaxRequestRetry(int maxRequestRetry) { configBuilder.setMaxRequestRetry(maxRequestRetry); return this; }
public Builder setConnectTimeout(int connectTimeout) { configBuilder.setConnectTimeout(connectTimeout); return this; }
public Builder setAllowPoolingConnections(boolean allowPoolingConnections) { configBuilder.setAllowPoolingConnections(allowPoolingConnections); return this; }
public Builder setRequestTimeout(int defaultRequestTimeout) { configBuilder.setRequestTimeout(defaultRequestTimeout); return this; }