org.apache.http.conn.ConnectionPoolTimeoutException Java Examples
The following examples show how to use
org.apache.http.conn.ConnectionPoolTimeoutException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMisc.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test that a large number of open/close does not lose connections; * check for null response. * This test uses an implicit HTTPSession. */ @Test public void testClosing2() throws HTTPException { // Set max # of connections HTTPSession.setGlobalMaxConnections(201); for (int i = 0; i < 200; i++) { HTTPMethod m = HTTPFactory.Get(CLOSEFILE); HttpResponse res = null; try { res = m.executeRaw(); } catch (HTTPException e) { if (e.getCause() instanceof ConnectionPoolTimeoutException) { System.err.println("TestMisc: timeout: " + i); } else throw e; } Assert.assertFalse("Null response", res == null); m.close(); } }
Example #2
Source File: ConnectionPoolMaxConnectionsIntegrationTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = 60 * 1000) public void leasing_a_new_connection_fails_with_connection_pool_timeout() throws Exception { String localhostEndpoint = "http://localhost:" + server.getPort(); AmazonHttpClient httpClient = new AmazonHttpClient( new ClientConfiguration() .withMaxConnections(1) .withConnectionTimeout(100) .withMaxErrorRetry(0)); Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET); // Block the first connection in the pool with this request. httpClient.requestExecutionBuilder().request(request).execute(new EmptyAWSResponseHandler()); try { // A new connection will be leased here which would fail in // ConnectionPoolTimeoutException. httpClient.requestExecutionBuilder().request(request).execute(); Assert.fail("Connection pool timeout exception is expected!"); } catch (AmazonClientException e) { Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException); } }
Example #3
Source File: ApacheHttpRequester.java From algoliasearch-client-java-2 with MIT License | 6 votes |
/** * Sends the http request asynchronously to the API If the request is time out it creates a new * response object with timeout set to true Otherwise it throws a run time exception * * @param request the request to send * @throws AlgoliaRuntimeException When an error occurred while sending the request */ public CompletableFuture<HttpResponse> performRequestAsync(HttpRequest request) { HttpRequestBase requestToSend = buildRequest(request); return toCompletableFuture(fc -> asyncHttpClient.execute(requestToSend, fc)) .thenApplyAsync(this::buildResponse, config.getExecutor()) .exceptionally( t -> { if (t.getCause() instanceof ConnectTimeoutException || t.getCause() instanceof SocketTimeoutException || t.getCause() instanceof ConnectException || t.getCause() instanceof TimeoutException || t.getCause() instanceof ConnectionPoolTimeoutException || t.getCause() instanceof NoHttpResponseException) { return new HttpResponse(true); } else if (t.getCause() instanceof HttpException) { return new HttpResponse().setNetworkError(true); } throw new AlgoliaRuntimeException(t); }); }
Example #4
Source File: HttpErrorPage.java From esigate with Apache License 2.0 | 6 votes |
public static CloseableHttpResponse generateHttpResponse(Exception exception) { if (exception instanceof HttpHostConnectException) { return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Connection refused"); } else if (exception instanceof ConnectionPoolTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Connection pool timeout"); } else if (exception instanceof ConnectTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Connect timeout"); } else if (exception instanceof SocketTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Socket timeout"); } else if (exception instanceof SocketException) { return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Socket Exception"); } else if (exception instanceof ClientProtocolException) { String message = exception.getMessage(); if (message == null && exception.getCause() != null) { message = exception.getCause().getMessage(); } return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Protocol error: " + message); } else { LOG.error("Error retrieving URL", exception); return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Error retrieving URL"); } }
Example #5
Source File: ElasticSearchRestClient.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
private ElasticSearchException handleConnectionPoolTimeOutException(ConnectionPoolTimeoutException ex){ ClientConfiguration configuration = ClientConfiguration.getClientConfiguration(this.httpPool); if(configuration == null){ return new ElasticSearchException(ex); } else{ StringBuilder builder = new StringBuilder(); builder.append("Wait timeout for ").append(configuration.getConnectionRequestTimeout()).append("ms for idle http connection from http connection pool."); return new ElasticSearchException(builder.toString(),ex); } }
Example #6
Source File: ConnectionPoolMaxConnectionsIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test(timeout = 60 * 1000) public void leasing_a_new_connection_fails_with_connection_pool_timeout() { AmazonSyncHttpClient httpClient = HttpTestUtils.testClientBuilder() .retryPolicy(RetryPolicy.none()) .httpClient(ApacheHttpClient.builder() .connectionTimeout(Duration.ofMillis(100)) .maxConnections(1) .build()) .build(); SdkHttpFullRequest request = server.configureHttpEndpoint(SdkHttpFullRequest.builder()) .method(SdkHttpMethod.GET) .build(); // Block the first connection in the pool with this request. httpClient.requestExecutionBuilder() .request(request) .originalRequest(NoopTestRequest.builder().build()) .executionContext(executionContext(request)) .execute(combinedSyncResponseHandler(new EmptySdkResponseHandler(), null)); try { // A new connection will be leased here which would fail in // ConnectionPoolTimeoutException. httpClient.requestExecutionBuilder() .request(request) .originalRequest(NoopTestRequest.builder().build()) .executionContext(executionContext(request)) .execute(combinedSyncResponseHandler(null, null)); Assert.fail("Connection pool timeout exception is expected!"); } catch (SdkClientException e) { Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException); } }
Example #7
Source File: NamedConnectionPool.java From ribbon with Apache License 2.0 | 5 votes |
@Override protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, InterruptedException { Stopwatch stopWatch = requestTimer.start(); try { return super.getEntryBlocking(route, state, timeout, tunit, aborter); } finally { stopWatch.stop(); } }
Example #8
Source File: ClientConnectionRequestFactoryTest.java From ibm-cos-sdk-java with Apache License 2.0 | 4 votes |
@Override public HttpClientConnection get(long timeout, TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { return null; }
Example #9
Source File: ConnectionReuseTest.java From lucene-solr with Apache License 2.0 | 4 votes |
public HttpClientConnection getConn(ConnectionRequest mConn) throws InterruptedException, ConnectionPoolTimeoutException, ExecutionException { HttpClientConnection conn = mConn.get(30, TimeUnit.SECONDS); return conn; }
Example #10
Source File: BlockingHttpClient.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private boolean isRemoteUnavailable(final Exception e) { if (e instanceof ConnectionPoolTimeoutException) { return false; } return true; }