类org.apache.http.ConnectionClosedException源码实例Demo

下面列出了怎么用org.apache.http.ConnectionClosedException的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
void testWaitForJsonFieldAppearsHandledException() throws IOException, IllegalAccessException, NoSuchFieldException
{
    when(httpClient.execute(argThat(base -> base instanceof HttpRequestBase
            && base.getMethod().equals(GET)
            && base.getURI().equals(URI.create(URL))),
            argThat(context -> context instanceof HttpClientContext)))
        .thenThrow(new ConnectionClosedException());
    HttpRequestExecutor httpRequestExecutor = new HttpRequestExecutor(httpClient, httpTestContext, softAssert);
    Field executorField = jsonResponseValidationSteps.getClass().getDeclaredField(HTTP_REQUEST_EXECUTOR_FIELD);
    executorField.setAccessible(true);
    executorField.set(jsonResponseValidationSteps, httpRequestExecutor);
    jsonResponseValidationSteps.waitForJsonFieldAppearance(STRING_PATH, URL, Duration.ofSeconds(1),
            DURATION_DIVIDER);
    verify(softAssert).recordFailedAssertion(
            (Exception) argThat(arg -> arg instanceof ConnectionClosedException
                    && "Connection is closed".equals(((Exception) arg).getMessage())));
}
 
源代码2 项目: helios   文件: HeliosSoloLogService.java
@Override
public Void call() throws IOException, DockerException {
  try (final LogStream logStream =
           dockerClient.logs(containerId, stdout(), stderr(), follow())) {
    log.info("attaching stdout/stderr for job={}, container={}", jobId, containerId);
    logStreamFollower.followLog(jobId, containerId, logStream);
  } catch (InterruptedException e) {
    // Ignore
  } catch (final Throwable t) {
    if (!(Throwables.getRootCause(t) instanceof ConnectionClosedException)) {
      log.warn("error streaming log for job={}, container={}", jobId, containerId, t);
    }
    throw t;
  }
  return null;
}
 
源代码3 项目: vividus   文件: HttpRequestExecutor.java
private HttpResponse executeHttpCallSafely(HttpMethod httpMethod, String endpoint, String relativeURL)
        throws IOException
{
    try
    {
        return execute(httpMethod, endpoint, relativeURL);
    }
    catch (HttpRequestBuildException | ConnectionClosedException e)
    {
        softAssert.recordFailedAssertion(e);
        return null;
    }
}
 
源代码4 项目: vividus   文件: HttpRequestExecutorTests.java
@Test
void testExecuteHttpRequestConnectionClosedException() throws IOException
{
    when(httpClient.execute(argThat(e -> e instanceof HttpRequestBase && URL.equals(e.getURI().toString())),
            nullable(HttpContext.class))).thenThrow(new ConnectionClosedException());
    httpRequestExecutor.executeHttpRequest(HttpMethod.GET, URL, Optional.empty());
    verify(softAssert).recordFailedAssertion(
            (Exception) argThat(arg -> arg instanceof ConnectionClosedException
                    && "Connection is closed".equals(((Exception) arg).getMessage())));
    verify(httpTestContext).releaseRequestData();
}
 
源代码5 项目: Photato   文件: StdErrorExceptionLogger.java
@Override
public void log(final Exception ex) {
    if (ex instanceof SocketTimeoutException || ex instanceof ConnectionClosedException) {
        // Do nothing
    } else {
        ex.printStackTrace();
    }
}
 
源代码6 项目: cyberduck   文件: HttpExceptionMappingService.java
@Override
public BackgroundException map(final IOException failure) {
    if(failure instanceof ConnectionClosedException) {
        final StringBuilder buffer = new StringBuilder();
        this.append(buffer, failure.getMessage());
        return new ConnectionRefusedException(buffer.toString(), failure);
    }
    return super.map(failure);
}
 
protected BackgroundException wrap(final T failure, final String title, final StringBuilder buffer) {
    if(buffer.toString().isEmpty()) {
        log.warn(String.format("No message for failure %s", failure));
        this.append(buffer, LocaleFactory.localizedString("Unknown"));
    }
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(cause instanceof InterruptedIOException) {
            // Handling socket timeouts
            return new ConnectionTimeoutException(buffer.toString(), failure);
        }
        if(cause instanceof TimeoutException) {
            //
            return new ConnectionTimeoutException(buffer.toString(), failure);
        }
        if(cause instanceof SocketException) {
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
        if(cause instanceof EOFException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
        if(cause instanceof UnknownHostException) {
            return new ResolveFailedException(buffer.toString(), failure);
        }
        if(cause instanceof NoHttpResponseException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
        if(cause instanceof ConnectionClosedException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
        if(cause instanceof InterruptedException) {
            return new ConnectionCanceledException(buffer.toString(), failure);
        }
    }
    if(failure instanceof RuntimeException) {
        return new ConnectionCanceledException(title, buffer.toString(), failure);
    }
    return new BackgroundException(title, buffer.toString(), failure);
}
 
源代码8 项目: lavaplayer   文件: HttpClientTools.java
private static boolean isPrematureEndException(Throwable exception) {
  return exception instanceof ConnectionClosedException && exception.getMessage() != null &&
      exception.getMessage().startsWith("Premature end of Content-Length");
}
 
 类所在包
 同包方法