Пример #1
0
 private SVNRepository createRepositoryConnection(
     final HttpServletRequest request, final RepositoryConfiguration configuration)
     throws SVNException {
   final Credentials credentials = extractCredentials(request, configuration);
   return repositoryConnectionFactory.createConnection(
       configuration.getName(), configuration.getSVNURL(), credentials);
 }
Пример #2
0
  /** {@inheritDoc} */
  protected ModelAndView handle(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final Object cmd,
      final BindException errors)
      throws Exception {

    logger.debug("Getting RSS feed");

    final BaseCommand command = (BaseCommand) cmd;
    logger.debug(command);

    if (!application.isConfigured()) {
      handleError(response, "sventon has not been configured yet!");
      return null;
    }

    final RepositoryConfiguration configuration =
        application.getRepositoryConfiguration(command.getName());
    if (configuration == null) {
      handleError(response, "Repository [" + command.getName() + "] does not exist!");
      return null;
    }

    addResponseHeaders(response);

    SVNRepository repository = null;

    try {
      final List<SVNLogEntry> logEntries = new ArrayList<SVNLogEntry>();
      repository = createRepositoryConnection(request, configuration);
      command.translateRevision(getRepositoryService().getLatestRevision(repository), repository);

      logger.debug("Outputting feed for [" + command.getPath() + "]");
      logEntries.addAll(
          getRepositoryService()
              .getRevisions(
                  command.getName(),
                  repository,
                  command.getRevisionNumber(),
                  FIRST_REVISION,
                  command.getPath(),
                  configuration.getRssItemsCount(),
                  false));
      rssFeedGenerator.outputFeed(configuration, logEntries, request, response);
    } catch (SVNAuthenticationException aex) {
      logger.info(aex.getMessage());
      httpAuthenticationHandler.sendChallenge(response);
    } catch (SVNException svnex) {
      handleSVNException(response, svnex);
    } finally {
      close(repository);
    }
    return null;
  }
  @Test
  public void testUpdate() throws Exception {
    final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory();
    configDirectory.setCreateDirectories(false);
    final MockServletContext servletContext = new MockServletContext();
    servletContext.setContextPath("sventon-test");
    configDirectory.setServletContext(servletContext);

    final Application application = new Application(configDirectory);

    final RepositoryConfiguration configuration = new RepositoryConfiguration("name");
    configuration.setCacheUsed(true);
    application.addConfiguration(configuration);
    application.setConfigured(true);

    final ObjectCache cache = createMemoryCache();

    try {
      final List<RepositoryChangeListener> listeners = new ArrayList<RepositoryChangeListener>();
      listeners.add(repositoryChangeListenerMock);
      final DefaultRepositoryChangeMonitor changeMonitor = new DefaultRepositoryChangeMonitor();
      changeMonitor.setListeners(listeners);
      changeMonitor.setMaxRevisionCountPerUpdate(3);
      changeMonitor.setApplication(application);

      changeMonitor.setRepositoryService(repositoryServiceMock);
      assertFalse(application.isUpdating(configuration.getName()));

      expect(repositoryServiceMock.getLatestRevision(null)).andReturn(6L);
      expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 1L, 3L))
          .andReturn(firstBatchOfRevisions);
      repositoryChangeListenerMock.update(isA(RevisionUpdate.class));
      expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 4L, 6L))
          .andReturn(secondBatchOfRevisions);
      repositoryChangeListenerMock.update(isA(RevisionUpdate.class));

      replay(repositoryServiceMock);
      replay(repositoryChangeListenerMock);
      changeMonitor.update(configuration.getName(), null, cache);
      verify(repositoryServiceMock);
      verify(repositoryChangeListenerMock);

      assertFalse(application.isUpdating(configuration.getName()));
    } finally {
      cache.shutdown();
    }
  }
Пример #4
0
  private Credentials extractCredentials(
      HttpServletRequest request, RepositoryConfiguration configuration) {
    final Credentials credentialsFromUrlParameters = extractCredentialsFromRequest(request);

    final Credentials credentials;
    if (configuration.isAccessControlEnabled()) {
      if (httpAuthenticationHandler.isLoginAttempt(request)) {
        logger.debug("Basic HTTP authentication detected. Parsing credentials from request.");
        credentials = httpAuthenticationHandler.parseCredentials(request);
      } else {
        logger.debug("Parsing credentials from url");
        credentials = credentialsFromUrlParameters;
      }
    } else {
      credentials = configuration.getUserCredentials();
    }
    return credentials;
  }
Пример #5
0
  private void sendMailMessage(
      SVNLogEntry logEntry, RepositoryName repositoryName, RepositoryConfiguration configuration) {
    try {
      final Message msg = createMessage(logEntry, repositoryName, configuration.getMailTemplate());
      final SMTPTransport transport = (SMTPTransport) session.getTransport(ssl ? "smtps" : "smtp");

      try {
        if (auth) {
          transport.connect(host, user, password);
        } else {
          transport.connect();
        }
        transport.sendMessage(msg, msg.getAllRecipients());
        LOGGER.debug("Notification mail was sent successfully");
      } finally {
        transport.close();
      }
    } catch (Exception e) {
      LOGGER.error("Unable to send notification mail", e);
    }
  }