@Override
  public InputStream getInputStream(long maxTimeoutMillis)
      throws IOException, ConfigurationSetupException {
    try {
      ServerURL theURL = new ServerURL(host, port, "/config", (int) maxTimeoutMillis, securityInfo);

      // JDK: 1.4.2 - These settings are proprietary to Sun's implementation of java.net.URL in
      // version 1.4.2
      System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(maxTimeoutMillis));
      System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(maxTimeoutMillis));

      return theURL.openStream(pwProvider);
    } catch (MalformedURLException murle) {
      throw new ConfigurationSetupException("Can't load configuration from " + this + ".");
    }
  }
コード例 #2
0
  private void testGroupInfoForServer(int tsaPort, boolean shouldPass)
      throws MalformedURLException {
    ServerURL theURL =
        new ServerURL(
            "localhost", tsaPort, TCServerImpl.GROUP_INFO_SERVLET_PATH, new SecurityInfo());
    InputStream l1PropFromL2Stream = null;
    System.out.println("Trying to get groupinfo from " + theURL.toString());
    int trials = 0;
    while (true) {
      try {
        l1PropFromL2Stream = theURL.openStream();
        Assert.assertNotNull(l1PropFromL2Stream);
        break;
      } catch (IOException e) {
        if (shouldPass) {
          System.out.println(
              "should have connected to [localhost:" + tsaPort + "]. trials so far: " + ++trials);
        } else {
          break;
        }
      }
    }

    if (shouldPass) {
      try {
        ServerGroupsDocument.Factory.parse(l1PropFromL2Stream);
      } catch (XmlException e) {
        if (shouldPass) {
          Assert.fail("should have been able to parse the groupinfo");
        }
      } catch (IOException e) {
        if (shouldPass) {
          Assert.fail("should have been able to parse the groupinfo");
        }
      }
    }
  }