0

I would like use RSSUtil to read an RSS feed but i'm facing a problem with the class loader...

The exception thrown is :

com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeedImpl

My Code is :

        SyndFeedImpl feed = null;
        final String _CLASS_NAME = "com.liferay.portlet.rss.util.RSSUtil";
        MethodKey _CONSTRUCTOR = new MethodKey(_CLASS_NAME, "getFeed", String.class);

        ObjectValuePair ovp = (ObjectValuePair) PortalClassInvoker.invoke(true, _CONSTRUCTOR, url);
        Class<SyndFeed> clazz = (Class<SyndFeed>) PortalClassLoaderUtil.getClassLoader().loadClass(
                "com.sun.syndication.feed.synd.SyndFeedImpl");

         feed = (SyndFeedImpl) ovp.getValue();

The problem is also explained in https://www.liferay.com/fr/community/forums/-/message_boards/message/15812507. I tried to do the same things but it doesn't work...

Thanks in advance for your help...

UPDATE : if i use the code below (other solution without RSSUtil) :

        URL feedUrl = new URL(url);
        HttpURLConnection httpcon = (HttpURLConnection) feedUrl.openConnection();

        SyndFeedInput input = new SyndFeedInput();
        XmlReader reader = new XmlReader(httpcon);
        SyndFeed feed = input.build(reader);

The exception thrown is :

java.lang.ClassCastException: com.sun.syndication.feed.synd.impl.ConverterForAtom10 cannot be cast to com.sun.syndication.feed.synd.Converter
Denis Cucchietti
  • 201
  • 6
  • 16

1 Answers1

0

i've faced the same problem. I've ended up copying two jars (dom4j.jar and rome.jar) from liferayroot/tomcatxxx/webapps/ROOT/WEB-INF/lib to liferayroot/tomcatxxx/lib/ext

The first error you get is because the class are loaded by differents class loaders (the portal class loader and your portlet class loader).

Try copy the jars, should work