留言板

Access own Services from Beanshell scripts

Morad Ahmad,修改在8 年前。

Access own Services from Beanshell scripts

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Hi all,

I use Beanshell to write some administrative tools for my portal. I put my "tango-portlet-service.jar" "/lib/ext/" of tomact to be able to access my services from other plugins. In some scripts i manged to access the services. but sometimes i got the error that "beanlocator" can't find the beans for my services. How can I access custom services from Beanshell?

Thank you,
Morad.
thumbnail
David H Nebinger,修改在8 年前。

RE: Access own Services from Beanshell scripts

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
Use PortletBeanLocatorUtil to find them.
Morad Ahmad,修改在8 年前。

RE: Access own Services from Beanshell scripts

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Thank you David,

yes these helps me. But there is still a little problem:

if I use it like these (without cast to service interface):
Object tangoMessageEntryLocalService = PortletBeanLocatorUtil.locate("tango-portlet", "de.portango.service.TangoMessageEntryLocalService");
if(tangoMessageEntryLocalService == null) {
System.out.println("couldn't find tangoMessageEntryLocalService!");
return;
}
tangoMessageEntryLocalService.addTangoMessageEntry(userId, groupId, title, text, thumbnail, serviceContext);

it woks will.

But if i try to cast the bean:


TangoMessageEntryLocalService tangoMessageEntryLocalService = (TangoMessageEntryLocalService) PortletBeanLocatorUtil.locate("tango-portlet", "de.portango.service.TangoMessageEntryLocalService");
if(tangoMessageEntryLocalService == null) {
System.out.println("couldn't find tangoMessageEntryLocalService!");
return;
}
tangoMessageEntryLocalService.addTangoMessageEntry(userId, groupId, title, text, thumbnail, serviceContext);

I got a casting error can't cast Proxy.... to service.

And It's also strange that I cane some times use "TangoMessageEntryLocalServiceUtil.someMethod(...)" with no problems and sometimes not!!! I have no Idea
what is the reason???

Thanks you so much,
Morad.
thumbnail
David H Nebinger,修改在8 年前。

RE: Access own Services from Beanshell scripts

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
You will get a casting error when there are multiple service jars in play and the interface is loaded by a different class loader.

The XxxLocalServiceUtil can be used if the portlet starts after the service provider, either by accident by naming or purposefully when you correctly add a required-deployment-context entry in liferay-plugin-package.properties.