Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Brian Russell
Servlet Filter via Hook in 6.0.6?
February 21, 2012 2:35 PM
Answer

Brian Russell

Rank: Junior Member

Posts: 40

Join Date: October 31, 2011

Recent Posts

I have read that the ability to create a custom servlet filter is available via hooks in version 6.1, however, I also see that the DTD for the liferay-hook.xml file (http://www.liferay.com/dtd/liferay-hook_6_0_0.dtd) contains the elements for servlet-filter & servlet-filter-mapping. Has anyone had success in creating a custom servlet filter using a hook plugin (rather than via ext plugin) in version 6.0.x?

I'm currently running on v. 6.0.6 of the Community Edition.

My liferay-hook.xml looks like this:
 1<?xml version="1.0"?>
 2<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.0.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_0_0.dtd">
 3
 4<hook>
 5    <portal-properties>portal.properties</portal-properties>
 6    <servlet-filter>
 7        <servlet-filter-name>CW SSO CAS Filter</servlet-filter-name>
 8        <servlet-filter-impl>com.my.custom.sso.cas.CWCASFilter</servlet-filter-impl>
 9    </servlet-filter>
10    <servlet-filter-mapping>
11        <servlet-filter-name>CW SSO CAS Filter</servlet-filter-name>
12        <after-filter>Session Id Filter</after-filter>
13        <url-pattern>/c/portal/login</url-pattern>
14        <url-pattern>/c/portal/logout</url-pattern>
15        <dispatcher>REQUEST</dispatcher>
16        <dispatcher>FORWARD</dispatcher>
17    </servlet-filter-mapping>
18</hook>


And the error I'm receiving when trying to deploy the hook is:
 122:19:42,955 INFO  [HookHotDeployListener:394] Registering hook for cwcassso-hook
 222:19:42,958 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for cwcassso-hook
 3com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for cwcassso-hook
 4    at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:45)
 5    at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:221)
 6    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
 7    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
 8    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
 9    at com.liferay.portal.kernel.servlet.HookContextListener.contextInitialized(HookContextListener.java:36)
10    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
11    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
12    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
13    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
14    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
15    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
16    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
17    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
18    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345)
19    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
20    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
21    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
22    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
23    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
24    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
25    at java.lang.Thread.run(Thread.java:680)
26Caused by: com.liferay.portal.kernel.xml.DocumentException: Error on line 6 of document  : Element type "servlet-filter" must be declared. Nested exception: Element type "servlet-filter" must be declared.
27    at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:372)
28    at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:383)
29    at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:145)
30    at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:403)
31    at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:218)
32    ... 20 more
33Caused by: org.dom4j.DocumentException: Error on line 6 of document  : Element type "servlet-filter" must be declared. Nested exception: Element type "servlet-filter" must be declared.
34    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
35    at org.dom4j.io.SAXReader.read(SAXReader.java:365)
36    at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:369)
37    ... 24 more


Seems pretty obvious to me that even though the DTD declares the elements for filters, it is not working yet in 6.0.6, but just wanted to confirm that and find out if anybody else has had success? I'd really like to accomplish this via a hook rather than ext, and I can't yet upgrade to 6.1

Thank you!
Brian Russell
RE: Servlet Filter via Hook in 6.0.6?
February 21, 2012 2:45 PM
Answer

Brian Russell

Rank: Junior Member

Posts: 40

Join Date: October 31, 2011

Recent Posts

Well, I just took a look at the DTD that is actually bundled with my version and it does not contain the servlet-filter or servlet-filter-mapping elements despite what I thought! That explains it!
 1<!--
 2This is the DTD for the Hook parameters for Liferay Portal.
 3
 4<!DOCTYPE hook PUBLIC
 5    "-//Liferay//DTD Hook 6.0.0//EN"
 6    "http://www.liferay.com/dtd/liferay-hook_6_0_0.dtd">
 7-->
 8
 9<!ELEMENT hook (portal-properties?, language-properties*, custom-jsp-dir?,
10service*)>
11
12<!ELEMENT portal-properties (#PCDATA)>
13
14<!ELEMENT language-properties (#PCDATA)>
15
16<!ELEMENT custom-jsp-dir (#PCDATA)>
17
18<!ELEMENT service (service-type, service-impl)>
19
20<!ELEMENT service-type (#PCDATA)>
21
22<!ELEMENT service-impl (#PCDATA)>


Wondering if I just update the DTD if it'll work?
Hitoshi Ozawa
RE: Servlet Filter via Hook in 6.0.6?
February 21, 2012 3:11 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

As you've stated in your first post, it seems like it's supported from 6.1.0.

http://www.liferay.com/ja/community/forums/-/message_boards/message/8878943
Brian Russell
RE: Servlet Filter via Hook in 6.0.6?
February 21, 2012 3:06 PM
Answer

Brian Russell

Rank: Junior Member

Posts: 40

Join Date: October 31, 2011

Recent Posts

Ya, that's what I was thinking too, but this message board post gave me some hope that it was available in 6.0:

http://www.liferay.com/community/forums/-/message_boards/view_message/12495269#_19_message_12495269

But his response seems to refer to the Enterprise Edition, so I'm not sure.
David H Nebinger
RE: Servlet Filter via Hook in 6.0.6?
February 21, 2012 5:48 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7157

Join Date: September 1, 2006

Recent Posts

I think you can use Jelmer's suggestion about deploying via the EXT plugin in 6.0.6 CE...
Mika Koivisto
RE: Servlet Filter via Hook in 6.0.6?
February 22, 2012 3:12 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

This feature is available starting from 6.1 CE and 6.0 EE SP2.
David H Nebinger
RE: Servlet Filter via Hook in 6.0.6?
February 22, 2012 4:03 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7157

Join Date: September 1, 2006

Recent Posts

Right, but won't the EXT plugin option work even under 6.0.6? That's one of the things the EXT plugin is good for...
Mika Koivisto
RE: Servlet Filter via Hook in 6.0.6?
February 22, 2012 4:14 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

Yes, you can still use the Ext way in 6.0.6.
Brian Russell
RE: Servlet Filter via Hook in 6.0.6?
February 23, 2012 6:12 AM
Answer

Brian Russell

Rank: Junior Member

Posts: 40

Join Date: October 31, 2011

Recent Posts

Thanks guys! Just wanted to verify that I still had to go the EXT route, which I did, and everything is working fine. Once we eventually upgrade to 6.1, I'll change it over to a hook.
Kris k Krishna
RE: Servlet Filter via Hook in 6.0.6?
June 27, 2013 10:49 AM
Answer

Kris k Krishna

Rank: New Member

Posts: 2

Join Date: August 3, 2006

Recent Posts

Brian, How did you implement this using EXT. I am running into same issue of : Element type "struts-action" must be declared.