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);
}
}
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\"");
}
}
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;
}
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();
}
}
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();
}
}
}
Aggregations