Forums de discussion

Using Class Loader Proxy classes to share plugins services (error)

Rick Dangerous, modifié il y a 13 années.

Using Class Loader Proxy classes to share plugins services (error)

Junior Member Publications: 61 Date d'inscription: 25/01/11 Publications récentes
I'm using this way => wiki to share service classes between 2 portlets

Portlet 1 has the service classes. I have got Portlet1-service.jar, and put inside the Portlet2, at /docroot/WEB-INF/lib.

At Portlet 2, only has (for test reasons) one view.jsp that the next call:
List<test> testList = testLocalServiceUtil.findAllInGroup(groupId);

This call to the service works perfectly at Portlet1. At Portlet2, when I show the portlet, there is an error...


Caused by: java.lang.NullPointerException
	at com.myportlet.portal.rickdangerous.service.testLocalServiceClp.<init>(testLocalServiceClp.java:663)
	at com.myportlet.portal.rickdangerous.service.testLocalServiceUtil.getService(testLocalServiceUtil.java:298)
	at com.myportlet.portal.rickdangerous.service.testLocalServiceUtil.findAllInGroup(testLocalServiceUtil.java:242)
	at org.apache.jsp.view_jsp._jspService(view_jsp.java:167)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
</init>


I try to debut this, but eclipse not show correctly the service classes (because it's a jar, not source). I attach the sources's Portlet1 project butt that now shows correctly the debug.

If I see manually the last line where is throwed NullException at testLocalServiceUtil:
public static rutasLocalService getService() {
		if (_service == null) {
			Object obj = PortletBeanLocatorUtil.locate(ClpSerializer.SERVLET_CONTEXT_NAME,
					rutasLocalService.class.getName());
			ClassLoader portletClassLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.SERVLET_CONTEXT_NAME,
					"portletClassLoader");

			ClassLoaderProxy classLoaderProxy = new ClassLoaderProxy(obj,
					portletClassLoader);

			[b]_service = new rutasLocalServiceClp(classLoaderProxy);[/b]

			ClpSerializer.setClassLoader(portletClassLoader);
		}

		return _service;
	}

The exception is throwed at :
_service = new rutasLocalServiceClp(classLoaderProxy);

What's wrong?
thumbnail
Raja Nagendra Kumar, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Expert Publications: 484 Date d'inscription: 02/03/06 Publications récentes
This may be a class loader issue.

Try to put the common classes which needs to be used by both portlet1 and portlet2 in global context and see if the service works fine in portlet1 context first. if yes, it should work in portlet2 context two.

Keeping the jar in lib folder of portlet2 would mean class loader of portlet2 would be different than the on used by portlet1.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
-Liferay Excellence
Rick Dangerous, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Junior Member Publications: 61 Date d'inscription: 25/01/11 Publications récentes
Raja Nagendra Kumar:
This may be a class loader issue.

Try to put the common classes which needs to be used by both portlet1 and portlet2 in global context and see if the service works fine in portlet1 context first. if yes, it should work in portlet2 context two.

Keeping the jar in lib folder of portlet2 would mean class loader of portlet2 would be different than the on used by portlet1.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
-Liferay Excellence


I put service jar file at tomcat /lib/ext dir, and deleted from portlet1 and portlet2. portlet1 works fine, portlet2... the same error.
thumbnail
Raja Nagendra Kumar, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Expert Publications: 484 Date d'inscription: 02/03/06 Publications récentes
For checking purpose, can you put your portlet2 test code in portlet 1 and see if it works. As you have resolved the class loader issues, the Nullpointer must be some thing to do with initialization of the portlet or configuration.
Rick Dangerous, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Junior Member Publications: 61 Date d'inscription: 25/01/11 Publications récentes
Raja Nagendra Kumar:
For checking purpose, can you put your portlet2 test code in portlet 1 and see if it works. As you have resolved the class loader issues, the Nullpointer must be some thing to do with initialization of the portlet or configuration.


I already did it. The portlet2's code works fine inside the portlet1's project, without any NullPointer.
thumbnail
Raja Nagendra Kumar, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Expert Publications: 484 Date d'inscription: 02/03/06 Publications récentes
O.K, Then this seem to be some configuration issues can you check portal.xml and liferay-poortal.xml file differences. Or try to put portal1 entire code (with the test code) in portlet 2.

Better approach is through remote debugging of portlet2 with break points to know the cause.

http://www.liferay.com/community/wiki/-/wiki/Main/Eclipse

Regards,
Nagendra
thumbnail
Ray Augé, modifié il y a 13 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Liferay Legend Publications: 1197 Date d'inscription: 08/02/05 Publications récentes
Ok, so please don't shoot the messenger!

Quite unfortunately, there is a bug in Service Builder's generation of Plugin's Classloader proxy classes.

The resolution of this bug is already applied to 6.0EE and trunk, was accidentally omitted from 6.0.6, but can be found here:

LPS-12372 Fix initializing order and ProxyClassLoader creation
thumbnail
sasi kala, modifié il y a 12 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

New Member Publications: 18 Date d'inscription: 15/11/10 Publications récentes
Hiii Ray....

I created one Entity Service in one Portelt1.I wanted to use the same service in another Portlet2. I have copied the service jar in portlet2 as well as src...It is giving me NullPointerException...As u said there is a bug in 6.0.6 version....Is there any solution to overcome this....
thumbnail
sasi kala, modifié il y a 12 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

New Member Publications: 18 Date d'inscription: 15/11/10 Publications récentes
I got the solution for the above problem....

1: After build-service in portlet1 , copy the generated service jar file from /portlet1/docroot/WEB-INF/lib/
to /tomcat-6.0.29/lib/ext/ (if we will not copy this jar at context level, we would get NullpointerException )and remove the jar from /portlet1/docroot/WEB-INF/lib/ (if we would not remove the jar from here we will get ClassCastException)
2:Undeploy the two portlets if we already deployed...and restart the server (if we would not clear all caches of tomcat we will get BeanLocatorException)
3.deploy portlet1 and portlet2...
thumbnail
Mathieu Hicauber, modifié il y a 12 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Junior Member Publications: 79 Date d'inscription: 22/12/10 Publications récentes
Hi,

With the method above, I'm getting a noSuchMethodExxception when trying to access the service. To be clear, when using a method having primitive types as parameters, or jmv class, no problem, teh problem occurs when I use methods having classes defined in the service jar as parameters. That definitely looks like a classloader issue, however I made sur that the service jar is only deployed in the lib/ext directory of tomcat...

Any clue ?

Thank you,

Mathieu.
thumbnail
Luyen Tien Dinh, modifié il y a 11 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

New Member Publications: 3 Date d'inscription: 08/06/12 Publications récentes
2 solutions:
+ http://issues.liferay.com/browse/LPS-12372?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs
(just pack new portal-impl.jar, build your service again, put in global [tomcat]\lib\ext, make sure you already deleted ur service jar file in portlet level.)
+ http://www.liferay.com/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
Javier Vera, modifié il y a 9 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

New Member Publications: 18 Date d'inscription: 01/08/14 Publications récentes
hi, could you please provide a cleaner way to achieve this method sharing?
thumbnail
David H Nebinger, modifié il y a 9 années.

RE: Using Class Loader Proxy classes to share plugins services (error)

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Javier Vera:
hi, could you please provide a cleaner way to achieve this method sharing?


Sure, it's called Service Builder. Even though Service Builder's main focus is on database services, you can actually use a "fake entity" to implement shared business services, front external web service calls, etc. There's a whole thread on it covered here.