Fórumok

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

Rick Dangerous, módosítva 13 év-val korábban

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

Junior Member Bejegyzések: 61 Csatlakozás dátuma: 2011.01.25. Legújabb bejegyzések
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, módosítva 13 év-val korábban

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

Expert Bejegyzések: 484 Csatlakozás dátuma: 2006.03.02. Legújabb bejegyzések
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, módosítva 13 év-val korábban

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

Junior Member Bejegyzések: 61 Csatlakozás dátuma: 2011.01.25. Legújabb bejegyzések
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, módosítva 13 év-val korábban

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

Expert Bejegyzések: 484 Csatlakozás dátuma: 2006.03.02. Legújabb bejegyzések
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, módosítva 13 év-val korábban

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

Junior Member Bejegyzések: 61 Csatlakozás dátuma: 2011.01.25. Legújabb bejegyzések
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, módosítva 13 év-val korábban

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

Expert Bejegyzések: 484 Csatlakozás dátuma: 2006.03.02. Legújabb bejegyzések
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é, módosítva 13 év-val korábban

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

Liferay Legend Bejegyzések: 1197 Csatlakozás dátuma: 2005.02.08. Legújabb bejegyzések
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, módosítva 12 év-val korábban

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

New Member Bejegyzések: 18 Csatlakozás dátuma: 2010.11.15. Legújabb bejegyzések
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, módosítva 12 év-val korábban

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

New Member Bejegyzések: 18 Csatlakozás dátuma: 2010.11.15. Legújabb bejegyzések
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, módosítva 12 év-val korábban

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

Junior Member Bejegyzések: 79 Csatlakozás dátuma: 2010.12.22. Legújabb bejegyzések
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, módosítva 11 év-val korábban

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

New Member Bejegyzések: 3 Csatlakozás dátuma: 2012.06.08. Legújabb bejegyzések
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, módosítva 9 év-val korábban

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

New Member Bejegyzések: 18 Csatlakozás dátuma: 2014.08.01. Legújabb bejegyzések
hi, could you please provide a cleaner way to achieve this method sharing?
thumbnail
David H Nebinger, módosítva 9 év-val korábban

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

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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.