Search in sources :

Example 6 with FeedException

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);
    }
}
Also used : HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) WireFeedOutput(com.rometools.rome.io.WireFeedOutput) FeedException(com.rometools.rome.io.FeedException) Charset(java.nio.charset.Charset) MediaType(org.springframework.http.MediaType) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 7 with FeedException

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);
    }
}
Also used : WireFeedInput(com.rometools.rome.io.WireFeedInput) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FeedException(com.rometools.rome.io.FeedException) MediaType(org.springframework.http.MediaType) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 8 with FeedException

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);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) FeedException(com.rometools.rome.io.FeedException) IOException(java.io.IOException) URL(java.net.URL)

Example 9 with FeedException

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);
}
Also used : FeedException(com.rometools.rome.io.FeedException) URL(java.net.URL) Test(org.junit.Test)

Example 10 with FeedException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput)

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