Forums de discussion

Hook servlet.service.events.pre

e boats, modifié il y a 7 années.

Hook servlet.service.events.pre

New Member Publications: 18 Date d'inscription: 13/05/16 Publications récentes
Hello,

We have a velocity-related Hook created for our liferay portlet application. In the portal.properties, I see we have a servlet.service.events.pre whose value is set to a couple of custom classes that extend com.liferay.portal.kernel.events.Action

The overridden run() method on these classes are getting called 20-30 times per page load. Each page of course has a few portlets on the page, but I'm wondering why this run() is getting fired so many times.

Are classes referenced by servlet.service.events.pre supposed to be fired once per portlet request, or how does this work? I'm trying to figure out what might be causing these run() methods to be fired so much.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
They will be called for every portal request including those for static assets (css & js), images, etc.
e boats, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

New Member Publications: 18 Date d'inscription: 13/05/16 Publications récentes
Thanks, our run() method is setting a map of variables to be used by Velocity, like :

request.setAttribute(WebKeys.VM_VARIABLES, velocityVariables);

Is there some other event or filter I could use instead of "servlet.service.events.pre" that would maybe just fire once per page load or portlet request, rather than each time a js, css, html is requested? I'd like to minimize calls to run() but still have the variable map available for Velocity.

These Velocity variables are just being used by our Theme, so it seems like we don't need to keep setting them over and over.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
You only want these settings to be very lightweight because they are invoked every time.
e boats, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

New Member Publications: 18 Date d'inscription: 13/05/16 Publications récentes
One more question about a class configured with servlet.service.events.pre. When our class gets called, we are setting a request attribute, but when the class gets called again (it is firing multiple times per page load), the request attribute is gone. So, is it a unique httpservletrequest every time the class gets fired per page load? We are using PortalUtil.getOriginalServletRequest(request) to get the original httpservlet request but can't find the request attribute there. I'm wondering if a request attribute can be preserved across multiple firings of this class.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Yes they are separate requests.

The browser is calling back for this resource or that resource, etc. That's the source of the multiple calls. Since they are different requests, the attributes will not be retained.
thumbnail
Nithin KV, modifié il y a 7 années.

RE: Hook servlet.service.events.pre

Junior Member Publications: 56 Date d'inscription: 23/07/12 Publications récentes
Hi Regarding the same issue,

I see the code written in ServicePostAction like below. Now, How do i make sure that my servlet.service.events.post hook is getting called only once per full request ? I am able to see many hits when i access the portal with this hook. can you pls explain me in detail about how to manage these multiple hits ?

// Make sure this is called only once per full request, ignore
// requests spawned by the portlet

//String requestURI = GetterUtil.getString(request.getRequestURI());

// Doesn't this cause a memory leak?

/*if (requestURI.endsWith("/portal/render_portlet")) {
return;
}*/