Example #1
0
  public void testExecuteCancelStalledConnect() throws Exception {
    final StubProgressMonitor monitor = new StubProgressMonitor();
    HttpClient client = new HttpClient();
    WebLocation location = new WebLocation(TestUrl.DEFAULT.getConnectionTimeout().toString());
    HostConfiguration hostConfiguration =
        WebUtil.createHostConfiguration(client, location, monitor);

    GetMethod method = new GetMethod(location.getUrl());
    try {
      Runnable runner =
          new Runnable() {
            public void run() {
              try {
                Thread.sleep(500);
              } catch (InterruptedException e) {
              }
              monitor.canceled = true;
            }
          };
      new Thread(runner).start();
      WebUtil.execute(client, hostConfiguration, method, monitor);
      client.executeMethod(method);
      fail("Expected OperationCanceledException");
    } catch (OperationCanceledException expected) {
      assertTrue(monitor.isCanceled());
    } catch (ConnectException ignored) {
      System.err.println("Skipping testExecuteCancelStalledConnect() due to blocking firewall");
    } finally {
      WebUtil.releaseConnection(method, monitor);
    }
  }
Example #2
0
  public void testExecute() throws Exception {
    StubProgressMonitor monitor = new StubProgressMonitor();
    HttpClient client = new HttpClient();
    WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());
    HostConfiguration hostConfiguration =
        WebUtil.createHostConfiguration(client, location, monitor);

    GetMethod method = new GetMethod(location.getUrl());
    try {
      int result = WebUtil.execute(client, hostConfiguration, method, monitor);
      assertEquals(HttpStatus.SC_OK, result);
    } finally {
      WebUtil.releaseConnection(method, monitor);
    }
  }
Example #3
0
  public void testExecuteAlreadyCancelled() throws Exception {
    StubProgressMonitor monitor = new StubProgressMonitor();
    HttpClient client = new HttpClient();
    WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());
    HostConfiguration hostConfiguration =
        WebUtil.createHostConfiguration(client, location, monitor);

    GetMethod method = new GetMethod(location.getUrl());
    try {
      monitor.canceled = true;
      WebUtil.execute(client, hostConfiguration, method, monitor);
      fail("Expected InterruptedIOException");
    } catch (OperationCanceledException expected) {
    } finally {
      WebUtil.releaseConnection(method, monitor);
    }
  }