Foros de discusión

How to make Inter Portlet Communication (IPC) with own class in Liferay 7

Antonio Javier Ortega Pérez, modificado hace 6 años.

How to make Inter Portlet Communication (IPC) with own class in Liferay 7

New Member Mensajes: 22 Fecha de incorporación: 20/04/11 Mensajes recientes
How to make Inter Portlet Communication (IPC) work with own class in Liferay 7

Hi community! I followed some forum threads like this:

https://web.liferay.com/es/community/forums/-/message_boards/message/79742622

and now I can made Inter Portlet Communication (IPC) between portlets using ‘trivial’ data as payload (classes that belong to java.lang package like String or HashMap).

Now I wanted to use my own class as event data but when I launch the event in the action phase it happens a ClassNotFoundException inside Liferay:

Daemon Thread [http-nio-8081-exec-3] (Suspended (exception ClassNotFoundException))	
	owns: WebappClassLoader  (id=35311)	
	owns: Object  (id=35312)	
	owns: NioChannel  (id=35278)	
	WebappClassLoader(WebappClassLoaderBase).findClass(String) line: 861	
	WebappClassLoader(WebappClassLoaderBase).loadClass(String, boolean) line: 1277	
	URLClassLoader(ClassLoader).loadClass(String, boolean) line: 411	
	URLClassLoader(ClassLoader).loadClass(String) line: 357	
	PortletContainerImpl.serializeEvent(Event, ClassLoader) line: 237	
	PortletContainerImpl._processEvent(HttpServletRequest, HttpServletResponse, Portlet, Layout, Event) line: 516	
	PortletContainerImpl.processEvent(HttpServletRequest, HttpServletResponse, Portlet, Layout, Event) line: 132	
	SecurityPortletContainerWrapper.processEvent(HttpServletRequest, HttpServletResponse, Portlet, Layout, Event) line: 113	
	RestrictPortletContainerWrapper.processEvent(HttpServletRequest, HttpServletResponse, Portlet, Layout, Event) line: 92	
	PortletContainerUtil.processEvent(HttpServletRequest, HttpServletResponse, Portlet, Layout, Event) line: 142	
	PortletContainerUtil._processEvents(HttpServletRequest, HttpServletResponse, List<event>) line: 287	
	PortletContainerUtil.processAction(HttpServletRequest, HttpServletResponse, Portlet) line: 120	</event>


My test example is very simple:
  • One portlet (‘portlet1’) that fires the event.
  • One portlet (‘portlet2’) that receives the event.
  • The event data is of class com.sample.EventData wich has two Strings.
  • All three elements are in the same module (portlets 1 and 2, and EventData).


Y suppose that this is obvious because Liferay core doesn’t know anything about my class. I tried to make package com.sample exportable in my Osgi module, but it happens the same (i suppose because this is a runtime dependency, not a compile or deployment dependency).
Given this, how I can make IPC with my own class as data payload?

Thanks in advance.
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
The best part of that other thread is the part where they talk about using client side IPC. Like David said (on the other thread) , server side IPC has had it's day and isn't really a great idea for building rich user experiences these days. With that said, if you are dead set on doing it then can you please provide the java code for the three classes here so that I can see what you have?
Antonio Javier Ortega Pérez, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

New Member Mensajes: 22 Fecha de incorporación: 20/04/11 Mensajes recientes
Hi Andrew, thanks for the answer. For some scenarios I thing that is better backend events, mainly when the event must update backend data.
Here it is my prove of concept of an IPC portlet with an own class:

https://drive.google.com/file/d/13IC_uxltJZzkEpSNWRJad9RKtbCRwRvF/view?usp=sharing

Thanks in advance.
Antonio Javier Ortega Pérez, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

New Member Mensajes: 22 Fecha de incorporación: 20/04/11 Mensajes recientes
Hello Andrew, is there anything new about this? Could you do the test? It would be useful to know if it really can be done or if it is simply impossible in Liferay 7 / DXP.

Thank you very much.
thumbnail
Olaf Kock, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
Antonio Javier Ortega Pérez:
Hello Andrew, is there anything new about this? Could you do the test? It would be useful to know if it really can be done or if it is simply impossible in Liferay 7 / DXP.


As you're getting a ClassNotFoundException, it probably boils down to your payload class not being available to both portlets. You can either package them in the same bundle, or you can extract (or export) your payload class, to make it accessible to both portlets.

As this adds complexity to the deployment, I always like to just use JRE-types, e.g. Maps of Strings and other built-in types, rather than my own classes. Yes, it's a bit clumsy, but those are the types that are available everywhere, all the time. Plus, I don't like to encode too much business logic in Events anyways, and this neatly decouples sender and receiver.
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Antonio,

I haven't had a chance to try it to be honest, but I just thumbs up what Olaf said. Good advice. Making a bean just for sake of having a bean isn't something I generally do either.

I still maintain that the server side eventing is something the should be avoided -- it doesn't really created a great (or modern) user experience. If nothing else, it will slow the application by reloading portlets whose state hasn't changed. I haven't used server side events in almost 4 years now and haven't missed them one bit. It does require a little more finesse with javascript, but in the end I like it more.

Just for the sake of conversation, why do you feel that the server side event is the better option?
Antonio Javier Ortega Pérez, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

New Member Mensajes: 22 Fecha de incorporación: 20/04/11 Mensajes recientes
I think same, I prefer client side IPC for modern UX but server side IPC was a client requirement to reuse a bunch of existing code. Let me explain, the client has a backend tool made in Java wich is like a black box. It uses lots of POJOs in an API JAR (with some levels of nesting) as model, then, the portlets are a front end of this backend system and uses all this POJOs to call the backend, so, if in a page have various portlets that work with these POJO's and want to comunicate them, the client prefers to work allways with this model and not make conversions.

As you're getting a ClassNotFoundException, it probably boils down to your payload class not being available to both portlets


At first glance it would be what Olaf says, but after several tests I did the simplest test, a module with three classes, sender, receiver, and payload, then, it can't be a problem of payload not being available to both portlets.

Best regards.
thumbnail
Fabian Bouché, modificado hace 6 años.

RE: How to make Inter Portlet Communication (IPC) with own class in Liferay

New Member Mensajes: 12 Fecha de incorporación: 8/04/16 Mensajes recientes
Hello!

I came across the same problem without finding a solution (other than switching back to simple type like String or Maps).
In my use case, I had a JSF Portlet and a MVCPortlet.
I was able to send a Serializable object from MVCPortlet to JSF but I came across the ClassNotFoundException the other way around.
As Olaf suggested, I created a dedicated bundle to carry the serializable DTOs and Export-Packaged them.
When looking at the gogo shell, I see both of my portlets do import the package so I suspect there must be something at the portal level handling the event bus throwing that exception:

2018-02-06 10:18:13,028 ERROR [http-nio-8080-exec-3] portal_web.docroot.html.portal.status_jsp Htpas1VdWoN_0117 - java.lang.RuntimeException: java.lang.ClassNotFoundException: com.bnpp.pf.pfux.sample.xmppdto.IncomingCallData


Weird... :'(

Best regards,
Fabian