use of com.sun.syndication.io.SyndFeedInput in project jersey by jersey.
the class FeedDownloader method apply.
@Override
@SuppressWarnings("unchecked")
public List<SyndEntry> apply(URL url) {
try (XmlReader xmlReader = new XmlReader(url)) {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(xmlReader);
return feed.getEntries();
} catch (Exception e) {
LOG.warn("An error during downloading and parsing a given feed: " + url, e);
}
return Collections.emptyList();
}
use of com.sun.syndication.io.SyndFeedInput in project cubrid-manager by CUBRID.
the class NoticeDashboardEntity method readFeedFromRemote.
/**
* get syndFeed from rss
*
* @param source
* @return
* @throws IllegalArgumentException
* @throws FeedException
* @throws IOException
*/
private void readFeedFromRemote() throws IllegalArgumentException, FeedException, IOException {
SyndFeedInput input = new SyndFeedInput();
// Locale.setDefault(Locale.ENGLISH);
URLConnection feedUrl = new URL(rssurl).openConnection();
// java.io.IOException: Server returned HTTP response code: 403
feedUrl.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
feedUrl.setConnectTimeout(5000);
XmlReader xmlReader = new XmlReader(feedUrl);
rssData = input.build(xmlReader);
}
use of com.sun.syndication.io.SyndFeedInput in project camel by apache.
the class RssUtils method createFeed.
public static SyndFeed createFeed(String feedUri, ClassLoader classLoader) throws Exception {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
InputStream in = new URL(feedUri).openStream();
SyndFeedInput input = new SyndFeedInput();
return input.build(new XmlReader(in));
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
use of com.sun.syndication.io.SyndFeedInput in project rhsm-qe by RedHatQE.
the class CandlepinTasks method getSyndFeedFor.
protected static SyndFeed getSyndFeedFor(String candlepinUsername, String candlepinPassword, String url, String path) throws IOException, IllegalArgumentException, FeedException {
/* References:
* http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html
* http://www.avajava.com/tutorials/lessons/how-do-i-connect-to-a-url-using-basic-authentication.html
* http://wiki.java.net/bin/view/Javawsxml/Rome
*/
// Notes: Alternative curl approach to getting the atom feed:
// [ajay@garuda-rh proxy{pool_refresh}]$ curl -k -u admin:admin --request GET "https://localhost:8443/candlepin/owners/admin/atom" > /tmp/atom.xml; xmllint --format /tmp/atom.xml > /tmp/atom1.xml
// from https://bugzilla.redhat.com/show_bug.cgi?id=645597
SSLCertificateTruster.trustAllCerts();
// set the atom feed url for an owner, consumer, or null
// String url = String.format("https://%s:%s%s%s/atom", candlepinHostname, candlepinPort, candlepinPrefix, path);
url = url + path + "/atom";
// if (ownerORconsumer!=null && key!=null) {
// url = String.format("https://%s:%s%s/%s/%s/atom", candlepinHostname, candlepinPort, candlepinPrefix, ownerORconsumer, key);
// }
log.fine("SyndFeedUrl: " + url);
String authString = candlepinUsername + ":" + candlepinPassword;
log.finer("SyndFeedAuthenticationString: " + authString);
byte[] authEncBytes = Base64.encodeBytesToBytes(authString.getBytes());
String authStringEnc = new String(authEncBytes);
log.finer("SyndFeed Base64 encoded SyndFeedAuthenticationString: " + authStringEnc);
SyndFeed feed = null;
URL feedUrl = null;
URLConnection urlConnection = null;
feedUrl = new URL(url);
urlConnection = feedUrl.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
SyndFeedInput input = new SyndFeedInput();
XmlReader xmlReader = new XmlReader(urlConnection);
feed = input.build(xmlReader);
// debug logging
log.finest("SyndFeed from " + feedUrl + ":\n" + feed);
// log.fine("SyndFeed from "+feedUrl+":\n"+feed);
if (feed.getEntries().size() == 0) {
log.fine(String.format("%s entries[] is empty", feed.getTitle()));
} else
for (int i = 0; i < feed.getEntries().size(); i++) {
log.fine(String.format("%s entries[%d].title=%s description=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription() == null ? "null" : ((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue()));
// log.fine(String.format("%s entries[%d].title=%s description=%s updatedDate=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription()==null?"null":((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue(), ((SyndEntryImpl) feed.getEntries().get(i)).getUpdatedDate()));
// log.fine(String.format("%s entries[%d].title=%s description=%s updatedDate=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription()==null?"null":((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue(), formatDateString( ((SyndEntryImpl) feed.getEntries().get(i)).getUpdatedDate()) ));
}
return feed;
}
use of com.sun.syndication.io.SyndFeedInput in project eclipse-integration-commons by spring-projects.
the class AggregateFeedJob method run.
@Override
protected IStatus run(final IProgressMonitor monitor) {
synchronized (getClass()) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
Job[] buildJobs = Job.getJobManager().find(CONTENT_FAMILY);
for (Job curr : buildJobs) {
if (curr != this && curr instanceof AggregateFeedJob) {
AggregateFeedJob job = (AggregateFeedJob) curr;
if (job.isCoveredBy(this)) {
curr.cancel();
}
}
}
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final CountDownLatch resultLatch = new CountDownLatch(1);
Runnable downloadRunnable = new Runnable() {
public void run() {
SyndFeedInput input = new SyndFeedInput();
Map<String, String> feedToContent = new HashMap<String, String>();
try {
Set<Entry<String, String>> entrySet = feedsToIconsMap.entrySet();
SubMonitor progress = SubMonitor.convert(monitor, entrySet.size());
if (!entrySet.isEmpty()) {
Iterator<Entry<String, String>> iter = entrySet.iterator();
while (iter.hasNext()) {
Entry<String, String> entry = iter.next();
String feedUrlStr = entry.getKey();
String iconPath = entry.getValue();
XmlReader reader;
if (feedUrlStr.startsWith("http")) {
reader = new XmlReader(HttpUtil.stream(new URI(feedUrlStr), progress.newChild(1)));
} else {
InputStream stream = FileLocator.openStream(IdeUiPlugin.getDefault().getBundle(), new Path(feedUrlStr), false);
reader = new XmlReader(stream);
}
StringBuilder cachedFeed = new StringBuilder();
char[] buffer = new char[256];
int length = 0;
while ((length = reader.read(buffer)) > 0) {
cachedFeed.append(buffer, 0, length);
}
reader.close();
feedReader.readFeeds(new StringReader(cachedFeed.toString()), input, iconPath);
feedToContent.put(feedUrlStr, cachedFeed.toString());
}
}
feedManager.cacheFeeds(feedToContent);
} catch (Exception e) {
// do nothing, feeds read from cache
}
resultLatch.countDown();
}
};
try {
new Thread(downloadRunnable).start();
if (resultLatch.await(30, TimeUnit.SECONDS)) {
updateNotifications(monitor);
return Status.OK_STATUS;
} else {
// reading from cache if it exists
try {
feedManager.readCachedFeeds(monitor);
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
}
}
} catch (InterruptedException e) {
}
updateNotifications(monitor);
return Status.CANCEL_STATUS;
}
Aggregations