我已经使用给定的 xml 在 liferay 中创建了一个钩子
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 7.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_7_2_0.dtd">
<hook>
<servlet-filter>
<servlet-filter-name>Servlet Request Filter</servlet-filter-name>
<servlet-filter-impl>package.SecurityFilters</servlet-filter-impl>
</servlet-filter>
<servlet-filter-mapping>
<servlet-filter-name>Servlet Request Filter</servlet-filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</servlet-filter-mapping>
<servlet-filter>
<servlet-filter-name>Servlet Request DocumentDownloadFilter</servlet-filter-name>
<servlet-filter-impl>package.DocumentDownloadFilter</servlet-filter-impl>
</servlet-filter>
<servlet-filter-mapping>
<servlet-filter-name>Servlet Request DocumentDownloadFilter</servlet-filter-name>
<url-pattern>/documents/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</servlet-filter-mapping>
</hook>
部署此挂钩后,我看到此异常:
The content of element type "hook" must match "(portal-properties?,language-properties*,custom-jsp-dir?,custom-jsp-global?,indexer-post-processor*,service*,servlet-filter*,servlet-filter-mapping*,struts-action*)".
如果我注释掉一个或另一个 servlet 配置,则挂钩部署正确,并且我可以在日志中看到过滤器正在工作。 从 DTD 中我了解到我应该能够放置许多 servlet-filter 和 servlet-filter-mapping,所以我不确定我在哪里犯了错误。 DTD 文档
If an element name in DTD is followed by the star [*], this element can occur zero, once or several times.
是否可以在一个 liferay hook 中创建 2 个 servlet 过滤器?
根据 DTD,您使用的是 Liferay 7.2 - 考虑忽略 6.x 挂钩概念并使用 OSGi ServletFilter:
@Component(
immediate = true,
property = {
"before-filter=Auto Login Filter",
"dispatcher=REQUEST",
"servlet-context-name=",
"servlet-filter-name=My Servlet Filter",
"url-pattern=/change/me"
},
service = Filter.class
)
public class BladeServletFilter extends BaseFilter {
@Override
protected void processFilter(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, FilterChain filterChain)
throws Exception {
// implement your own logic here
}
}