我有一个带有战争网络应用程序的 .ear,它由 n 个网络片段罐子组成。在使用 url 模式映射过滤器时,我不知何故无法让我的 servlet 过滤器调用 doFilter 甚至 init 方法。我正在使用一个映射到应用程序根目录并过滤每个请求的 shiro 过滤器。这个过滤器实际上是有效的,并且 shiro-filter 的代码被执行:
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
当我尝试在另一个 web-fragment.xml 中注册以下过滤器并调用 localhost:8080/application-name/myservice/getMyData 它只是忽略提供的 url-pattern:
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment metadata-complete="true" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<display-name>My Web Application</display-name>
<servlet>
<servlet-name>MyService</servlet-name>
<servlet-class>at.mycompany.product.service.impl.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyService</servlet-name>
<url-pattern>myservice/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>GetToPostServlet</servlet-name>
<servlet-class>at.mycompany.core.common.service.GetToPostServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GetToPostServlet</servlet-name>
<url-pattern>myservice/getToPostServlet</url-pattern>
</servlet-mapping>
<filter>
<filter-name>HttpGetToPostFilter</filter-name>
<filter-class>at.mycompany.core.common.service.HttpGetToPostFilter</filter-class>
<init-param>
<param-name>at.mycompany.core.common.service.utils.HTTP_GET_TO_EMPTY_SOAP</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpGetToPostFilter</filter-name>
<url-pattern>myservice/getMyData/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- ServiceInfoFilter: ServiceInfo speichern -->
<filter>
<filter-name>ServiceInfoFilter</filter-name>
<filter-class>at.mycompany.shared.util.info.ServiceInfoFilter</filter-class>
<init-param>
<param-name>ServiceInfoFilter</param-name>
<param-value>ServiceInfoFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ServiceInfoFilter</filter-name>
<url-pattern>myservice/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>at.mycompany.core.common.service.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>myservice/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>The unprotected myservice servlet</web-resource-name>
<url-pattern>/myservice</url-pattern>
</web-resource-collection>
</security-constraint>
</web-fragment>
上述过滤器触发器都没有......我还尝试了不同的 url 模式,例如:
<url-pattern>/myservice/getMyData</url-pattern>
<url-pattern>myservice/getMyData/</url-pattern>
<url-pattern>myservice/getMyData/*</url-pattern>
我究竟做错了什么?没有证据表明 url-patterns 不适用于规范中的 web-fragments:http: //download.oracle.com/otn-pub/jcp/servlet-3_1-fr-eval-spec/servlet-3_1-final .pdf?AuthParam=1539621798_87c76bcc77456ce463d523d10f4ac5e1
我知道我也可以通过 servlet-mapping 绑定过滤器,但我真的不想用 GetToPostFilter 过滤来自 MyService 的所有请求,只过滤 .../getMyData 上的那些请求