Fórum

How to share plugin services to other plugin.

ruchi sharma, modificado 11 Anos atrás.

How to share plugin services to other plugin.

Junior Member Postagens: 95 Data de Entrada: 24/03/11 Postagens Recentes
Hello Friends,
I am trying to share my portlet 'A' services (portlet is in ext) to a other portlet 'B'(outside ext in sdk > portlet).
When I am trying to do so , I am getting the following exception...
java.lang.ClassCastException: $Proxy234 cannot be cast to com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalService
	at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getService(ArticleDisplayListLocalServiceUtil.java:340)
	at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getAuthorProfile(ArticleDisplayListLocalServiceUtil.java:236)
	at news.Corporate_News.getAssets(Corporate_News.java:141)
	at news.Corporate_News.doView(Corporate_News.java:102)
	at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:206)
	at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:294)
	at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
	at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
	at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


But when I share potlet 'A' services to hook 'H' , its working fine.
Don't why the same thing is working in Hook not in Portlet?
NOTE : I am having the jars files of portlet 'A' in the lib folder of Portlet 'B' and the Hook 'H' as well.
Please let me know.
Thanks
Ruchi
thumbnail
Miroslav Ligas, modificado 11 Anos atrás.

RE: How to share plugin services to other plugin.

New Member Postagens: 17 Data de Entrada: 23/02/12 Postagens Recentes
Hi

you have problems with the class loaders. The hook operate on the portal class loader so it has access to the ext classes, but portlet operate on his own class loader so you can't access them.

There are several ways how to approach this problem but the first question is Why you even need it?? It's really bad practice to try to access the portal-imp classes or ext classes from portlets.

The solution here would be to get the portal class loader and access the required classes form there. Have a look at PortalClassLoaderUtil.java, PortalBeanLocatorUtil.java

Miro
ruchi sharma, modificado 11 Anos atrás.

RE: How to share plugin services to other plugin.

Junior Member Postagens: 95 Data de Entrada: 24/03/11 Postagens Recentes
Hello Miro,

Thanks for the reply.
Atleast I got reason why its working on hooks not on portlets.

Well I can't modify the following method getservice() below in XLocalService Util class , bcoz its been generated by service builder automatically. (where the exception is coming as mentioned above)
You are right its a class loader problem ... as we can see the exception.
If you see other getservice() method we have class loader and clp classes, here in this method I am missing all those classes... this is because when I do buid services on the portlet A defined in ext it does not generate the clp class for me... Do you know any reason why this is happening ??
public static ArticleDisplayListLocalService getService() {
		if (_service == null) {
			_service = (ArticleDisplayListLocalService)PortalBeanLocatorUtil.locate(ArticleDisplayListLocalService.class.getName());
		}

		return _service;
	}


Here you can see the complete problem thread, (with code how I am calling the method from view.jsp in Portlet emoticon
http://www.liferay.com/community/forums/-/message_boards/message/13399872

Any suggestions ??
Thanks
Ruchi
Paul Butenko, modificado 11 Anos atrás.

RE: How to share plugin services to other plugin.

Junior Member Postagens: 38 Data de Entrada: 02/07/10 Postagens Recentes
Hello,
You can use required-deployment-contexts property of liferay-plugin-package.properties. It will make portlets dependend and share service layer.
Also you can check this post.

BR,
Paul
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: How to share plugin services to other plugin.

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Did you restart liferay after moving (not copying) portlet A jar file to lib\ext of the application server. Files in lib\ext are loaded during application server startup.
You also shouldn't put lib in each portlet after moving the jar to application server lib\ext because that would cause error.

Also, define your jar ins liferay-plugin-package.properties of each portlet.
ruchi sharma, modificado 11 Anos atrás.

RE: How to share plugin services to other plugin.

Junior Member Postagens: 95 Data de Entrada: 24/03/11 Postagens Recentes
Hi,

Hitoshi Ozawa:
Did you restart liferay after moving (not copying) portlet A jar file to lib\ext of the application server. Files in lib\ext are loaded during application server startup.
You also shouldn't put lib in each portlet after moving the jar to application server lib\ext because that would cause error.

Yes I did restart the server.... actually the portlet A jar file are in lib\ext of the application server (as the portlet A is in ext) and the same jars for ext are automatically generated in hooks / portlets in server/webapps/ Portlet A / WEB-INF/lib . I din't manually copy
those jar files.

Hitoshi Ozawa:
Also, define your jar ins liferay-plugin-package.properties of each portlet.

Today I tried to define the jars in liferay-plugin-package.properties , this also does work.
Thanks
Ruchi