Search in sources :

Example 51 with SyndFeed

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

the class FeedEntriesAtomBodyWriter method writeTo.

@Override
public void writeTo(List<FeedEntry> entries, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    List<SyndEntry> syndEntries = entries.parallelStream().map(entry -> {
        SyndContent description = new SyndContentImpl();
        description.setType(MediaType.TEXT_PLAIN);
        description.setValue(entry.getDescription());
        SyndEntry syndEntry = new SyndEntryImpl();
        syndEntry.setTitle(entry.getTitle());
        syndEntry.setLink(entry.getLink());
        syndEntry.setPublishedDate(entry.getPublishDate());
        syndEntry.setDescription(description);
        return syndEntry;
    }).collect(Collectors.toList());
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle("Combined Feed");
    feed.setDescription("Combined Feed created by a feed-combiner application");
    feed.setPublishedDate(new Date());
    feed.setEntries(syndEntries);
    writeSyndFeed(entityStream, feed);
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) Date(java.util.Date) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) LoggerFactory(org.slf4j.LoggerFactory) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) FeedException(com.sun.syndication.io.FeedException) MediaType(javax.ws.rs.core.MediaType) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) OutputStreamWriter(java.io.OutputStreamWriter) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Collection(java.util.Collection) IOException(java.io.IOException) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) Collectors(java.util.stream.Collectors) SyndContent(com.sun.syndication.feed.synd.SyndContent) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) Date(java.util.Date)

Example 52 with SyndFeed

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

the class AggregateRssFeedStrategy method aggregate.

public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    if (oldExchange == null) {
        return newExchange;
    }
    SyndFeed oldFeed = oldExchange.getIn().getBody(SyndFeed.class);
    SyndFeed newFeed = newExchange.getIn().getBody(SyndFeed.class);
    if (oldFeed != null && newFeed != null) {
        List<SyndEntryImpl> oldEntries = CastUtils.cast(oldFeed.getEntries());
        List<SyndEntryImpl> newEntries = CastUtils.cast(newFeed.getEntries());
        List<SyndEntryImpl> mergedList = new ArrayList<SyndEntryImpl>(oldEntries.size() + newEntries.size());
        mergedList.addAll(oldEntries);
        mergedList.addAll(newEntries);
        oldFeed.setEntries(mergedList);
    } else {
        log.debug("Could not merge exchanges. One body was null.");
    }
    return oldExchange;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList)

Example 53 with SyndFeed

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

the class FetcherEventListenerImpl method fetchFeed.

@SuppressWarnings("unchecked")
private void fetchFeed() throws IllegalArgumentException, IOException, FeedException, FetcherException {
    // Retrieve the feed.
    // We will get a Feed Polled Event and then a
    // Feed Retrieved event (assuming the feed is valid)
    SyndFeed feed = fetcher.retrieveFeed(feedUrl);
    if (modified) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(feedUrl + " retrieved");
            LOGGER.info(feedUrl + " has a title: " + feed.getTitle() + " and contains " + feed.getEntries().size() + " entries.");
        }
        List<? extends SyndEntryImpl> fetchedFeeds = feed.getEntries();
        rssFeedBuffer.addAll(fetchedFeeds);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 54 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method assertTheNewConsumerFeed.

protected void assertTheNewConsumerFeed(String ownerKey, String consumerUuid, SyndFeed oldConsumerFeed, String[] newEventTitles) throws IllegalArgumentException, IOException, FeedException {
    // assert the consumer feed...
    SyndFeed newConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerUuid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    Assert.assertEquals(newConsumerFeed.getTitle(), "Event feed for consumer " + consumerUuid);
    assertFeedContainsNoUnknownEvents(newConsumerFeed);
    log.info("Expecting the new feed for consumer (" + consumerUuid + ") to have grown by (" + newEventTitles.length + ") events:");
    int e = 0;
    for (String newEventTitle : newEventTitles) log.info(String.format("  Expecting entry[%d].title %s", e++, newEventTitle));
    // Assert.assertEquals(newConsumerFeed.getEntries().size(), oldConsumerFeed_EntriesSize+newEventTitles.length, "The event feed for consumer "+consumerUuid+" has increased by "+newEventTitles.length+" entries.");
    // if (oldConsumerFeed_EntriesSize+newEventTitles.length <= feedLimit) {
    // Assert.assertEquals(newConsumerFeed.getEntries().size(), oldConsumerFeed_EntriesSize+newEventTitles.length, "The event feed for consumer "+consumerUuid+" has increased by "+newEventTitles.length+" entries.");
    // } else {
    // Assert.assertEquals(newConsumerFeed.getEntries().size(), feedLimit, "The event feed length for consumer '"+consumerUuid+"' has hit the max entry count as set by the Candlepin class AtomResource/ConsumerResource/OwnerResource hard-coded variable feedlimit.");
    // }
    Assert.assertEquals(getFeedGrowthCount(newConsumerFeed, oldConsumerFeed), newEventTitles.length, newEventTitles.length + " new event feed entries for consumer '" + consumerUuid + "' has been pushed onto the stack.");
    int i = 0;
    for (String newEventTitle : newEventTitles) {
        String actualEventTitle = ((SyndEntryImpl) newConsumerFeed.getEntries().get(i)).getTitle();
        Assert.assertEquals(actualEventTitle, newEventTitle, "The next (" + i + ") newest event feed entry for consumer " + consumerUuid + " is '" + newEventTitle + "'.");
        i++;
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 55 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method testNegativeConsumerUserPassword.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21843", "RHEL7-51664" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: negative test for consumer user/password.", groups = { "Tier3Tests", "NegativeConsumerUserPassword_Test" }, dependsOnGroups = { "ConsumerCreated_Test" }, enabled = true)
@ImplementsNitrateTest(caseId = 50404)
public void testNegativeConsumerUserPassword() throws JSONException, Exception {
    String authuser = "", authpwd = "";
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    try {
        // enter the wrong user, correct passwd
        authuser = sm_client1Username + getRandInt();
        authpwd = sm_client1Password;
        CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
        consumerCert.consumerid, authuser, authpwd, sm_serverUrl);
        Assert.fail("Expected the candlepin server request for a syndication feed to return an HTTP response code 401 Unauthorized due to invalid authorization credentials " + authuser + ":" + authpwd);
    } catch (IOException e) {
        Assert.assertContainsMatch(e.getMessage(), "HTTP response code: 401", "Atom feed is unauthorized when attempting to authorize with credentials " + authuser + ":" + authpwd);
    }
    try {
        // enter the correct user, wrong passwd
        authuser = sm_client1Username;
        authpwd = sm_client1Password + getRandInt();
        CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
        consumerCert.consumerid, authuser, authpwd, sm_serverUrl);
        Assert.fail("Expected the candlepin server request for a syndication feed to return an HTTP response code 401 Unauthorized due to invalid authorization credentials " + authuser + ":" + authpwd);
    } catch (IOException e) {
        Assert.assertContainsMatch(e.getMessage(), "HTTP response code: 401", "Atom feed is unauthorized when attempting to authorize with credentials " + authuser + ":" + authpwd);
    }
    try {
        // enter the correct user, correct passwd for super admin atom
        authuser = sm_client1Username;
        authpwd = sm_client1Password;
        CandlepinTasks.getSyndFeed(authuser, authpwd, sm_serverUrl);
        Assert.fail("Expected the candlepin server request for a syndication feed to return an HTTP response code 401 Unauthorized due to invalid authorization credentials " + authuser + ":" + authpwd);
    } catch (IOException e) {
        Assert.assertContainsMatch(e.getMessage(), "HTTP response code: 403", "Atom feed is forbidden when attempting to authorize with credentials " + authuser + ":" + authpwd);
    }
    // finally assert success with valid credentials
    authuser = sm_client1Username;
    authpwd = sm_client1Password;
    SyndFeed feed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, authuser, authpwd, sm_serverUrl);
    Assert.assertTrue(!feed.getEntries().isEmpty(), "Atom feed for consumer events is successful with valid credentials " + authuser + ":" + authpwd);
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) IOException(java.io.IOException) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

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