我想使用 RSSUtil 来读取 RSS 提要,但我遇到了类加载器的问题......
抛出的异常是:
com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeedImpl
我的代码是:
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();
该问题也在https://www.liferay.com/fr/community/forums/-/message_boards/message/15812507中进行了解释。我试图做同样的事情,但它不起作用......
在此先感谢您的帮助...
更新:如果我使用下面的代码(没有 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);
抛出的异常是:
java.lang.ClassCastException: com.sun.syndication.feed.synd.impl.ConverterForAtom10 cannot be cast to com.sun.syndication.feed.synd.Converter