コード例 #1
0
    public static ListBoxModel fillAuthenticationItems() {
      ListBoxModel items = new ListBoxModel();
      items.add("");
      for (BasicDigestAuthentication basicDigestAuthentication :
          HttpRequestGlobalConfig.get().getBasicDigestAuthentications()) {
        items.add(basicDigestAuthentication.getKeyName());
      }
      for (FormAuthentication formAuthentication :
          HttpRequestGlobalConfig.get().getFormAuthentications()) {
        items.add(formAuthentication.getKeyName());
      }

      return items;
    }
コード例 #2
0
  public ResponseContentSupplier performHttpRequest(
      TaskListener listener, RequestAction requestAction) throws InterruptedException, IOException {
    final PrintStream logger = listener.getLogger();
    logger.println("HttpMode: " + requestAction.getMode());
    logger.println(String.format("URL: %s", requestAction.getUrl()));
    for (HttpRequestNameValuePair header : requestAction.getHeaders()) {
      if (header.getName().equalsIgnoreCase("Authorization")) {
        logger.println(header.getName() + ": *****");
      } else {
        logger.println(header.getName() + ": " + header.getValue());
      }
    }

    DefaultHttpClient httpclient = new SystemDefaultHttpClient();

    HttpClientUtil clientUtil = new HttpClientUtil();
    HttpRequestBase httpRequestBase = clientUtil.createRequestBase(requestAction);

    HttpContext context = new BasicHttpContext();

    if (authentication != null && !authentication.isEmpty()) {
      final Authenticator auth = HttpRequestGlobalConfig.get().getAuthentication(authentication);
      if (auth == null) {
        throw new IllegalStateException(
            "Authentication '" + authentication + "' doesn't exist anymore");
      }

      logger.println("Using authentication: " + auth.getKeyName());
      auth.authenticate(httpclient, context, httpRequestBase, logger, timeout);
    }

    ResponseContentSupplier responseContentSupplier;
    try {
      final HttpResponse response =
          clientUtil.execute(httpclient, context, httpRequestBase, logger, timeout);
      // The HttpEntity is consumed by the ResponseContentSupplier
      responseContentSupplier = new ResponseContentSupplier(response);
    } catch (UnknownHostException uhe) {
      logger.println("Treating UnknownHostException(" + uhe.getMessage() + ") as 404 Not Found");
      responseContentSupplier =
          new ResponseContentSupplier("UnknownHostException as 404 Not Found", 404);
    } catch (SocketTimeoutException | ConnectException ce) {
      logger.println(
          "Treating " + ce.getClass() + "(" + ce.getMessage() + ") as 408 Request Timeout");
      responseContentSupplier =
          new ResponseContentSupplier(
              ce.getClass() + "(" + ce.getMessage() + ") as 408 Request Timeout", 408);
    }

    if (consoleLogResponseBody) {
      logger.println("Response: \n" + responseContentSupplier.getContent());
    }

    responseCodeIsValid(responseContentSupplier, logger);
    contentIsValid(responseContentSupplier, logger);

    return responseContentSupplier;
  }
コード例 #3
0
    public static FormValidation validateKeyName(String value) {
      List<Authenticator> list = HttpRequestGlobalConfig.get().getAuthentications();

      int count = 0;
      for (Authenticator basicAuthentication : list) {
        if (basicAuthentication.getKeyName().equals(value)) {
          count++;
        }
      }

      if (count > 1) {
        return FormValidation.error("The Key Name must be unique");
      }

      return FormValidation.validateRequired(value);
    }