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();
}
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);
}
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");
}
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;
}
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);
}
}
Aggregations