Foren

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

Rick Dangerous, geändert vor 13 Jahren.

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

Junior Member Beiträge: 61 Beitrittsdatum: 25.01.11 Neueste Beiträge
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, geändert vor 13 Jahren.

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

Expert Beiträge: 484 Beitrittsdatum: 02.03.06 Neueste Beiträge
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, geändert vor 13 Jahren.

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

Junior Member Beiträge: 61 Beitrittsdatum: 25.01.11 Neueste Beiträge
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, geändert vor 13 Jahren.

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

Expert Beiträge: 484 Beitrittsdatum: 02.03.06 Neueste Beiträge
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, geändert vor 13 Jahren.

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

Junior Member Beiträge: 61 Beitrittsdatum: 25.01.11 Neueste Beiträge
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, geändert vor 13 Jahren.

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

Expert Beiträge: 484 Beitrittsdatum: 02.03.06 Neueste Beiträge
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é, geändert vor 13 Jahren.

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

Liferay Legend Beiträge: 1197 Beitrittsdatum: 08.02.05 Neueste Beiträge
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, geändert vor 12 Jahren.

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

New Member Beiträge: 18 Beitrittsdatum: 15.11.10 Neueste Beiträge
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, geändert vor 12 Jahren.

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

New Member Beiträge: 18 Beitrittsdatum: 15.11.10 Neueste Beiträge
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, geändert vor 12 Jahren.

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

Junior Member Beiträge: 79 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 11 Jahren.

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

New Member Beiträge: 3 Beitrittsdatum: 08.06.12 Neueste Beiträge
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, geändert vor 9 Jahren.

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

New Member Beiträge: 18 Beitrittsdatum: 01.08.14 Neueste Beiträge
hi, could you please provide a cleaner way to achieve this method sharing?
thumbnail
David H Nebinger, geändert vor 9 Jahren.

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

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.