Foren

How can I use a service in SDK and 5.1.2? (Null Beanlocator)

thumbnail
Pierpaolo Cira, geändert vor 13 Jahren.

How can I use a service in SDK and 5.1.2? (Null Beanlocator)

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
Hi all,

I'm writing an hook and I need to use some classes provided by another portlet service.

For example I have a customPortlet (in SDK) containing a customPortlet-service.jar (made by "ant build service").
If I put the jar in my hook lib folder, then I'm able to compile, deploy and run the hook... but when the hook tries to access to the service, it throws a NullPointerException.

I think that the service is not properly initialized.

Any idea or suggestion will be very appreciated.

Thank you
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
It's a bug. Classloader proxies are currently broken in liferay 6.0.5

See: http://www.liferay.com/community/forums/-/message_boards/message/5968217

relevant jira issues are LPS-12372 LPS-12791 and LPS-12792

attached you will find a patch that can be applied against the liferay 6.0.5 classes to restore the functionality. This means you will have to build liferay from source
thumbnail
Pierpaolo Cira, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
Thank you for you reply... but.. I forgot to write that I'm using Liferay Portal 5.1.2.
I'm searching on the web for similar issue... but without any result.

Do you think the bug you wrote exists since 5.x version... or can I have another problem?


EDIT:
I worked in the same way of http://www.liferay.com/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
But in the second comment Jakub Liska wrote:
sharing services then calls from "localContext A" to "otherContext B" EntityLocalServiceUtil.methods() are realized on freshly loaded class loaded by "localContext A" classloader without _service field initialized by spring.
Therefor if (_service == null) is true.


Any idea?

Thanks again
thumbnail
Pierpaolo Cira, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
Another indication, supponing my bean is named "My".

Using MyServiceUtil.getService() I receive:
19:38:46,827 ERROR [PortletBeanLocatorUtil:52] BeanLocator is null
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set

Using MyUtil.getPersistence() I get a null object.

Please, can you help me?
Any suggestion or consideration will be very appreciated.
thumbnail
Iván Bautista Bautista, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 166 Beitrittsdatum: 25.01.10 Neueste Beiträge
Hi Pierpaolo,

Do you try using MyLocalServiceUtil?? Maybe this will works.
thumbnail
Peter Shin, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 121 Beitrittsdatum: 24.09.07 Neueste Beiträge
hi pierpaolo, try adding this listener to your web.xml

<listener>
	<listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
</listener>
thumbnail
Pierpaolo Cira, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
Hi Ivàn and Peter... thank you for your reply... but I tried both your solutions, but without success.

However I think that I find the solution.
If a portlet (x) needs to use the service layer defined by another portlet (y), and the y-service.jar is in the Tomcat lib/ext folder, then in the portlet x, I need to copy the service.properties and the files it requires (under src/META-INF) from the portlet y.

Then I followed your suggestion.

I hope it isn't conceptually wrong.

Now I'm going to test it in a hook.

Thanks again.

Pierpaolo
thumbnail
Iván Rodríguez Bautista, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 166 Beitrittsdatum: 25.01.10 Neueste Beiträge
In theory, you just have to access to service throught the jars thats the portlet "y" generates. Is strange that this doesn,t work....

Did you try to add the project of portlet "y" to "x" java build path (the second option in project->properties->java build path?? With ext and the rest of the portlets works, maybe this will helps you.
thumbnail
Pierpaolo Cira, geändert vor 13 Jahren.

RE: How can I use a service in SDK?

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
Thnks again for you answer.

Iván Rodríguez Bautista:
In theory, you just have to access to service throught the jars thats the portlet "y" generates. Is strange that this doesn,t work....

emoticon

Iván Rodríguez Bautista:

Did you try to add the project of portlet "y" to "x" java build path (the second option in project->properties->java build path?? With ext and the rest of the portlets works, maybe this will helps you.

This solution doesn't work... emoticon
Infact "Java build path" is only for compile purpose, and not regards deployment.

PS: I'm working in Plugin mode and not ext.

Thanks again

Other idea about the solution I found?