Servlet过滤器未初始化,URL映射在Web片段中不起作用?

时间:2018-10-15 18:03:58

标签: servlets servlet-filters web-fragment

我有一个带战争Web应用程序的.ear,它由n个Web碎片罐组成。当用url-pattern映射过滤器时,我不知何故无法让我的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模式:

<?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模式不适用于网络片段:http://download.oracle.com/otn-pub/jcp/servlet-3_1-fr-eval-spec/servlet-3_1-final.pdf?AuthParam=1539621798_87c76bcc77456ce463d523d10f4ac5e1

我知道我也可以通过servlet映射来绑定过滤器,但是我真的不想仅使用... / getMyData

中的GetToPostFilter过滤来自MyService的所有请求。

0 个答案:

没有答案