org.apache.http.ConnectionClosedException Java Examples

The following examples show how to use org.apache.http.ConnectionClosedException. 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: JsonResponseValidationStepsTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@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())));
}
 
Example #2
Source File: HeliosSoloLogService.java    From helios with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: HttpRequestExecutor.java    From vividus with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #4
Source File: HttpRequestExecutorTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #5
Source File: StdErrorExceptionLogger.java    From Photato with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void log(final Exception ex) {
    if (ex instanceof SocketTimeoutException || ex instanceof ConnectionClosedException) {
        // Do nothing
    } else {
        ex.printStackTrace();
    }
}
 
Example #6
Source File: HttpExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: AbstractExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: HttpClientTools.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
private static boolean isPrematureEndException(Throwable exception) {
  return exception instanceof ConnectionClosedException && exception.getMessage() != null &&
      exception.getMessage().startsWith("Premature end of Content-Length");
}