Pregunta

usando el marco de primavera aquí ...

He creado un filtro para cambiar el cuerpo de respuesta de los archivos CSS y si llamo a una URL directamente se ejecuta. Sin embargo, si se coincide con una regla de urlrewrite, se salta el filtro.

Ejemplo: En web.xml:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <!-- skipping init params here for brevity -->
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>cssFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
    <filter-mapping>
    <filter-name>cssFilter</filter-name>
    <url-pattern>*css</url-pattern>
</filter-mapping>

Hay un mapeo configurado como este en urlrewrite.xml:

<rule>
    <from>/styles-special/(.*)$</from>
    <to last="true">/styles/$1</to>
</rule>

(necesitamos esto por varias razones)

SO, CUALQUIERO DE * .CSS cuya ruta comienza con W / "/ Styles-Special /" se reescribirá a "/ estilos /" y se llamará a la CSSFilter, pero cualquier archivo * .CSS cuya ruta se inicie w / "/ estilos /" se ejecutará a través del cssfilter como se esperaba.

He intentado cambiar el patrón de URL para CSSFilter a una serie de opciones diferentes, pero el mismo resultado. Me parece que el filtro Tuckey Urlrewrite simplemente no llama a Chain.Dofilter () después de una reescritura, pero tal vez sea más complicado que eso?

¿Alguna idea de lo que el problema podría estar aquí? ¿Es esta funcionalidad esperada? ¿Alguna solución? ... ¿Tal vez un interceptor o controlador sea la forma de ir aquí?

¡Gracias de antemano por algún consejo sobre esto!


NOTA: Uso de lo siguiente (como se sugiere AXTAVT):

<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>

Corrige el problema con encadenamiento y se ejecuta el filtro. Sin embargo, obtengo el siguiente error:

java.lang.IllegalStateException: NO CONTENT
at org.mortbay.jetty.HttpGenerator.addContent(HttpGenerator.java:106)
at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:644)
at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:579)

Aquí está el fragmento del código del filtro:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    OutputStream out = httpResponse.getOutputStream();
    GenericResponseWrapper wrapper = new GenericResponseWrapper(httpResponse);

    chain.doFilter(request, wrapper);

    if(log.isDebugEnabled()) log.debug("doFilter: chain");

    String respBody = new String(wrapper.getData()); // this throws error
...

¿Fue útil?

Solución

When Tuckey UrlRewrite Filter rewrites a URL, it forwards request to the new URL instead of passing it down the filter chain. By default filters are not applied to the forwarded requests, so you need to configure it:

<filter-mapping>
     <filter-name>cssFilter</filter-name>
     <url-pattern>*css</url-pattern>
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
</filter-mapping>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top