Fórumok

Access service from other portlet

Daniel Nordhoff-Vergien, módosítva 10 év-val korábban

Access service from other portlet

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.03.17. Legújabb bejegyzések
Hi,

when I try to access a service created with service builder from another plugin I get the following exception:

 ERROR [http-bio-8080-exec-4][render_portlet_jsp:154] java.lang.ClassCastException: myservice.model.Bean cannot be cast to myservice.model.Bean
        at myservice.service.base.TaxonLocalServiceClpInvoker.invokeMethod(TaxonLocalServiceClpInvoker.java:52)
        at myservice.service.base.TaxonLocalServiceBaseImpl.invokeMethod(TaxonLocalServiceBaseImpl.java:276)
        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
        at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
        ...


This only happens when the parameter of return value of the service is a "custom" class, not one like java.lang.String. My classes are in a separate jar which is packed as a dependency via maven to both projects.

Regards

Daniel
thumbnail
David H Nebinger, módosítva 10 év-val korábban

RE: Access service from other portlet

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
You cannot do this.

Service builder crosses the class loader boundary between the plugin providing the service and the plugin consuming the service.

Even though your class is in a separate jar and may be part of both projects, the separate class loaders involve will load classes that cannot be passed across the boundary.

Your two choices would be

a) move the jar file to the global lib (tomcat's lib/ext directory), this would make the instance at the global level so it removes the class loader issue, but the jar cannot be updated when the application container is running.

b) define your objects as entities in the service.xml file. SB can pass entities, but not regular classes. Entities are normally backed by the database, but I have an example here that uses what I call 'fake' entities, or entities that are not backed by the database but are still defined as entities in the service.xml file.

Taking route b) is the best option, as this does not have the requirement of stopping the app container to deploy an update, but it takes more work on your part to get you there.