Message Boards

Servlet filter is not getting invoked in 7.2

thumbnail
sricanth arroju, modified 3 Years ago.

Servlet filter is not getting invoked in 7.2

Regular Member Posts: 133 Join Date: 10/3/09 Recent Posts
Hi 
Servlet filter not getting invoked if the url-param is a shorter
example@Component(
        immediate = true,
        property = {
                "servlet-context-name=",
                "servlet-filter-name=sample",
                "url-pattern=/documents/*"
        },
        service = Filter.class
)
if i'm using the siteurl as the url-param like "url-pattern=/group/abc/home", The filter is getting invokedi have tried the solution provided in https://lifedev-solutions.blogspot.com/2019/11/servlet-filter-in-liferay-72.html

​​​​​​​Thanks,Srikanth
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Servlet filter is not getting invoked in 7.2

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Srikanth Arroju:

Hi 
Servlet filter not getting invoked if the url-param is a shorter
example@Component(
        immediate = true,
        property = {
                "servlet-context-name=",
                "servlet-filter-name=sample",
                "url-pattern=/documents/*"
        },
        service = Filter.class
)
if i'm using the siteurl as the url-param like "url-pattern=/group/abc/home", The filter is getting invokedi have tried the solution provided in https://lifedev-solutions.blogspot.com/2019/11/servlet-filter-in-liferay-72.html
I don't really get what's working and what not. But this sample worked for me - doesn't look like it's significantly different. Note the different comments in the class you find in the sample to give you a hint what you need to take care for (e.g. unique name) and where to find what you can specify as before-filter. You don't specify anything, so I'm not sure what it defaults to: For some filters I've needed to pick the right position in the chain to make a difference - they're all rewriting some of the context.
thumbnail
sricanth arroju, modified 3 Years ago.

RE: Servlet filter is not getting invoked in 7.2

Regular Member Posts: 133 Join Date: 10/3/09 Recent Posts
Hi Olaf,

Thank you for your response. What we are trying to acheive is triggering a custom filter when a keyword is present in the URL, just like what you provided in your sample "/change/me". Unfortunately it is not working for us. When we give the url-pattern like "/group/<<siteName>>/home" or "/*" then the custom filter is getting called. It is not working for our keyword like "/ab/". We tried the sample which you provided and it is also not getting called when we hit the url   "http://localhost:8080/change/me".We have enabled the log level for the package "com.liferay.portal.kernel.servlet" and in the log it shows the url pattern is matched in FilterMapping class and still it is not executing the code in doFilter / processFilter method.
DEBUG [http-nio-8080-exec-2][FilterMapping:118] class com.abcd.filter.TestFilter has a pattern match with /ab/123
DEBUG [http-nio-8080-exec-2][FilterMapping:168] class com.abcd.filter.TestFilter has a regex match with /ab/123

the pattern is matching but the filter is not getting called in Invokerfilter.java Please let us know if you need any further details.

Env. DXP 7.2 Fixpack 5

Thanks,
Srikanth
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Servlet filter is not getting invoked in 7.2

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
so, did you try different values for before-filter?
thumbnail
sricanth arroju, modified 3 Years ago.

RE: Servlet filter is not getting invoked in 7.2

Regular Member Posts: 133 Join Date: 10/3/09 Recent Posts
Thanks  Olaf,

The filter is getting called when we use  "before-filter=Absolute Redirects Filter"