Search in sources :

Example 11 with FeedException

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);
    }
}
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 12 with FeedException

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);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) HistoricalEvent(models.HistoricalEvent) FileWriter(java.io.FileWriter) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with FeedException

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();
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FetcherException(com.sun.syndication.fetcher.FetcherException) FeedException(com.sun.syndication.io.FeedException) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) FeedException(com.sun.syndication.io.FeedException) FetcherException(com.sun.syndication.fetcher.FetcherException)

Example 14 with FeedException

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;
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) FeedEntryModel(com.gitblit.models.FeedEntryModel) InputStream(java.io.InputStream) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) XmlReader(com.sun.syndication.io.XmlReader) URLConnection(java.net.URLConnection) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 15 with FeedException

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) FeedException(com.sun.syndication.io.FeedException) XmlReader(com.sun.syndication.io.XmlReader) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

FeedException (com.sun.syndication.io.FeedException)15 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)9 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)5 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)5 Date (java.util.Date)5 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)4 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)3 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)3 XmlReader (com.sun.syndication.io.XmlReader)3 SyndContent (com.sun.syndication.feed.synd.SyndContent)2 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)2 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 RssFeedEntry (org.apache.archiva.rss.RssFeedEntry)2 GitBlitException (com.gitblit.GitBlitException)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1