留言板

Hook servlet.service.events.pre

e boats,修改在7 年前。

Hook servlet.service.events.pre

New Member 帖子: 18 加入日期: 16-5-13 最近的帖子
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,修改在7 年前。

RE: Hook servlet.service.events.pre

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
They will be called for every portal request including those for static assets (css & js), images, etc.
e boats,修改在7 年前。

RE: Hook servlet.service.events.pre

New Member 帖子: 18 加入日期: 16-5-13 最近的帖子
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,修改在7 年前。

RE: Hook servlet.service.events.pre

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
You only want these settings to be very lightweight because they are invoked every time.
e boats,修改在7 年前。

RE: Hook servlet.service.events.pre

New Member 帖子: 18 加入日期: 16-5-13 最近的帖子
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,修改在7 年前。

RE: Hook servlet.service.events.pre

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在7 年前。

RE: Hook servlet.service.events.pre

Junior Member 帖子: 56 加入日期: 12-7-23 最近的帖子
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;
}*/