Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Srikanth Adepu
Why portlet CSS & JS file requests are not coming to hook servlet filter?
September 15, 2013 12:42 PM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

Hi,

I have written Servlet filter in hook. My requirement is to find the CSS / JS requests in my filter to change the URL pattern before reaching the request to server. However, None of the custom theme and custom portlet CSS / JS request are not coming to my servlet filter. Filter showing only the request which comes for under ROOT/html/.. But when i check my apache web server logs, its clearly showing all kind of requests but not application server.

I have used <before-filter>Absolute Redirects Filter</before-filter> element to load my filter to first at the sequence.

My doFilter menthos in filter class as below

=======================================
String uri = (String) request.getAttribute(WebKeys.INVOKER_FILTER_URI);

HttpServletRequest httpRequest = (HttpServletRequest) request;
logger.info("ORIGINAL REQUEST URI " + httpRequest.getRequestURI());
logger.info("URI " + uri);

// logic to wrap the request
chain.doFilter(wrapped, response);


====================================

My liferay-hook.xml as below

<servlet-filter>
<servlet-filter-name>Sample Filter</servlet-filter-name>
<servlet-filter-impl>com.sample.SampleFilter</servlet-filter-impl>
</servlet-filter>

<servlet-filter-mapping>
<servlet-filter-name>Sample Filter</servlet-filter-name>
<before-filter>Absolute Redirects Filter</before-filter>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</servlet-filter-mapping>


=============================================

All i need to find the my custom portlet and custom theme css and js request inmy filter. Please suggest me what is the best way to do this.

Thanks,
Srikanth
Srikanth Adepu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 16, 2013 10:33 AM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

Can any one give a solution on this?
David H Nebinger
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 16, 2013 12:44 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 5740

Join Date: September 1, 2006

Recent Posts

The path they come from will differ depending upon the origin...

For example, a JS request for a page to a standard theme would go through the Liferay servlet and probably get hit by your filter. However, a custom theme (deployed as a separate war) has a different path, one that goes directly to the theme war and will not be handled by the Liferay servlet.

For header/footer js defined in liferay-portlet.xml, the path is directly within your portlet and therefore will not go through the Liferay servlet. Embedded JS gets injected and that, too, would not go through your servlet.
Mika Koivisto
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 16, 2013 2:41 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1494

Join Date: August 7, 2006

Recent Posts

That will only filter requests coming to the portal context.
Archi Madhu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 16, 2013 9:14 PM
Answer

Archi Madhu

Rank: Regular Member

Posts: 232

Join Date: March 24, 2008

Recent Posts

Hello,

You can write hook to extend ServicePreAction.java class.

In that class, you may check CSS/JS requests using

themeDisplay.getPathThemeCss()

themeDisplay.getPathThemeJavaScript()

and based on customization you can set it also.

HTH!
Archi
Srikanth Adepu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 12:23 AM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

We wanted to know how the liferay resource cache filter interpret all css and js requests? please let us know if it has any short comings

We want our filter to precede the above and intercept, which is not working.
Srikanth Adepu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 2:15 AM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

Archi Madhu:
Hello,

You can write hook to extend ServicePreAction.java class.

In that class, you may check CSS/JS requests using

themeDisplay.getPathThemeCss()

themeDisplay.getPathThemeJavaScript()

and based on customization you can set it also.

HTH!
Archi


Thanks for your reply. I was able to get the CSS and JS paths which are loading from our custom themes by overriding the ServicePreAction.java.

But i need to get the CSS and JS paths which are loading from our custom portlet also. Is there any way for this. And also is it possible to get the CSS / JS paths including file name?

Thanks,
Srikanth
Srikanth Adepu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 10:07 AM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

Mika Koivisto:
That will only filter requests coming to the portal context.


Then what is the solution to filter the each and every request before hitting the server. I just tried with HOOK overriding ServicePreAction.java class. but that was not helpful. Kindly suggest if you have any other way to filter the custom theme and custom portlet CSS and JS requests.
Srikanth Adepu
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 10:11 AM
Answer

Srikanth Adepu

Rank: New Member

Posts: 10

Join Date: October 31, 2012

Recent Posts

David H Nebinger:
The path they come from will differ depending upon the origin...

For example, a JS request for a page to a standard theme would go through the Liferay servlet and probably get hit by your filter. However, a custom theme (deployed as a separate war) has a different path, one that goes directly to the theme war and will not be handled by the Liferay servlet.

For header/footer js defined in liferay-portlet.xml, the path is directly within your portlet and therefore will not go through the Liferay servlet. Embedded JS gets injected and that, too, would not go through your servlet.


So what you suggest now? How can i get all the CSS and JS requests urls.

Kindly suggest if you have any other way to filter the custom theme and custom portlet CSS and JS requests.
David H Nebinger
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 11:12 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 5740

Join Date: September 1, 2006

Recent Posts

I don't know that there is one filter to rule them all. Instead I think you need to have the filter in each war, and they would all intercept the request to their own js separately.
Mika Koivisto
RE: Why portlet CSS & JS file requests are not coming to hook servlet filte
September 17, 2013 12:13 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1494

Join Date: August 7, 2006

Recent Posts

There is no way to filter all requests regardless of their context without going to appplication server level. In tomcat there's thing called Valve and that can process all requests. Another way to do it is like David suggests putting the filter to every single webapp that needs to have it's requests run through that filter.