Search in sources :

Example 1 with FeedException

use of com.rometools.rome.io.FeedException in project asterixdb by apache.

the class RSSFeedServlet method get.

@Override
protected void get(IServletRequest req, IServletResponse res) throws IOException {
    try {
        SyndFeed feed = getFeed(req);
        String feedType = req.getParameter(FEED_TYPE);
        feedType = (feedType != null) ? feedType : defaultFeedType;
        feed.setFeedType(feedType);
        HttpUtil.setContentType(res, MIME_TYPE);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, res.writer());
    } catch (FeedException | ParseException ex) {
        GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, ex.getMessage(), ex);
        String msg = COULD_NOT_GENERATE_FEED_ERROR;
        res.writer().print(msg);
        res.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) FeedException(com.rometools.rome.io.FeedException) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) ParseException(java.text.ParseException)

Example 2 with FeedException

use of com.rometools.rome.io.FeedException in project BIMserver by opensourceBIM.

the class SyndicationServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (request.getHeader("Origin") != null && !getBimServer().getServerSettingsCache().isHostAllowed(request.getHeader("Origin"))) {
        response.setStatus(403);
        return;
    }
    if (request.getHeader("Authorization") != null) {
        String authorization = request.getHeader("Authorization");
        String usernamePasswordEncoded = authorization.substring(6);
        String decodeBase64 = new String(Base64.decodeBase64(usernamePasswordEncoded.getBytes(Charsets.UTF_8)), Charsets.UTF_8);
        if (decodeBase64.equals(":")) {
            response.getWriter().print("Not authenticated");
            return;
        }
        String[] split = decodeBase64.split(":");
        String username = split[0];
        String password = split[1];
        String token = (String) getServletContext().getAttribute("token");
        ServiceMap serviceMap = null;
        try {
            if (token == null) {
                serviceMap = getBimServer().getServiceFactory().get(AccessMethod.SYNDICATION);
            } else {
                serviceMap = getBimServer().getServiceFactory().get(token, AccessMethod.SYNDICATION);
            }
            if (serviceMap.getAuthInterface().login(username, password) != null) {
                String requestURI = request.getRequestURI();
                response.setContentType("application/atom+xml");
                try {
                    if (requestURI.endsWith("/projects")) {
                        writeProjectsFeed(request, response, serviceMap);
                    } else if (requestURI.contains("/revisions")) {
                        writeRevisionsFeed(request, response, serviceMap);
                    } else if (requestURI.contains("/checkouts")) {
                        writeCheckoutsFeed(request, response, serviceMap);
                    }
                } catch (ServiceException e) {
                    response.setContentType("text/html");
                    response.getWriter().println(e.getUserMessage());
                } catch (FeedException e) {
                    LOGGER.error("", e);
                }
            } else {
                response.setStatus(401);
                response.setHeader("WWW-Authenticate", "Basic realm=\"Secure Area\"");
            }
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } catch (PublicInterfaceNotFoundException e) {
            LOGGER.error("", e);
        }
    } else {
        response.setStatus(401);
        response.setHeader("WWW-Authenticate", "Basic realm=\"Secure Area\"");
    }
}
Also used : ServiceMap(org.bimserver.webservices.ServiceMap) ServiceException(org.bimserver.shared.exceptions.ServiceException) FeedException(com.rometools.rome.io.FeedException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Example 3 with FeedException

use of com.rometools.rome.io.FeedException in project KaellyBot by Kaysoro.

the class RSS method getRSSFeeds.

public static List<RSS> getRSSFeeds(Language lg) {
    List<RSS> rss = new ArrayList<>();
    try {
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(new XmlReader(new URL(Translator.getLabel(lg, "game.url") + Translator.getLabel(lg, "feed.url"))));
        for (SyndEntry entry : feed.getEntries()) {
            Matcher m = Pattern.compile("<img.+src=\"(.*\\.jpg)\".+>").matcher(entry.getDescription().getValue());
            rss.add(new RSS(entry.getTitle(), entry.getLink(), (m.find() ? m.group(1) : null), entry.getPublishedDate().getTime()));
        }
    } catch (FeedException e) {
        Reporter.report(e);
        LOG.error("getRSSFeeds", e);
    } catch (IOException e) {
        ExceptionManager.manageSilentlyIOException(e);
    } catch (Exception e) {
        ExceptionManager.manageSilentlyException(e);
    }
    Collections.sort(rss);
    return rss;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Matcher(java.util.regex.Matcher) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) FeedException(com.rometools.rome.io.FeedException)

Example 4 with FeedException

use of com.rometools.rome.io.FeedException in project tutorials by eugenp.

the class JsonChannelHttpMessageConverter method writeInternal.

@Override
protected void writeInternal(Channel wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    WireFeedOutput feedOutput = new WireFeedOutput();
    try {
        String xmlStr = feedOutput.outputString(wireFeed, true);
        JSONObject xmlJSONObj = XML.toJSONObject(xmlStr);
        String jsonPrettyPrintString = xmlJSONObj.toString(4);
        outputMessage.getBody().write(jsonPrettyPrintString.getBytes());
    } catch (JSONException | FeedException e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) WireFeedOutput(com.rometools.rome.io.WireFeedOutput) FeedException(com.rometools.rome.io.FeedException) JSONException(org.json.JSONException)

Example 5 with FeedException

use of com.rometools.rome.io.FeedException in project muikku by otavanopisto.

the class FeedSynchronizer method updateFeeds.

@Schedule(second = "0", minute = "0", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateFeeds() {
    Client client = ClientBuilder.newClient();
    feedItemDao.deleteAll();
    List<Feed> feeds = feedDao.listAll();
    for (Feed feed : feeds) {
        WebTarget target = client.target(feed.getUrl());
        try (InputStream stream = target.request("*").get(InputStream.class)) {
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed syndFeed = input.build(new XmlReader(stream));
            List<SyndEntry> entries = syndFeed.getEntries();
            for (SyndEntry entry : entries) {
                feedItemDao.create(entry.getTitle(), entry.getLink(), entry.getAuthor(), entry.getDescription() == null ? null : clean(entry.getDescription().getValue()), entry.getPublishedDate(), (String) null, feed);
            }
        } catch (IOException | IllegalArgumentException | FeedException e) {
            logger.warning(String.format("Error while synchronizing feeds: %s", e.getMessage()));
            ejbContext.setRollbackOnly();
        }
    }
}
Also used : InputStream(java.io.InputStream) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(fi.otavanopisto.muikku.plugins.feed.model.Feed) TransactionAttribute(javax.ejb.TransactionAttribute) Schedule(javax.ejb.Schedule)

Aggregations

FeedException (com.rometools.rome.io.FeedException)19 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)13 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)7 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)7 IOException (java.io.IOException)6 URL (java.net.URL)6 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)5 XmlReader (com.rometools.rome.io.XmlReader)4 WireFeedOutput (com.rometools.rome.io.WireFeedOutput)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SyndContent (com.rometools.rome.feed.synd.SyndContent)2 Result (ddf.catalog.data.Result)2 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)2 Reader (java.io.Reader)2 Charset (java.nio.charset.Charset)2 Element (org.jdom2.Element)2