Search in sources :

Example 41 with ConnectTimeoutException

use of org.apache.http.conn.ConnectTimeoutException in project sda-dropwizard-commons by SDA-SE.

the class SuppressConnectTimeoutErrorsToNullTest method shouldSuppressForObjectReturnType.

@Test
public void shouldSuppressForObjectReturnType() {
    ProcessingErrorsSuppressed given = createProxy(ProcessingErrorsSuppressed.class, () -> {
        throw new ProcessingException(new ConnectTimeoutException());
    });
    assertThat(given.suppressed()).isNull();
}
Also used : ProcessingException(javax.ws.rs.ProcessingException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 42 with ConnectTimeoutException

use of org.apache.http.conn.ConnectTimeoutException in project sda-dropwizard-commons by SDA-SE.

the class SuppressReadTimeoutErrorsToNullTest method shouldNotSuppressConnectTimeoutForObjectReturnType.

@Test
public void shouldNotSuppressConnectTimeoutForObjectReturnType() {
    ProcessingErrorsSuppressed given = createProxy(ProcessingErrorsSuppressed.class, () -> {
        throw new ProcessingException(new ConnectTimeoutException());
    });
    assertThatExceptionOfType(ClientRequestException.class).isThrownBy(given::suppressed);
}
Also used : ClientRequestException(org.sdase.commons.client.jersey.error.ClientRequestException) ProcessingException(javax.ws.rs.ProcessingException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 43 with ConnectTimeoutException

use of org.apache.http.conn.ConnectTimeoutException in project sda-dropwizard-commons by SDA-SE.

the class ClientRequestExceptionMapperTest method mapConnectionTimeout.

@Test
public void mapConnectionTimeout() {
    ClientRequestException exception = new ClientRequestException(new ProcessingException(new ConnectTimeoutException()));
    Response response = clientRequestExceptionMapper.toResponse(exception);
    assertThat(response.getStatus()).isEqualTo(500);
    assertThat(response.getHeaders().getFirst(CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
    assertThat(response.getEntity()).isInstanceOf(ApiError.class);
    assertThat((ApiError) response.getEntity()).extracting(ApiError::getTitle).asString().isNotBlank().containsIgnoringCase("connect").containsIgnoringCase("timeout");
}
Also used : Response(javax.ws.rs.core.Response) ApiError(org.sdase.commons.shared.api.error.ApiError) ProcessingException(javax.ws.rs.ProcessingException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 44 with ConnectTimeoutException

use of org.apache.http.conn.ConnectTimeoutException in project ed-springboot-learning by QQ986945193.

the class WXPayRequest method request.

private String request(String urlSuffix, String uuid, String data, int connectTimeoutMs, int readTimeoutMs, boolean useCert, boolean autoReport) throws Exception {
    Exception exception = null;
    long elapsedTimeMillis = 0;
    long startTimestampMs = WXPayUtil.getCurrentTimestampMs();
    boolean firstHasDnsErr = false;
    boolean firstHasConnectTimeout = false;
    boolean firstHasReadTimeout = false;
    IWXPayDomain.DomainInfo domainInfo = config.getWXPayDomain().getDomain(config);
    if (domainInfo == null) {
        throw new Exception("WXPayConfig.getWXPayDomain().getDomain() is empty or null");
    }
    try {
        String result = requestOnce(domainInfo.domain, urlSuffix, uuid, data, connectTimeoutMs, readTimeoutMs, useCert);
        elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs() - startTimestampMs;
        config.getWXPayDomain().report(domainInfo.domain, elapsedTimeMillis, null);
        WXPayReport.getInstance(config).report(uuid, elapsedTimeMillis, domainInfo.domain, domainInfo.primaryDomain, connectTimeoutMs, readTimeoutMs, firstHasDnsErr, firstHasConnectTimeout, firstHasReadTimeout);
        return result;
    } catch (UnknownHostException ex) {
        // dns 解析错误,或域名不存在
        exception = ex;
        firstHasDnsErr = true;
        elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs() - startTimestampMs;
        WXPayUtil.getLogger().warn("UnknownHostException for domainInfo {}", domainInfo);
        WXPayReport.getInstance(config).report(uuid, elapsedTimeMillis, domainInfo.domain, domainInfo.primaryDomain, connectTimeoutMs, readTimeoutMs, firstHasDnsErr, firstHasConnectTimeout, firstHasReadTimeout);
    } catch (ConnectTimeoutException ex) {
        exception = ex;
        firstHasConnectTimeout = true;
        elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs() - startTimestampMs;
        WXPayUtil.getLogger().warn("connect timeout happened for domainInfo {}", domainInfo);
        WXPayReport.getInstance(config).report(uuid, elapsedTimeMillis, domainInfo.domain, domainInfo.primaryDomain, connectTimeoutMs, readTimeoutMs, firstHasDnsErr, firstHasConnectTimeout, firstHasReadTimeout);
    } catch (SocketTimeoutException ex) {
        exception = ex;
        firstHasReadTimeout = true;
        elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs() - startTimestampMs;
        WXPayUtil.getLogger().warn("timeout happened for domainInfo {}", domainInfo);
        WXPayReport.getInstance(config).report(uuid, elapsedTimeMillis, domainInfo.domain, domainInfo.primaryDomain, connectTimeoutMs, readTimeoutMs, firstHasDnsErr, firstHasConnectTimeout, firstHasReadTimeout);
    } catch (Exception ex) {
        exception = ex;
        elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs() - startTimestampMs;
        WXPayReport.getInstance(config).report(uuid, elapsedTimeMillis, domainInfo.domain, domainInfo.primaryDomain, connectTimeoutMs, readTimeoutMs, firstHasDnsErr, firstHasConnectTimeout, firstHasReadTimeout);
    }
    config.getWXPayDomain().report(domainInfo.domain, elapsedTimeMillis, exception);
    throw exception;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) UnknownHostException(java.net.UnknownHostException) UnknownHostException(java.net.UnknownHostException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 45 with ConnectTimeoutException

use of org.apache.http.conn.ConnectTimeoutException in project manifoldcf by apache.

the class RSSConnector method handleRSSFeedSAX.

/**
 * Handle an RSS feed document, using SAX to limit the memory impact
 */
protected void handleRSSFeedSAX(String documentIdentifier, IProcessActivity activities, Filter filter) throws ManifoldCFException, ServiceInterruption {
    // First, catch all flavors of IO exception, and handle them properly
    try {
        // Open the input stream, and set up the parse
        InputStream is = cache.getData(documentIdentifier);
        if (is == null) {
            Logging.connectors.error("RSS: Document '" + documentIdentifier + "' should be in cache but isn't");
            return;
        }
        try {
            Parser p = new Parser();
            // Parse the document.  This will cause various things to occur, within the instantiated XMLParsingContext class.
            XMLFuzzyHierarchicalParseState x = new XMLFuzzyHierarchicalParseState();
            OuterContextClass c = new OuterContextClass(x, documentIdentifier, activities, filter);
            x.setContext(c);
            try {
                // Believe it or not, there are no parsing errors we can get back now.
                p.parseWithCharsetDetection(null, is, x);
                c.checkIfValidFeed();
                c.setDefaultRescanTimeIfNeeded();
            } finally {
                x.cleanup();
            }
        } finally {
            is.close();
        }
    } catch (java.net.SocketTimeoutException e) {
        throw new ManifoldCFException("Socket timeout error: " + e.getMessage(), e);
    } catch (ConnectTimeoutException e) {
        throw new ManifoldCFException("Socket connect timeout error: " + e.getMessage(), e);
    } catch (InterruptedIOException e) {
        throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
    } catch (IOException e) {
        throw new ManifoldCFException("IO error: " + e.getMessage(), e);
    }
}
Also used : java.net(java.net) DateParser(org.apache.manifoldcf.core.common.DateParser) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Aggregations

ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)146 SocketTimeoutException (java.net.SocketTimeoutException)77 IOException (java.io.IOException)66 HttpResponse (org.apache.http.HttpResponse)30 HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)23 UnknownHostException (java.net.UnknownHostException)21 HttpPost (org.apache.http.client.methods.HttpPost)21 SocketException (java.net.SocketException)19 HttpEntity (org.apache.http.HttpEntity)19 ConnectException (java.net.ConnectException)18 NoHttpResponseException (org.apache.http.NoHttpResponseException)17 HttpClient (org.apache.http.client.HttpClient)17 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 StatusLine (org.apache.http.StatusLine)16 ClientProtocolException (org.apache.http.client.ClientProtocolException)16 HttpGet (org.apache.http.client.methods.HttpGet)15 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)14 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 InterruptedIOException (java.io.InterruptedIOException)11