Message Boards

How to implement 6.2 portal properties hook in Liferay 7?

thumbnail
Gaurav Jain, modified 6 Years ago.

How to implement 6.2 portal properties hook in Liferay 7?

Junior Member Posts: 85 Join Date: 7/12/16 Recent Posts
Hello everyone,
In liferay 6.2 there used to be a property, hot.deploy.listeners, which could be overridden using portal properties hook.
In liferay 7, I am not able to find any way, to include my custom class in existing list of classes under this property.

I tried overriding this property in portal-ext file, but for my custom class, it throws ClassNotFoundException, which is expected.

I also tried by putting this property in a portal.properties file with my custom class as value, inside a module, as following:
hot.deploy.listeners=com.example.portlet.DeployListener


Tried keeping portal.properties file in following locations:

lr7-wrkspc\modules\practice.module\src\portal.properties
lr7-wrkspc\modules\practice.module\src\main\resources\portal.properties

But my custom class was not executed.

Checked the module using lb in gogo shell , it is in active state.

Please help.

Regards,
Gaurav
thumbnail
David H Nebinger, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Gaurav Jain:
But my custom class was not executed.

Checked the module using lb in gogo shell , it is in active state.


It doesn't matter if it is active state or not, it's a matter of class loader.

The properties you're hitting are used in portal scope to invoke the classes, and anything in OSGi is not going to be at portal scope so you end up with CNFEs.

The only solution will be the EXT plugin once it is added back in GA4.









Come meet me at the 2017 LSNA!
thumbnail
Gaurav Jain, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Junior Member Posts: 85 Join Date: 7/12/16 Recent Posts
Hi David,

Thanks for your suggestion.
thumbnail
Andrew Jardine, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Question David, though this is probably not the CORRECT way to do it, as a work around (given the absence of the EXT plugins for the moment), could you not place the class into a global space that is accessible by all class loaders in the container? Similar to putting something in TOMCAT_HOME/lib/ext?
thumbnail
David H Nebinger, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Of course you can do that, but you'll never get Liferay to approve such a thing, and any real SCM will probably push back on it also.

Global class loader is the same sort of hack as a global variable - they both suffer from severe code smell. Sometimes they're necessary, but often times they are best avoided.

Putting into the global class loader, you always have to worry about dependencies; any dependencies you introduce must also be resolvable in the global class loader. Once you put a class in the global class loader, that often overrides what you have in the local class loader so sometimes you will have version issues to worry about. Sometimes when you make the dependency global, it has all kinds of transitive dependencies that must also be global, so you get into all kinds of trouble there, too.

For such a simple case as this, perhaps this is not an issue. From the SCM perspective, though, deploying something to global space is frowned upon. SCM would mandate that a global change requires a complete global test to ensure that the change is fully tested and approved before it can be promoted.

Finally, there's just the maintenance issues which can also work against you. A global class like this has no deployment support. On windows, you can't update globals while the app server is running, so the app server must be shut down to deploy an update because tomcat has the files locked and the OS won't allow the overwrite. On non windows, you may be able to overwrite while the app server is running but many will still use the old, loaded version until they are restarted.

Then you get folks who deploy both globally and a different version locally, and they wonder why they get results different than expected because they lose sight of the fact that they have some global class/jar which trumps whatever local code they're trying to use. This is the kind of scenario that drives everyone nuts (client gives war/jar to liferay to test, works fine there and close ticket, client mad at "works for me" response), mostly because the global guys have unexpected impacts to deployed apps.

Once the EXT is back, that would be the way to push something like this, but imagine the frustration trying to figure out what is going on if the class was previously manually put into the lib/ext directory and EXT doesn't take hold because some sort of class loading order issue? Who wants to take the time to diagnose that kind of nightmare and resolve it?

So yes, while it is possible to push like this, we will never tell you as much because it just comes with so much baggage.







Come meet me at the 2017 LSNA!
thumbnail
Andrew Jardine, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Fair enough -- and all points I would more than agree with. I guess at the end of the day --

HURRY UP AND RELEASE GA4!

emoticon
thumbnail
David H Nebinger, modified 6 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Well, I would prefer you had responded with:

HURRY UP AND RELEASE A SOLID, STABLE GA4!

Otherwise you might get a slightly repackaged GA3, and I don't think that would help anyone emoticon







Come meet me at the 2017 LSNA!
Nora Kobrossy, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

New Member Posts: 7 Join Date: 1/29/20 Recent Posts
Hi, do we still have this limitation in the latest version 7.2.0 GA2 ? 
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Nora,

When you say "do we have this" ... Do you mean the ability to alter a property using a plugin instead of the portal-ext?
Nora Kobrossy, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

New Member Posts: 7 Join Date: 1/29/20 Recent Posts
Hi Andrew,I wanted to know if we can create a hot deploy listener as osgi bundle instead of implementing it as a EXT plugins ?My class has dependencies on other osgi bundles that won t be accessible if the listener is deployed as EXT plugin.
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Nora,

Well, looking at the class 
[code]public class HookHotDeployListener
   extends BaseHotDeployListener implements PropsKeys {

It looks like the property is still in the list. So you should be able to use the OSGI approach by creating a service where the component annotation to manipulate the property. Something like this -- though I am not sure which value you would use for the service in this case.

@Component(
   enabled = false, immediate = true, property = "key=login.events.post",
   service = LifecycleAction.class
)


I am guessing that you want to do this because you are still writing plugins that are using the old WAR style in terms of structure/type. Is that correct?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Nora Kobrossy:

Hi Andrew,I wanted to know if we can create a hot deploy listener as osgi bundle instead of implementing it as a EXT plugins ?My class has dependencies on other osgi bundles that won t be accessible if the listener is deployed as EXT plugin.
Back in 6.x, a HotDeployListener was one possible solution to choose for solving an underlying business problem.
Instead of asking if you can still use the same technique as 4 years ago for solving an unnamed problem, I'd prefer to hear about the underlying problem and try to solve a solution. That would be part of a different thread though.
The architecture has changed dramatically - don't try to port old solutions 1:1
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
haha -- it took everything in me not t just reply "you shouldn't need this property anymore -- you should build your plugins using the new OSGI model." emoticon
Nora Kobrossy, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

New Member Posts: 7 Join Date: 1/29/20 Recent Posts
In fact, we want to add a listener on the deploy event and not on the login events. If the listener has dependencies to osgi modules and i deploy it under EXT, it won t be able to load the bundles. So basically any liferay hook should be equally deployed as osgi bundle, otherwise we ll have ClassNotFound Exceptions. 
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Nora,

Right, I did understand that you were looking to alter a different property, I just provided that component annotation as an example of "how to do it in Liferay 7+" now that the hook plugins are no longer around.

With that said, I'm not sure that I am understanding your requirement. This property, I believe, would only affect deployments that go through the deploy folder -- which means WAR plugins (which of course would then pass through the WAB generator to become OSGI services modules and such). But in your comments you are referencing OSGI modules as well -- so I am not sure I understand what it is you are doing exactly.

Could you share with us a bigger picture of what you are trying to achieve? Maybe a little context will help us help you.
thumbnail
David H Nebinger, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
There are numerous opportunities to track events such as bundle loading and unloading, all things that are OSGi-backed.

But to echo my compatriots, what do you need to do during these kinds of deployment activities?


Not to say that we doubt why you might want to do this, because there are plenty of good use cases such as Liferay's own spring extender module which looks for spring configs in new bundles or the I18N support which is checking for resource bundles to link in.


It's more along the lines of trying to figure out if there is a better way to solve a requirement than to wire into the bundle activation layers...
Nora Kobrossy, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

New Member Posts: 7 Join Date: 1/29/20 Recent Posts
Hi, thank you for your quick replies. 
What we're trying to achieve is this : 
we have WARs that will be deployed in Liferay 7 , so they will go through the WAB process, 
on deploy we want to have a listener in order to duplicate portlets preferences across pages ( it s a configuration issue)
can we develop the listener as OSGI bundle ? 
we definitely don't want to have a listener under ROOT/WEB-INF/LIB because it has dependencies on other osgi bundles.
Thank you !
thumbnail
David H Nebinger, modified 4 Years ago.

RE: How to implement 6.2 portal properties hook in Liferay 7?

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
For this, I'd be using an UpgradeProcess in the WAR itself. When it deploys, the UP executes to get to the next version level, you put the prefs duplication in there and it will just work. Each new WAR version would have a new incremental version number and registered Upgrade Process to take care of the replication.

This way it is not an external piece figuring out something new is there to push prefs from, now it would be up to the WAR itself to push pref updates as a result of the WAR being deployed.