Foros de discusión

Servlet Filter via Hook in 6.0.6?

thumbnail
Brian Russell, modificado hace 12 años.

Servlet Filter via Hook in 6.0.6?

Junior Member Mensajes: 41 Fecha de incorporación: 31/10/11 Mensajes recientes
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:
<!--?xml version="1.0"?-->


<hook>
	<portal-properties>portal.properties</portal-properties>
	<servlet-filter>
        <servlet-filter-name>CW SSO CAS Filter</servlet-filter-name>
        <servlet-filter-impl>com.my.custom.sso.cas.CWCASFilter</servlet-filter-impl>
    </servlet-filter>
    <servlet-filter-mapping>
        <servlet-filter-name>CW SSO CAS Filter</servlet-filter-name>
        <after-filter>Session Id Filter</after-filter>
		<url-pattern>/c/portal/login</url-pattern>
		<url-pattern>/c/portal/logout</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
    </servlet-filter-mapping>
</hook>


And the error I'm receiving when trying to deploy the hook is:
22:19:42,955 INFO  [HookHotDeployListener:394] Registering hook for cwcassso-hook
22:19:42,958 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for cwcassso-hook
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for cwcassso-hook
	at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:45)
	at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:221)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
	at com.liferay.portal.kernel.servlet.HookContextListener.contextInitialized(HookContextListener.java:36)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:680)
Caused 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.
	at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:372)
	at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:383)
	at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:145)
	at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:403)
	at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:218)
	... 20 more
Caused 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.
	at org.dom4j.io.SAXReader.read(SAXReader.java:482)
	at org.dom4j.io.SAXReader.read(SAXReader.java:365)
	at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:369)
	... 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!
thumbnail
Brian Russell, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Junior Member Mensajes: 41 Fecha de incorporación: 31/10/11 Mensajes recientes
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!
<!--
This is the DTD for the Hook parameters for Liferay Portal.

<!DOCTYPE hook PUBLIC
	"-//Liferay//DTD Hook 6.0.0//EN"
	"http://www.liferay.com/dtd/liferay-hook_6_0_0.dtd">
-->

<!--ELEMENT hook (portal-properties?, language-properties*, custom-jsp-dir?,
service*)-->

<!--ELEMENT portal-properties (#PCDATA)-->

<!--ELEMENT language-properties (#PCDATA)-->

<!--ELEMENT custom-jsp-dir (#PCDATA)-->

<!--ELEMENT service (service-type, service-impl)-->

<!--ELEMENT service-type (#PCDATA)-->

<!--ELEMENT service-impl (#PCDATA)-->


Wondering if I just update the DTD if it'll work?
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
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
thumbnail
Brian Russell, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Junior Member Mensajes: 41 Fecha de incorporación: 31/10/11 Mensajes recientes
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.
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
I think you can use Jelmer's suggestion about deploying via the EXT plugin in 6.0.6 CE...
thumbnail
Mika Koivisto, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6? (Respuesta)

Liferay Legend Mensajes: 1519 Fecha de incorporación: 7/08/06 Mensajes recientes
This feature is available starting from 6.1 CE and 6.0 EE SP2.
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
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...
thumbnail
Mika Koivisto, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Liferay Legend Mensajes: 1519 Fecha de incorporación: 7/08/06 Mensajes recientes
Yes, you can still use the Ext way in 6.0.6.
thumbnail
Brian Russell, modificado hace 12 años.

RE: Servlet Filter via Hook in 6.0.6?

Junior Member Mensajes: 41 Fecha de incorporación: 31/10/11 Mensajes recientes
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, modificado hace 10 años.

RE: Servlet Filter via Hook in 6.0.6?

New Member Mensajes: 2 Fecha de incorporación: 3/08/06 Mensajes recientes
Brian, How did you implement this using EXT. I am running into same issue of : Element type "struts-action" must be declared.