Beispiel #1
0
  public InputStream getFileStream(String url, Map headers)
      throws HoneycombTestException, IOException {
    Log.DEBUG("getFileStream: " + url);
    CmdResult cr = new CmdResult();

    byte[] readBuf = new byte[BUFSIZE];

    try {
      cr.filename = url;
      HTTPResponse rsp = conn.Get(url);

      if (rsp.getStatusCode() >= 300) throw makeTestException("getFile", url, rsp);

      if (headers != null)
        for (Enumeration hdrs = rsp.listHeaders(); hdrs.hasMoreElements(); ) {
          String name = (String) hdrs.nextElement();
          String value = rsp.getHeader(name);
          headers.put(name.toLowerCase(), value);
        }

      cr.filesize = 0;
      return rsp.getInputStream();
    } catch (ModuleException e) {
      e.printStackTrace();
      cr.pass = false;
      cr.addException(e);
    }
    return null;
  }
Beispiel #2
0
 public long getServerTime() throws HoneycombTestException {
   try {
     return conn.Get("/").getHeaderAsDate("Date").getTime();
   } catch (Exception e) {
     throw new HoneycombTestException(e);
   }
 }
Beispiel #3
0
  public CmdResult getFile(String url, boolean calcHash) throws HoneycombTestException {
    Log.DEBUG("getFile: " + url);
    CmdResult cr = new CmdResult();

    byte[] readBuf = new byte[BUFSIZE];

    try {
      MessageDigest sha = null; // for hash
      if (calcHash) sha = MessageDigest.getInstance(HC_HASH);

      cr.filename = url;
      long t1 = System.currentTimeMillis();
      HTTPResponse rsp = conn.Get(url);

      if (rsp.getStatusCode() >= 300) throw makeTestException("getFile", url, rsp);

      cr.filesize = 0;
      InputStream is = rsp.getInputStream();

      while (true) {
        int ct = is.read(readBuf);
        if (ct == -1) break;
        cr.filesize += ct;
        if (calcHash) sha.update(readBuf, 0, ct);
      }

      cr.time = System.currentTimeMillis() - t1;
      cr.pass = true;

      if (calcHash) cr.datasha1 = HCUtil.convertHashBytesToString(sha.digest());
    } catch (HoneycombTestException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      cr.pass = false;
      cr.addException(e);
    }
    return cr;
  }