示例#1
0
 public void testCreateHostConfigurationProxy() throws Exception {
   StubProgressMonitor monitor = new StubProgressMonitor();
   HttpClient client = new HttpClient();
   WebUtil.createHostConfiguration(
       client,
       new WebLocation(
           TestUrl.DEFAULT.getHttpOk().toString(),
           null,
           null,
           new IProxyProvider() {
             public Proxy getProxyForHost(String host, String proxyType) {
               assertEquals(IProxyData.HTTP_PROXY_TYPE, proxyType);
               return null;
             }
           }),
       monitor);
   WebUtil.createHostConfiguration(
       client,
       new WebLocation(
           TestUrl.DEFAULT.getHttpsOk().toString(),
           null,
           null,
           new IProxyProvider() {
             public Proxy getProxyForHost(String host, String proxyType) {
               assertEquals(IProxyData.HTTPS_PROXY_TYPE, proxyType);
               return null;
             }
           }),
       monitor);
 }
示例#2
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);
    }
  }
示例#3
0
  public void testConfigureClient() throws Exception {
    WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());

    WebUtil.createHostConfiguration(client, location, null /*monitor*/);

    HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    assertEquals(
        CoreUtil.TEST_MODE ? 2 : MAX_HTTP_HOST_CONNECTIONS_DEFAULT,
        params.getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION));
    assertEquals(
        CoreUtil.TEST_MODE ? 20 : MAX_HTTP_TOTAL_CONNECTIONS_DEFAULT,
        params.getMaxTotalConnections());
  }
示例#4
0
 public void testGetTitleFromUrl() throws Exception {
   assertEquals(
       "Eclipse Mylyn Open Source Project",
       WebUtil.getTitleFromUrl(new WebLocation(TestUrl.DEFAULT.getHttpOk().toString()), null));
   // disabled: fails in environments where the DNS resolver redirects for unknown hosts
   //		try {
   //			String title = WebUtil.getTitleFromUrl(new WebLocation("http://invalidurl"), null);
   //			fail("Expected UnknownHostException, got: " + title);
   //		} catch (UnknownHostException e) {
   //		}
   String url = "http://" + proxyAddress.getHostName() + ":" + proxyAddress.getPort() + "/";
   testProxy.addResponse(TestProxy.OK);
   assertNull(WebUtil.getTitleFromUrl(new WebLocation(url), null));
 }
示例#5
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);
    }
  }
示例#6
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);
    }
  }