Exemplo n.º 1
0
  /**
   * Verify that a {@link Throwable} is a {@link TTransportException} wrapping the expected cause
   *
   * @param throwable The {@link Throwable} to check
   * @param expectedCause The expected cause of the {@link TTransportException}
   */
  private void checkTransportException(
      Throwable throwable, Class<? extends Throwable> expectedCause) {
    assertNotNull(throwable);
    Throwable cause = throwable.getCause();

    if (!(throwable instanceof TTransportException)) {
      fail("Exception of type " + throwable.getClass() + " when expecting a TTransportException");
    } else if (!(expectedCause.isAssignableFrom(throwable.getCause().getClass()))) {
      fail(
          "TTransportException caused by "
              + cause.getClass()
              + " when expecting a TTransportException caused by "
              + expectedCause);
    }
  }
Exemplo n.º 2
0
  @Test(groups = "standalone")
  public void testNonProxyHostsRequestOverridesConfig()
      throws IOException, ExecutionException, TimeoutException, InterruptedException {

    ProxyServer configProxy = proxyServer("localhost", port1 - 1).build();
    ProxyServer requestProxy = proxyServer("localhost", port1).setNonProxyHost("localhost").build();

    try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(configProxy))) {
      String target = "http://localhost:1234/";
      client.prepareGet(target).setProxyServer(requestProxy).execute().get();
      assertFalse(true);
    } catch (Throwable e) {
      assertNotNull(e.getCause());
      assertEquals(e.getCause().getClass(), ConnectException.class);
    }
  }
  @Test(groups = "online", enabled = false)
  public void invalidStreamTest2() throws Exception {
    AsyncHttpClientConfig config =
        config() //
            .setRequestTimeout(10000) //
            .setFollowRedirect(true) //
            .setKeepAlive(false) //
            .setMaxRedirects(6) //
            .build();

    try (AsyncHttpClient c = asyncHttpClient(config)) {
      Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get();
      if (response != null) {
        System.out.println(response);
      }
    } catch (Throwable t) {
      t.printStackTrace();
      assertNotNull(t.getCause());
      assertEquals(t.getCause().getMessage(), "invalid version format: ICY");
    }
  }