Search in sources :

Example 76 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project archiva by apache.

the class RssFeedServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String repoId = null;
    String groupId = null;
    String artifactId = null;
    String url = StringUtils.removeEnd(req.getRequestURL().toString(), "/");
    if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") > 0) {
        artifactId = StringUtils.substringAfterLast(url, "/");
        groupId = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, "feeds/"), "/");
        groupId = StringUtils.replaceChars(groupId, '/', '.');
    } else if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") == 0) {
        // we receive feeds?babla=ded which is not correct
        if (StringUtils.countMatches(url, "feeds?") > 0) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url.");
            return;
        }
        repoId = StringUtils.substringAfterLast(url, "/");
    } else {
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url.");
        return;
    }
    RssFeedProcessor processor = null;
    try {
        Map<String, String> map = new HashMap<>();
        SyndFeed feed = null;
        if (isAllowed(req, repoId, groupId, artifactId)) {
            if (repoId != null) {
                // new artifacts in repo feed request
                processor = newArtifactsprocessor;
                map.put(RssFeedProcessor.KEY_REPO_ID, repoId);
            } else if ((groupId != null) && (artifactId != null)) {
                // TODO: this only works for guest - we could pass in the list of repos
                // new versions of artifact feed request
                processor = newVersionsprocessor;
                map.put(RssFeedProcessor.KEY_GROUP_ID, groupId);
                map.put(RssFeedProcessor.KEY_ARTIFACT_ID, artifactId);
            }
        } else {
            res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED);
            return;
        }
        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try {
            feed = processor.process(map, repositorySession.getRepository());
        } finally {
            repositorySession.close();
        }
        if (feed == null) {
            res.sendError(HttpServletResponse.SC_NO_CONTENT, "No information available.");
            return;
        }
        res.setContentType(MIME_TYPE);
        if (repoId != null) {
            feed.setLink(req.getRequestURL().toString());
        } else if ((groupId != null) && (artifactId != null)) {
            feed.setLink(req.getRequestURL().toString());
        }
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, res.getWriter());
    } catch (UserNotFoundException unfe) {
        log.debug(COULD_NOT_AUTHENTICATE_USER, unfe);
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (AccountLockedException acce) {
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (AuthenticationException authe) {
        log.debug(COULD_NOT_AUTHENTICATE_USER, authe);
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (FeedException ex) {
        log.debug(COULD_NOT_GENERATE_FEED_ERROR, ex);
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR);
    } catch (MustChangePasswordException e) {
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (UnauthorizedException e) {
        log.debug(e.getMessage());
        if (repoId != null) {
            res.setHeader("WWW-Authenticate", "Basic realm=\"Repository Archiva Managed " + repoId + " Repository");
        } else {
            res.setHeader("WWW-Authenticate", "Basic realm=\"Artifact " + groupId + ":" + artifactId);
        }
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED);
    }
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) AccountLockedException(org.apache.archiva.redback.policy.AccountLockedException) HashMap(java.util.HashMap) AuthenticationException(org.apache.archiva.redback.authentication.AuthenticationException) FeedException(com.sun.syndication.io.FeedException) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MustChangePasswordException(org.apache.archiva.redback.policy.MustChangePasswordException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) RssFeedProcessor(org.apache.archiva.rss.processor.RssFeedProcessor) UnauthorizedException(org.apache.archiva.redback.authorization.UnauthorizedException)

Example 77 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project archiva by apache.

the class NewVersionsOfArtifactRssFeedProcessorTest method testProcess.

@SuppressWarnings("unchecked")
@Test
public void testProcess() throws Exception {
    Date whenGathered = new Date(123456789);
    ArtifactMetadata artifact1 = createArtifact(whenGathered, "1.0.1");
    ArtifactMetadata artifact2 = createArtifact(whenGathered, "1.0.2");
    Date whenGatheredNext = new Date(345678912);
    ArtifactMetadata artifact3 = createArtifact(whenGatheredNext, "1.0.3-SNAPSHOT");
    Map<String, String> reqParams = new HashMap<>();
    reqParams.put(RssFeedProcessor.KEY_GROUP_ID, GROUP_ID);
    reqParams.put(RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID);
    expect(metadataRepository.getRepositories()).andReturn(Collections.singletonList(TEST_REPO));
    expect(metadataRepository.getProjectVersions(TEST_REPO, GROUP_ID, ARTIFACT_ID)).andReturn(Arrays.asList("1.0.1", "1.0.2", "1.0.3-SNAPSHOT"));
    expect(metadataRepository.getArtifacts(TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1")).andReturn(Collections.singletonList(artifact1));
    expect(metadataRepository.getArtifacts(TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2")).andReturn(Collections.singletonList(artifact2));
    expect(metadataRepository.getArtifacts(TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT")).andReturn(Collections.singletonList(artifact3));
    metadataRepositoryControl.replay();
    SyndFeed feed = newVersionsProcessor.process(reqParams, metadataRepository);
    assertEquals("New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle());
    assertEquals("New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.", feed.getDescription());
    assertEquals("en-us", feed.getLanguage());
    assertEquals(whenGatheredNext, feed.getPublishedDate());
    List<SyndEntry> entries = feed.getEntries();
    assertEquals(2, entries.size());
    assertEquals("New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, entries.get(0).getTitle());
    assertEquals(whenGathered, entries.get(0).getPublishedDate());
    assertEquals("New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext, entries.get(1).getTitle());
    assertEquals(whenGatheredNext, entries.get(1).getPublishedDate());
    metadataRepositoryControl.verify();
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) HashMap(java.util.HashMap) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 78 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project archiva by apache.

the class RssFeedGeneratorTest method testNewFeed.

@SuppressWarnings("unchecked")
@Test
public void testNewFeed() throws Exception {
    List<RssFeedEntry> entries = new ArrayList<>();
    RssFeedEntry entry = new RssFeedEntry("Item 1");
    Date whenGathered = new Date(System.currentTimeMillis());
    entry.setDescription("RSS 2.0 feed item 1.");
    entry.setPublishedDate(whenGathered);
    entries.add(entry);
    entry = new RssFeedEntry("Item 2");
    entry.setDescription("RSS 2.0 feed item 2.");
    entry.setPublishedDate(whenGathered);
    entries.add(entry);
    entry = new RssFeedEntry("Item 3");
    entry.setDescription("RSS 2.0 feed item 3.");
    entry.setPublishedDate(whenGathered);
    entries.add(entry);
    SyndFeed feed = generator.generateFeed("Test Feed", "The test feed from Archiva.", entries);
    assertEquals("Test Feed", feed.getTitle());
    assertEquals("The test feed from Archiva.", feed.getDescription());
    assertEquals("en-us", feed.getLanguage());
    assertEquals(entries.get(2).getPublishedDate(), feed.getPublishedDate());
    List<SyndEntry> syndEntries = feed.getEntries();
    assertEquals(3, syndEntries.size());
    assertEquals("Item 1", syndEntries.get(0).getTitle());
    assertEquals("Item 2", syndEntries.get(1).getTitle());
    assertEquals("Item 3", syndEntries.get(2).getTitle());
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 79 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project archiva by apache.

the class RssFeedGeneratorTest method testNoDataEntries.

@Test
public void testNoDataEntries() throws Exception {
    List<RssFeedEntry> entries = new ArrayList<>();
    SyndFeed feed = generator.generateFeed("Test Feed", "The test feed from Archiva.", entries);
    assertNull(feed);
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 80 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project ofbiz-framework by apache.

the class BlogRssServices method generateBlogRssFeed.

public static Map<String, Object> generateBlogRssFeed(DispatchContext dctx, Map<String, ? extends Object> context) {
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String contentId = (String) context.get("blogContentId");
    String entryLink = (String) context.get("entryLink");
    String feedType = (String) context.get("feedType");
    Locale locale = (Locale) context.get("locale");
    // create the main link
    String mainLink = (String) context.get("mainLink");
    mainLink = mainLink + "?blogContentId=" + contentId;
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    // get the main blog content
    GenericValue content = null;
    try {
        content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    if (content == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentCannotGenerateBlogRssFeed", UtilMisc.toMap("contentId", contentId), locale));
    }
    // create the feed
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(feedType);
    feed.setLink(mainLink);
    feed.setTitle(content.getString("contentName"));
    feed.setDescription(content.getString("description"));
    feed.setEntries(generateEntryList(dispatcher, delegator, contentId, entryLink, locale, userLogin));
    Map<String, Object> resp = ServiceUtil.returnSuccess();
    resp.put("wireFeed", feed.createWireFeed());
    return resp;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)89 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 URL (java.net.URL)10 FeedException (com.sun.syndication.io.FeedException)9 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)9 IOException (java.io.IOException)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 XmlReader (com.sun.syndication.io.XmlReader)7 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6