Ejemplo n.º 1
0
  @Test
  public void test_get_baidu() throws Exception {
    httpClientUtils = new HttpClientUtils();
    httpClientUtils.setReUserConnection(false);
    httpClientUtils.initHttpClient();
    Logger.info(this, "-------------- HttpClient initialized -------------");
    //        for(int i =0;i<3){
    //
    //        }
    httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());
    httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());
    //         httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());
    //         httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());
    //         httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());
    //         httpClientUtils.get("http://www.lufax.com" + "?" + RandomUtils.nextInt());

    ExceptionHandler exceptionHandler =
        new ExceptionHandler() {
          public boolean handle(Throwable e) {
            return true;
          }
        };
    runTest("http://www.lufax.com", 1, exceptionHandler, 10);

    //        System.out.println(resp);
  }
Ejemplo n.º 2
0
  @Test
  public void testConnectionResetByHttpClientUtils() throws IOException {
    testConnectionResetCount = 0;

    httpClientUtils = new HttpClientUtils();
    httpClientUtils.initHttpClient();
    Logger.info(this, "-------------- HttpClient initialized -------------");

    String resp = null;
    try {
      resp = httpClientUtils.get("http://localhost:65532/soso");
    } catch (IOException e) {
      Throwable ee = ExceptionUtils.getRootCause(e);
      if (ee == null) {
        ee = e;
      }
      Logger.error(this, "", ee);
      Assert.assertNotSame(NoHttpResponseException.class, ee.getClass());
      Assert.assertSame(SocketException.class, ee.getClass());
      Assert.assertTrue(
          "Connection reset".equals(ee.getMessage())
              || "Socket closed".equals(ee.getMessage())
              || "Unexpected end of file from server".equals(ee.getMessage()));
    } finally {
      Logger.info(
          this,
          "resp[HttpURLConnection]-["
              + testConnectionResetCount
              + "]=========["
              + resp
              + "]=========");
    }
    Assert.assertEquals(1, testConnectionResetCount);
  }