use of com.rometools.rome.io.FeedException in project blogwt by billy1380.
the class FeedServlet method doGet.
/* (non-Javadoc)
*
* @see com.willshex.service.ContextAwareServlet#doGet() */
@Override
protected void doGet() throws ServletException, IOException {
super.doGet();
Property generateRss = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.GENERATE_RSS_FEED);
if (PropertyHelper.isEmpty(generateRss) || Boolean.valueOf(generateRss.value).booleanValue()) {
HttpServletRequest request = REQUEST.get();
HttpServletResponse response = RESPONSE.get();
try {
SyndFeed feed = getFeed(request);
String feedType = request.getParameter(FEED_TYPE);
feedType = (feedType != null) ? feedType : defaultFeedType;
feed.setFeedType(feedType);
response.setContentType(MIME_TYPE);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
} catch (FeedException ex) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not generate feed");
}
}
}
use of com.rometools.rome.io.FeedException in project ddf by codice.
the class OpenSearchSource method processResponse.
/**
* @param is
* @param queryRequest
* @return
* @throws ddf.catalog.source.UnsupportedQueryException
*/
private SourceResponseImpl processResponse(InputStream is, QueryRequest queryRequest) throws UnsupportedQueryException {
List<Result> resultQueue = new ArrayList<>();
SyndFeedInput syndFeedInput = new SyndFeedInput();
SyndFeed syndFeed = null;
try {
syndFeed = syndFeedInput.build(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (FeedException e) {
LOGGER.debug("Unable to read RSS/Atom feed.", e);
}
List<SyndEntry> entries = null;
long totalResults = 0;
if (syndFeed != null) {
entries = syndFeed.getEntries();
for (SyndEntry entry : entries) {
resultQueue.addAll(createResponseFromEntry(entry));
}
totalResults = entries.size();
List<Element> foreignMarkup = syndFeed.getForeignMarkup();
for (Element element : foreignMarkup) {
if (element.getName().equals("totalResults")) {
try {
totalResults = Long.parseLong(element.getContent(0).getValue());
} catch (NumberFormatException | IndexOutOfBoundsException e) {
// totalResults is already initialized to the correct value, so don't change it here.
LOGGER.debug("Received invalid number of results.", e);
}
}
}
}
SourceResponseImpl response = new SourceResponseImpl(queryRequest, resultQueue);
response.setHits(totalResults);
return response;
}
use of com.rometools.rome.io.FeedException in project tika by apache.
the class FeedParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
// set the encoding?
try {
SyndFeed feed = new SyndFeedInput().build(new InputSource(new CloseShieldInputStream(stream)));
String title = stripTags(feed.getTitleEx());
String description = stripTags(feed.getDescriptionEx());
metadata.set(TikaCoreProperties.TITLE, title);
metadata.set(TikaCoreProperties.DESCRIPTION, description);
// store the other fields in the metadata
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
xhtml.element("h1", title);
xhtml.element("p", description);
xhtml.startElement("ul");
for (Object e : feed.getEntries()) {
SyndEntry entry = (SyndEntry) e;
String link = entry.getLink();
if (link != null) {
xhtml.startElement("li");
xhtml.startElement("a", "href", link);
xhtml.characters(stripTags(entry.getTitleEx()));
xhtml.endElement("a");
SyndContent content = entry.getDescription();
if (content != null) {
xhtml.newline();
xhtml.characters(stripTags(content));
}
xhtml.endElement("li");
}
}
xhtml.endElement("ul");
xhtml.endDocument();
} catch (FeedException e) {
throw new TikaException("RSS parse error", e);
}
}
use of com.rometools.rome.io.FeedException in project OpenOLAT by OpenOLAT.
the class PersonalRSSServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try (Writer writer = response.getWriter()) {
String pathInfo = request.getPathInfo();
if ((pathInfo == null) || (pathInfo.equals(""))) {
// error
return;
}
SyndFeed feed = null;
// pathInfo is like /personal/username/tokenid.rss
if (pathInfo.indexOf(PersonalRSSUtil.RSS_PREFIX_PERSONAL) == 0) {
feed = getPersonalFeed(pathInfo);
if (feed == null) {
DispatcherModule.sendNotFound(pathInfo, response);
return;
}
} else {
DispatcherModule.sendNotFound(pathInfo, response);
return;
}
// OLAT-5400 and OLAT-5243 related: sending back the reply can take arbitrary long,
// considering slow end-user connections for example - or a sudden death of the connection
// on the client-side which remains unnoticed (network partitioning)
DBFactory.getInstance().intermediateCommit();
response.setBufferSize(response.getBufferSize());
String encoding = feed.getEncoding();
if (encoding == null) {
encoding = DEFAULT_ENCODING;
if (log.isDebug()) {
log.debug("Feed encoding::" + encoding);
}
log.warn("No encoding provided by feed::" + feed.getClass().getCanonicalName() + " Using utf-8 as default.");
}
response.setCharacterEncoding(encoding);
response.setContentType("application/rss+xml");
Date pubDate = feed.getPublishedDate();
if (pubDate != null) {
response.setDateHeader("Last-Modified", pubDate.getTime());
}
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
} catch (FeedException e) {
// throw olat exception for nice logging
log.warn("Error when generating RSS stream for path::" + request.getPathInfo(), e);
DispatcherModule.sendNotFound("none", response);
} catch (Exception e) {
log.warn("Unknown Exception in rssservlet", e);
DispatcherModule.sendNotFound("none", response);
} catch (Error e) {
log.warn("Unknown Error in rssservlet", e);
DispatcherModule.sendNotFound("none", response);
} finally {
DBFactory.getInstance().commitAndCloseSession();
}
}
use of com.rometools.rome.io.FeedException in project opencast by opencast.
the class FeedServiceImpl method getFeed.
/*
* Note: We're using Regex matching for the path here, instead of normal JAX-RS paths. Previously this class was a servlet,
* which was fine except that it had auth issues. Removing the servlet fixed the auth issues, but then the paths (as written
* in the RestQuery docs) don't work because JAX-RS does not support having "/" characters as part of the variable's value.
*
* So, what we've done instead is match everything that comes in under the /feeds/ namespace, and then substring it out the way
* the old servlet code did. But without the servlet, or auth issues :)
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("{query: .*}")
// FIXME: These Opencast REST classes do not support this path style, and need to have that support added
@RestQuery(name = "getFeed", description = "Gets an Atom or RSS feed", pathParameters = { @RestParameter(description = "The feed type", name = "type", type = Type.STRING, isRequired = true), @RestParameter(description = "The feed version", name = "version", type = Type.STRING, isRequired = true), @RestParameter(description = "The feed query", name = "query", type = Type.STRING, isRequired = true) }, reponses = { @RestResponse(description = "Return the feed of the appropriate type", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response getFeed(@Context HttpServletRequest request) {
String contentType = null;
logger.debug("Requesting RSS or Atom feed.");
FeedInfo feedInfo = null;
Organization organization = securityService.getOrganization();
// Try to extract requested feed type and content
try {
feedInfo = extractFeedInfo(request);
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).build();
}
// Set the content type
if (feedInfo.getType().equals(Feed.Type.Atom))
contentType = "application/atom+xml";
else if (feedInfo.getType().equals(Feed.Type.RSS))
contentType = "application/rss+xml";
// Have a feed generator create the requested feed
Feed feed = null;
for (FeedGenerator generator : feeds) {
if (generator.accept(feedInfo.getQuery())) {
feed = generator.createFeed(feedInfo.getType(), feedInfo.getQuery(), feedInfo.getSize(), organization);
if (feed == null) {
return Response.serverError().build();
}
break;
}
}
// Have we found a feed generator?
if (feed == null) {
logger.debug("RSS/Atom feed could not be generated");
return Response.status(Status.NOT_FOUND).build();
}
// Set character encoding
Variant v = new Variant(MediaType.valueOf(contentType), null, feed.getEncoding());
String outputString = null;
try {
if (feedInfo.getType().equals(Feed.Type.RSS)) {
logger.debug("Creating RSS feed output.");
SyndFeedOutput output = new SyndFeedOutput();
outputString = output.outputString(new RomeRssFeed(feed, feedInfo));
} else {
logger.debug("Creating Atom feed output.");
WireFeedOutput output = new WireFeedOutput();
outputString = output.outputString(new RomeAtomFeed(feed, feedInfo));
}
} catch (FeedException e) {
return Response.serverError().build();
}
return Response.ok(outputString, v).build();
}
Aggregations