use of com.sun.syndication.io.FeedException 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);
}
}
use of com.sun.syndication.io.FeedException in project modules.playframework.org by playframework.
the class FeedCreationActor method createFeed.
private void createFeed(List<HistoricalEvent> historicalEvents, String feedType, File outputDirectory, String classifier) {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);
feed.setTitle("Play! Modules");
feed.setLink("http://modules.playframework.org");
feed.setUri("http://modules.playframework.org");
feed.setPublishedDate(new Date());
feed.setDescription("The Play! Framework's module repository feed");
List<SyndEntry> entries = new ArrayList<SyndEntry>(historicalEvents.size());
for (HistoricalEvent historicalEvent : historicalEvents) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(historicalEvent.category);
entry.setAuthor("Play framework modules");
entry.setPublishedDate(historicalEvent.creationDate);
// todo this will be the url of the module
entry.setLink("http://modules.playframework.org");
entry.setUri("mpo-he-" + historicalEvent.id);
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(historicalEvent.message);
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
Writer writer = null;
try {
File outputFile = new File(outputDirectory, String.format("mpo.%s.xml", classifier));
writer = new FileWriter(outputFile);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
writer.close();
} catch (IOException e) {
Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
} catch (FeedException e) {
Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
} finally {
IOUtils.close(writer);
}
}
use of com.sun.syndication.io.FeedException in project OpenClinica by OpenClinica.
the class RssReaderServlet method getFeed.
void getFeed(PrintWriter pw) {
SyndFeed feed = null;
String htmlFeed = null;
try {
feed = feedFetcher.retrieveFeed(new URL(rssUrl));
htmlFeed = feedHtml(feed);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FeedException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FetcherException e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
pw.println(htmlFeed);
pw.close();
}
}
use of com.sun.syndication.io.FeedException in project gitblit by gitblit.
the class SyndicationUtils method readFeed.
/**
* Reads a Gitblit RSS feed.
*
* @param url
* the url of the Gitblit server
* @param parameters
* the list of RSS parameters
* @param repository
* the repository name
* @param username
* @param password
* @return a list of SyndicationModel entries
* @throws {@link IOException}
*/
private static List<FeedEntryModel> readFeed(String url, List<String> parameters, String repository, String branch, String username, char[] password) throws IOException {
// build url
StringBuilder sb = new StringBuilder();
sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));
if (parameters.size() > 0) {
boolean first = true;
for (String parameter : parameters) {
if (first) {
sb.append('?');
first = false;
} else {
sb.append('&');
}
sb.append(parameter);
}
}
String feedUrl = sb.toString();
URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);
InputStream is = conn.getInputStream();
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
try {
feed = input.build(new XmlReader(is));
} catch (FeedException f) {
throw new GitBlitException(f);
}
is.close();
List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
for (Object o : feed.getEntries()) {
SyndEntryImpl entry = (SyndEntryImpl) o;
FeedEntryModel model = new FeedEntryModel();
model.repository = repository;
model.branch = branch;
model.title = entry.getTitle();
model.author = entry.getAuthor();
model.published = entry.getPublishedDate();
model.link = entry.getLink();
model.content = entry.getDescription().getValue();
model.contentType = entry.getDescription().getType();
if (entry.getCategories() != null && entry.getCategories().size() > 0) {
List<String> tags = new ArrayList<String>();
for (Object p : entry.getCategories()) {
SyndCategory cat = (SyndCategory) p;
tags.add(cat.getName());
}
model.tags = tags;
}
entries.add(model);
}
return entries;
}
use of com.sun.syndication.io.FeedException in project eol-globi-data by jhpoelen.
the class DatasetImporterForRSS method parseFeed.
private static SyndFeed parseFeed(Dataset datasetOrig) throws StudyImporterException {
SyndFeed feed;
String rss = getRSSEndpoint(datasetOrig);
try {
URI rssURI = URI.create(StringUtils.isBlank(rss) ? "rss" : rss);
feed = new SyndFeedInput().build(new XmlReader(datasetOrig.retrieve(rssURI)));
} catch (FeedException | IOException e) {
throw new StudyImporterException("failed to read rss feed [" + rss + "]", e);
}
return feed;
}
Aggregations