Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Daniel Nordhoff-Vergien
Access service from other portlet
May 3, 2013 7:06 AM

Daniel Nordhoff-Vergien

Rank: New Member

Posts: 7

Join Date: March 17, 2013

Recent Posts


when I try to access a service created with service builder from another plugin I get the following exception:
 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(
 4        at myservice.service.base.TaxonLocalServiceBaseImpl.invokeMethod(
 5        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
 6        at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(
 7        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(
 8        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
 9        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(
10        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
11        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(
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.


David H Nebinger
RE: Access service from other portlet
May 3, 2013 10:37 AM

David H Nebinger

Rank: Liferay Legend

Posts: 6256

Join Date: September 1, 2006

Recent Posts

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.