예제 #1
0
 private void setCookie(WebResponse rs) {
   String[] cookies = rs.getHeaderFields("set-cookie");
   for (String cookie : cookies) {
     String firstCookie = cookie.split(";")[0];
     String[] cookieStr = firstCookie.split("=");
     if (cookieStr.length == 2) {
       wc.putCookie(cookieStr[0], cookieStr[1]);
     } else {
       wc.putCookie(cookieStr[0], "");
     }
   }
 }
예제 #2
0
  public void addRepository(
      final Project project,
      final RedmineRepositoryConfig config,
      final SCMConnectorConfig scmConfig,
      final String username,
      final String password)
      throws MalformedURLException, IOException, SAXException {
    login(config);
    LOGGER.info("Redmine add Repository: " + scmConfig.getScmUrl());

    // Check if Repository should be added
    if (!config.isAddRepositoryConfiguration()) {
      LOGGER.debug("Redmine Repository config is disabled.");
      return;
    }

    List<Cookie> cookies = (List<Cookie>) _wt.getDialog().getCookies();
    for (Cookie cookie : cookies) {
      _wc.putCookie(cookie.getName(), cookie.getValue());
    }
    String token = getAuthenticityToken(_wt.getPageSource());
    LOGGER.debug("Token: {}", token);

    String scm = getScmType(scmConfig);
    LOGGER.debug("SCM CONFIG: {}", scm);

    postData(config, project, scmConfig, username, password, scm);
  }
예제 #3
0
  /**
   * @throws SAXException
   * @throws IOException
   * @throws MalformedURLException
   */
  private void postData(
      final RedmineRepositoryConfig config,
      final Project project,
      final SCMConnectorConfig scmConfig,
      final String username,
      final String password,
      final String scm) {
    LOGGER.info("Redmine add Repository: " + scmConfig.getScmUrl());

    // Check if Repository should be added
    if (!config.isAddRepositoryConfiguration()) {
      LOGGER.debug("Repository config is disabled");
      return;
    }

    List<Cookie> cookies = (List<Cookie>) _wt.getDialog().getCookies();
    for (Cookie cookie : cookies) {
      LOGGER.debug("Cookie: {}", cookie);
      _wc.putCookie(cookie.getName(), cookie.getValue());
    }

    PostMethodWebRequest form =
        new PostMethodWebRequest(
            config.getServer().getUrl() + "/projects/" + project.getName() + "/repositories");
    form.setParameter("authenticity_token", getAuthenticityToken(_wt.getPageSource()));
    form.setParameter("repository_scm", scm);
    form.setParameter("repository[url]", scmConfig.getProjectScmUrl(project.getName()));
    form.setParameter("repository[login]", username);
    form.setParameter("repository[password]", password);
    form.setParameter("commit", "Create");
    try {
      LOGGER.debug("Posting: {}", form);
      _wc.getResponse(form);
      LOGGER.debug("Posted");
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }