Foros de discusión

How to access portal specific -LocalServiceUtil methods in groovy script

Ashish Ashok, modificado hace 10 años.

How to access portal specific -LocalServiceUtil methods in groovy script

New Member Mensajes: 11 Fecha de incorporación: 18/06/13 Mensajes recientes
I am currently creating a workflow which includes an action. The scripting language I am using is groovy. I am trying to access my methods from my custom portlet. But it does not seem to work.


import com.xxxx.chameleon.service.DummyLocalServiceUtil;
DummyLocalServiceUtil.getJournalTemplate(10180,"MOVIETEMPLATE");


So I then tried to go to
Control panel -> Server Administration -> script

In the script I added the above code. Once I run the script I get the following error


20:49:23,596 ERROR [http-bio-8080-exec-96][EditServerAction:475] startup failed:
Script15.groovy: 1: unable to resolve class com.xxxx.chameleon.service.DummyLocalServiceUtil
 @ line 1, column 1.
   import com.xxxx.chameleon.service.DummyLocalServiceUtil;
   ^

1 error

Line 1: import com.xxxx.chameleon.service.DummyLocalServiceUtil;
Line 2: DummyLocalServiceUtil.getJournalTemplate(10180,"MOVIETEMPLATE");


Can anyone please explain me how to work on this issue. Thanks in advance.
thumbnail
Amos Fong, modificado hace 10 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Hi Ashish,

The problem is the groovy script executed by the portal, which is in the portal's classloader. Your service is in your plugin and thus not available to the portal. I'm not sure if it's possible to somehow manipulate the classloader in groovy, but one thing you can do is move your plugin's service.jar (and remove it from your plugin) to the app server's global lib.
thumbnail
Mohammad Azharuddin, modificado hace 7 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
Amos Fong:
Hi Ashish,

The problem is the groovy script executed by the portal, which is in the portal's classloader. Your service is in your plugin and thus not available to the portal. I'm not sure if it's possible to somehow manipulate the classloader in groovy, but one thing you can do is move your plugin's service.jar (and remove it from your plugin) to the app server's global lib.


Hi All

can some one help me to manipulate the classloader in groovy. I am on LR7
thumbnail
Amos Fong, modificado hace 7 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Hey Mohammed,

Since making this post, I've learned that you could call portlet services using bean locator:

DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("chameleon-portlet", "com.xxxx.chameleon.service.DummyLocalServiceUtil");

DummyLocalServiceUtil.addDummy();
thumbnail
Mohammad Azharuddin, modificado hace 7 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
Amos Fong:
Hey Mohammed,

Since making this post, I've learned that you could call portlet services using bean locator:

DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("chameleon-portlet", "com.xxxx.chameleon.service.DummyLocalServiceUtil");

DummyLocalServiceUtil.addDummy();


Hi Amos Fong

Thanks for you response . I am getting bean locator not set for servlet context exception . Is that what you have suggested works for OSGI modules as well ..?

Thanks
Azhar
thumbnail
Mohammad Azharuddin, modificado hace 7 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
Also i am able to run below code in my portlet(module) but if i run the same code in groovy i am getting class not found exception

ClassResolverUtil.resolveByPortletClassLoader("com.xxxx.chameleon.service.EntityLocalServiceUtil", "my-services")

Where my service builder module structure is as follows

my-services->my-services-api
>my-services-service


When i try the below suggested method i am getting bean locator exception --> com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator is not set for servlet context my-services. The below code doesn't even work in the portlet

DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services", "com.xxxx.chameleon.service.EntityLocalServiceUtil");


DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-api", "com.xxxx.chameleon.service.EntityLocalServiceUtil");


DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-service", "com.xxxx.chameleon.service.EntityLocalServiceUtil");

Please help
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
Any suggestion in how this can be achieved? I tryed the both solutions you guys suggested but none I could succeed emoticon Thanks in advance
thumbnail
Amos Fong, modificado hace 4 años.

RE: How to access portal specific -LocalServiceUtil methods in groovy scri

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
If using 7.0 and later, you should be able to do this for osgi services:
import com.liferay.registry.RegistryUtil
import java.util.Collections;

def registry = RegistryUtil.getRegistry()
def bundleContext = registry._bundleContext
serviceReference = bundleContext.getServiceReference("com.liferay.custom.service.DummyLocalService");
service = bundleContext.getService(serviceReference);
service.dummyMethod();