掲示板
Access own Services from Beanshell scripts
8年前 に Morad Ahmad によって更新されました。
Access own Services from Beanshell scripts
Junior Member 投稿: 71 参加年月日: 10/06/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.
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.
8年前 に David H Nebinger によって更新されました。
RE: Access own Services from Beanshell scripts
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Use PortletBeanLocatorUtil to find them.
8年前 に Morad Ahmad によって更新されました。
RE: Access own Services from Beanshell scripts
Junior Member 投稿: 71 参加年月日: 10/06/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.
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.
8年前 に David H Nebinger によって更新されました。
RE: Access own Services from Beanshell scripts
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
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.
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.