Example usage for org.apache.http.conn ConnectionPoolTimeoutException getMessage

List of usage examples for org.apache.http.conn ConnectionPoolTimeoutException getMessage

Introduction

In this page you can find the example usage for org.apache.http.conn ConnectionPoolTimeoutException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.microsoft.applicationinsights.internal.channel.common.TransmissionNetworkOutput.java

private TransmissionSendResult doSend(Transmission transmission) {
    HttpResponse response = null;//from  w w w .  jav a2  s.  c  o  m
    HttpPost request = null;
    try {
        request = createTransmissionPostRequest(transmission);
        httpClient.enhanceRequest(request);

        response = httpClient.sendPostRequest(request);

        HttpEntity respEntity = response.getEntity();
        int code = response.getStatusLine().getStatusCode();

        return translateResponse(code, respEntity);
    } catch (ConnectionPoolTimeoutException e) {
        InternalLogger.INSTANCE.error("Failed to send, connection pool timeout exception");
        return TransmissionSendResult.FAILED_TO_SEND_DUE_TO_CONNECTION_POOL;
    } catch (SocketException e) {
        InternalLogger.INSTANCE.error("Failed to send, socket timeout exception");
        return TransmissionSendResult.FAILED_TO_RECEIVE_DUE_TO_TIMEOUT;
    } catch (UnknownHostException e) {
        InternalLogger.INSTANCE.error(
                "Failed to send, wrong host address or cannot reach address due to network issues, exception: %s",
                e.getMessage());
        return TransmissionSendResult.FAILED_TO_SEND_DUE_TO_NETWORK_ISSUES;
    } catch (IOException ioe) {
        InternalLogger.INSTANCE.error("Failed to send, exception: %s", ioe.getMessage());
        return TransmissionSendResult.FAILED_TO_READ_RESPONSE;
    } catch (Exception e) {
        InternalLogger.INSTANCE.error("Failed to send, unexpected exception: %s", e.getMessage());
        return TransmissionSendResult.UNKNOWN_ERROR;
    } catch (Throwable t) {
        InternalLogger.INSTANCE.error("Failed to send, unexpected error: %s", t.getMessage());
        return TransmissionSendResult.UNKNOWN_ERROR;
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
        httpClient.dispose(response);
    }
}

From source file:org.dataconservancy.access.connector.HttpDcsConnector.java

/**
 * Execute the supplied request.  Method is package-private for unit testing.
 *
 * @param req the request object/*from w  ww . ja  v a  2s. c om*/
 * @param success_status http response status needed for the execution to succeed 
 * @return an HttpResponse
 * @throws DcsClientFault if the response status code is between 400 to 499 inclusive
 * @throws DcsServerException if the response status code is 500 or greater
 * @throws HttpIoException if a connection cannot be obtained from the connection pool, or an I/O error occurs
 * @throws DcsConnectorRuntimeException if any other RuntimeExceptions are caught
 */
HttpResponse execute(HttpUriRequest req, int success_status) throws DcsClientFault {
    HttpResponse response = null;
    String requestUri = null;
    try {
        requestUri = req.getRequestLine().getUri();
        response = client.execute(req);
    } catch (ConnectionPoolTimeoutException e) {
        throw new HttpIoException(
                "Timeout reached while obtaining an HTTP connection from the connection pool.  "
                        + "First, ensure response InputStreams are being read (this frees the connection), then try to "
                        + "increase the maximum number of connections, or increase the connection pool timeout.",
                e);
    } catch (IOException e) {
        throw new HttpIoException("Could not retrieve " + requestUri + ": " + e.getMessage(), e);
    } catch (IllegalStateException e) {
        // thrown when trying to re-use a connection that hasn't been closed
        req.abort();
        throw new DcsClientFault(e.getMessage(), e);
    } catch (RuntimeException e) {
        req.abort();
        throw new DcsConnectorRuntimeException(e.getMessage(), e);
    }

    final int statusCode = response.getStatusLine().getStatusCode();
    final String statusReason = response.getStatusLine().getReasonPhrase();

    if (statusCode != success_status) {

        req.abort();

        if (statusCode >= 400 && statusCode < 500) {
            throw new DcsClientFault("Could not retrieve " + requestUri + ": response from server was "
                    + statusCode + " '" + statusReason + "'");
        }

        if (statusCode >= 500) {
            throw new DcsServerException("Could not retrieve " + requestUri + ": response from server was "
                    + statusCode + " '" + statusReason + "'");
        }

        if (statusCode > 200 && statusCode < 300) {
            log.debug("Received status {} for {}", statusCode, requestUri);
            // TODO
        }

        if (statusCode >= 300 && statusCode < 400) {
            log.debug("Received status {} for {}", statusCode, requestUri);
            // TODO
        }

        if (statusCode >= 100 && statusCode < 200) {
            log.debug("Received status {} for {}", statusCode, requestUri);
            // TODO
        }
    }

    return response;
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

/**
 * Marshall and send the request.//from  w  w w.j a v  a  2  s . c  o  m
 * @param headers
 * @param entityString
 * @return
 * @throws SendRequestFailedException
 * @throws SSLException
 * @throws AuthenticationFailure
 * @throws ConnectionFailedException
 * @throws ConnectionPoolTimeoutException
 */
private synchronized InputStream sendRequest(Header[] headers, String entityString)
        throws SendRequestFailedException, SSLException, AuthenticationFailure, ConnectionFailedException,
        ConnectionPoolTimeoutException {
    long down = 0;
    long up = 0;
    long start = System.currentTimeMillis();

    if (!initialised)
        throw new IllegalStateException("AcalRequestor has not been initialised!");
    statusCode = -1;
    try {
        // Create request and add headers and entity
        request = new DavRequest(method, this.fullUrl());
        //         request.addHeader(new BasicHeader("User-Agent", AcalConnectionPool.getUserAgent()));
        if (headers != null)
            for (Header h : headers)
                request.addHeader(h);

        if (authRequired && authType != Servers.AUTH_NONE)
            request.addHeader(buildAuthHeader());
        else if (authRequired) {
            // Assume basicAuth
            request.addHeader(basicAuthHeader());
        }

        if (entityString != null) {
            request.setEntity(new StringEntity(entityString.toString(), "UTF-8"));
            up = request.getEntity().getContentLength();
        }

        // This trick greatly reduces the occurrence of host not found errors.
        try {
            InetAddress.getByName(this.hostName);
        } catch (UnknownHostException e1) {
            Thread.sleep(100);
            try {
                InetAddress.getByName(this.hostName);
            } catch (UnknownHostException e2) {
                Thread.sleep(100);
            }
        }

        int requestPort = -1;
        if (this.protocol == null)
            this.protocol = PROTOCOL_HTTP;
        String requestProtocol = this.protocol;
        if ((this.protocol.equals(PROTOCOL_HTTP) && this.port != 80)
                || (this.protocol.equals(PROTOCOL_HTTPS) && this.port != 443)) {
            requestPort = this.port;
        }

        if (Constants.LOG_DEBUG || debugThisRequest) {
            Log.println(Constants.LOGD, TAG,
                    String.format("Method: %s, Protocol: %s, Hostname: %s, Port: %d, Path: %s", method,
                            requestProtocol, hostName, requestPort, path));
        }
        HttpHost host = new HttpHost(this.hostName, requestPort, requestProtocol);

        if (debugThisRequest)
            logRequest(Constants.LOGV);

        // Send request and get response
        response = null;

        if (Constants.debugHeap)
            AcalDebug.heapDebug(TAG, "Making HTTP request");
        try {
            response = httpClient.execute(host, request);
        } catch (ConnectionPoolTimeoutException e) {
            Log.println(Constants.LOGI, TAG,
                    e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
            Log.println(Constants.LOGI, TAG, "Retrying...");
            response = httpClient.execute(host, request);
        }
        if (Constants.debugHeap)
            AcalDebug.heapDebug(TAG, "Finished HTTP request");

        this.responseHeaders = response.getAllHeaders();
        this.statusCode = response.getStatusLine().getStatusCode();

        HttpEntity entity = response.getEntity();
        down = (entity == null ? 0 : entity.getContentLength());

        long finish = System.currentTimeMillis();
        double timeTaken = (finish - start) / 1000.0;

        if (Constants.LOG_DEBUG || debugThisRequest)
            Log.println(Constants.LOGD, TAG, "Response: " + statusCode + ", Sent: " + up + ", Received: " + down
                    + ", Took: " + timeTaken + " seconds");

        if (debugThisRequest) {
            return logResponse(Constants.LOGV);
        } else if (entity != null) {
            if (entity.getContentLength() > 0)
                return entity.getContent();

            // Kind of admitting defeat here, but I can't track down why we seem
            // to end up in never-never land if we just return entity.getContent()
            // directly when entity.getContentLength() is -1 ('unknown', apparently).
            // Horribly inefficient too.
            //
            // @todo: Check whether this problem was caused by failing to close the InputStream
            // and this hack can be removed...  Need to find a server which does not send Content-Length headers.
            //
            String tmpEntity = entityToString(entity);
            return new ByteArrayInputStream(tmpEntity.getBytes());
        }

    } catch (SSLProtocolException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        return null;
    } catch (SSLHandshakeException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        throw e;
    } catch (SSLException e) {
        if (debugThisRequest)
            Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
        throw e;
    } catch (AuthenticationFailure e) {
        if (debugThisRequest)
            Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
        throw e;
    } catch (ConnectionPoolTimeoutException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        throw e;
    } catch (SocketTimeoutException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        return null;
    } catch (ConnectTimeoutException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        return null;
    } catch (UnknownHostException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        return null;
    } catch (IOException e) {
        Log.i(TAG, e.getClass().getSimpleName() + ": " + e.getMessage() + " to " + fullUrl());
        return null;
    } catch (Exception e) {
        Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
        if (statusCode < 300 || statusCode > 499)
            throw new SendRequestFailedException(e.getMessage());
    }
    return null;
}