use of com.rometools.rome.io.FeedException in project spring-framework by spring-projects.
the class AbstractWireFeedHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType != null) {
contentType = new MediaType(contentType, charset);
outputMessage.getHeaders().setContentType(contentType);
}
WireFeedOutput feedOutput = new WireFeedOutput();
try {
Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset);
feedOutput.output(wireFeed, writer);
} catch (FeedException ex) {
throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
}
}
use of com.rometools.rome.io.FeedException in project spring-framework by spring-projects.
the class AbstractWireFeedHttpMessageConverter method readInternal.
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
WireFeedInput feedInput = new WireFeedInput();
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : DEFAULT_CHARSET);
try {
InputStream inputStream = StreamUtils.nonClosing(inputMessage.getBody());
Reader reader = new InputStreamReader(inputStream, charset);
return (T) feedInput.build(reader);
} catch (FeedException ex) {
throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex, inputMessage);
}
}
use of com.rometools.rome.io.FeedException in project coffeenet-frontpage-plugin-rss by coffeenet.
the class BlogParser method parse.
@Override
public List<BlogEntry> parse(String blogUrl, int limit, int length) {
try {
URL url = new URL(blogUrl);
SyndFeed feed = feedFactory.build(url);
return feed.getEntries().stream().limit(limit).map(toBlogEntry(length)).collect(toList());
} catch (FeedException | IOException e) {
throw new ParserException("Failed to parse blog with rss link " + blogUrl, e);
}
}
use of com.rometools.rome.io.FeedException in project coffeenet-frontpage-plugin-rss by coffeenet.
the class BlogParserTest method parseBlogInvalidFeed.
@Test(expected = ParserException.class)
public void parseBlogInvalidFeed() throws FeedException, IOException {
when(feedFactory.build(any(URL.class))).thenThrow(new FeedException("foo"));
sut.parse("http://intblog/feed/", 10, 1);
}
use of com.rometools.rome.io.FeedException in project ddf by codice.
the class OpenSearchSource method processResponse.
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;
long totalResults = 0;
List<Element> foreignMarkup = null;
if (syndFeed != null) {
entries = syndFeed.getEntries();
for (SyndEntry entry : entries) {
resultQueue.addAll(createResponseFromEntry(entry));
}
totalResults = entries.size();
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);
if (foreignMarkup != null) {
this.foreignMarkupBiConsumer.accept(Collections.unmodifiableList(foreignMarkup), response);
}
return response;
}
Aggregations