Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
ruchi sharma
How to share plugin services to other plugin.
28 de Maio de 2012 06:33
Resposta

ruchi sharma

Ranking: Junior Member

Mensagens: 95

Data de entrada: 24 de Março de 2011

Mensagens 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...
 1java.lang.ClassCastException: $Proxy234 cannot be cast to com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalService
 2    at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getService(ArticleDisplayListLocalServiceUtil.java:340)
 3    at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getAuthorProfile(ArticleDisplayListLocalServiceUtil.java:236)
 4    at news.Corporate_News.getAssets(Corporate_News.java:141)
 5    at news.Corporate_News.doView(Corporate_News.java:102)
 6    at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:206)
 7    at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:294)
 8    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
 9    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
10    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
11    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
12    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
Miroslav Ligas
RE: How to share plugin services to other plugin.
28 de Maio de 2012 10:24
Resposta

Miroslav Ligas

Ranking: New Member

Mensagens: 2

Data de entrada: 23 de Fevereiro de 2012

Mensagens 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
Hitoshi Ozawa
RE: How to share plugin services to other plugin.
28 de Maio de 2012 16:02
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens 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
RE: How to share plugin services to other plugin.
29 de Maio de 2012 02:23
Resposta

ruchi sharma

Ranking: Junior Member

Mensagens: 95

Data de entrada: 24 de Março de 2011

Mensagens 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
ruchi sharma
RE: How to share plugin services to other plugin.
29 de Maio de 2012 02:39
Resposta

ruchi sharma

Ranking: Junior Member

Mensagens: 95

Data de entrada: 24 de Março de 2011

Mensagens 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 ??
1public static ArticleDisplayListLocalService getService() {
2        if (_service == null) {
3            _service = (ArticleDisplayListLocalService)PortalBeanLocatorUtil.locate(ArticleDisplayListLocalService.class.getName());
4        }
5
6        return _service;
7    }


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
RE: How to share plugin services to other plugin.
25 de Julho de 2012 04:56
Resposta

Paul Butenko

Ranking: Junior Member

Mensagens: 38

Data de entrada: 1 de Julho de 2010

Mensagens 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