Forums

angle-left Back

[RESOLVED] Develop portlet using RSSUtil and rome.jar classes

TC
Thomas C, modified 5 Years ago.

[RESOLVED] Develop portlet using RSSUtil and rome.jar classes

New Member Posts: 11 Join Date: 1/25/12 Recent Posts
Hi,

I try to developp a portlet using RSSUtil and rome.jar classes on Liferay 6.1.0.


SyndFeed feed = null;
final String className= "com.liferay.portlet.rss.util.RSSUtil";
MethodKey mKey = new MethodKey(className, "getFeed", String.class);
ObjectValuePair ovp = (ObjectValuePair)PortalClassInvoker.invoke(true, mKey , url);
feed = (SyndFeed)ovp.getValue();

The RSSUtil class is located in portal-impl. So I use PortalClassInvoker to use it.
When I use my code, I get the exception :


Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.sun.syndication.feed.synd.SyndFeedImpl
    at com.sun.syndication.io.SyndFeedInput.build(SyndFeedInput.java:123)
    at com.liferay.portlet.rss.util.RSSWebCacheItem.convert(RSSWebCacheItem.java:83)
    at com.liferay.portal.webcache.WebCachePoolImpl.get(WebCachePoolImpl.java:44)
    at com.liferay.portal.kernel.webcache.WebCachePoolUtil.get(WebCachePoolUtil.java:27)
    at com.liferay.portlet.rss.util.RSSUtil.getFeed(RSSUtil.java:34)


I think to a classLoader problem?
Any helps?

Regards
Thomas
Vilmos Papp, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

LIFERAY STAFF Liferay Master Posts: 522 Join Date: 10/21/10 Recent Posts
Hi,

It seems to be related to classloading. My first guess it to add rome.jar to the portal-depenecy-jars section of your liferay-plugin-package.properties file.

If it doesn't help you can check Activities portelt's RSSAction class to see how could you implement it by your own. Please note, that there are two RSSUtil classes one in util-java which has the export(SyndFeed) method.

Regards,
Vilmos
TC
Thomas C, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

New Member Posts: 11 Join Date: 1/25/12 Recent Posts
Hi,

I was thinking that too. Unfortunately adding rome.jar in portal-depenecy-jars section of liferay-plugin-package.properties file does'nt work.

This post :
http://osgi.dzone.com/articles/osgi-jumping-through
shows that it's related to classLoader...
TC
Thomas C, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

New Member Posts: 11 Join Date: 1/25/12 Recent Posts
In adding rome.jar in portal-depenecy-jars section of liferay-plugin-package.properties,
I have this exception now :

java.lang.ClassCastException: com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeed
Vilmos Papp, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

LIFERAY STAFF Liferay Master Posts: 522 Join Date: 10/21/10 Recent Posts
Hi,

That's wierd. I haven't tried to add RSS to plugins before, just built in portlets. If I have some time I'll check it what could be the problem, but it would be great if you could attach a sample code from plugins SDK what generates that error for you.

Regards,
Vilmos
Harish Kumar, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

Expert Posts: 478 Join Date: 7/31/10 Recent Posts
Thomas C:
In adding rome.jar in portal-depenecy-jars section of liferay-plugin-package.properties,
I have this exception now :

java.lang.ClassCastException: com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeed


Place the jar in \lib\ext and then try.

Regards,
TC
Thomas C, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

New Member Posts: 11 Join Date: 1/25/12 Recent Posts
Hi,

This is my code in a portlet file :

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

    ObjectValuePair ovp = (ObjectValuePair)PortalClassInvoker.invoke(true, _CONSTRUCTOR, url);
    PortalClassLoaderUtil.getClassLoader().loadClass("com.sun.syndication.feed.synd.SyndFeedImpl");
    feed = (SyndFeedImpl)ovp.getValue();
    if (Validator.isNull(title)) {
        title = feed.getTitle();
    }
}
catch (Exception e) {
}


As explain above, the RSSUtil class is located in portal-impl. So I use PortalClassInvoker to use it.
Moreover I added rome.jar to the portal-depenecy-jars section of my liferay-plugin-package.properties file.

And I got that error :


java.lang.ClassCastException: com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeedImpl
    at org.apache.jsp.WEB_002dINF.jsp.flux_002drss.view_jsp._jspService(view_jsp.java:422)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


I think for a classloader problem :
SyndFeedImpl feed = null;
is loaded in the portlet classloader
and
ovp.getValue();
is invoked with the portal classloader...

Thanks for your help
TC
Thomas C, modified 5 Years ago.

RE: Develop portlet using RSSUtil and rome.jar classes

New Member Posts: 11 Join Date: 1/25/12 Recent Posts
It was a ClassLoader problem.
In one hand, the portlet uses classes from "rome.jar" to show RSS streams.
In the other hand, the jar is loaded by the portal...

I resolve the problem by deleting the jar from the portal AND portlet libraries.
Then adding it to the extern tomcat libraries...