Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Daniel Nordhoff-Vergien
Access service from other portlet
3. Mai 2013 07:06
Antwort

Daniel Nordhoff-Vergien

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 17. März 2013

Neue Beiträge

Hi,

when I try to access a service created with service builder from another plugin I get the following exception:
 1
 2 ERROR [http-bio-8080-exec-4][render_portlet_jsp:154] java.lang.ClassCastException: myservice.model.Bean cannot be cast to myservice.model.Bean
 3        at myservice.service.base.TaxonLocalServiceClpInvoker.invokeMethod(TaxonLocalServiceClpInvoker.java:52)
 4        at myservice.service.base.TaxonLocalServiceBaseImpl.invokeMethod(TaxonLocalServiceBaseImpl.java:276)
 5        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
 6        at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
 7        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
 8        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
 9        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
10        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
11        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
12        ...


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
David H Nebinger
RE: Access service from other portlet
3. Mai 2013 10:37
Antwort

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 11306

Eintrittsdatum: 1. September 2006

Neue Beiträge

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.