开发者

How do I apply a servlet filter when serving an HTML page directly?

开发者 https://www.devze.com 2022-12-29 18:40 出处:网络
First off, I\'m using Google AppEngine and Guice, but I suspect my problem is not related to these. When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in developmen

First off, I'm using Google AppEngine and Guice, but I suspect my problem is not related to these.

When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in development mode, it is: http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997. Now, I setup my web.xml in the following way:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_2_5.xsd"
 version="2.5">
 <display-name>PuzzleBazar</display-name>

 <!-- Default page to serve -->
 <welcome-file-list>
  <welcome-file>Puzzlebazar.html</welcome-file>
 </welcome-file-list>


 <filter>
  <filter-name>guiceFilter</filter-name>
  <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>guiceFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <!--
  This Guice listener hijacks all further filters and servlets. Extra
  filters and servlets have to be configured in your
  ServletModule#configureServlets() by calling
  serve(String).with(Class<? extends HttpServlet>) and
  filter(String).through(Class<? extends Filter)
 -->
 <listener>
  <listener-class>com.puzzlebazar.server.guice.MyGuiceServletContextListener
  </listener-class>
 </listener>

</web-app>

And my appengine-web.xml is:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmln开发者_运维百科s="http://appengine.google.com/ns/1.0">
    <application>puzzlebazaar</application>
    <version>1</version>
    <sessions-enabled>true</sessions-enabled>

    <!-- Configure java.util.logging -->
    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>     
    </system-properties>

</appengine-web-app>

Since I'm using Guice, I have to configure extra filters in my ServletModule, where I do this:

filter("*.html").through( SecurityCookieFilter.class );

But my SecurityCookieFilter.doFilter is never called. I tried things like "*.html*" or <url-pattern>*</url-pattern> but to no avail. Any idea how I should do this?


You've probably configured html files to be served up as static content in your appengine-web.xml. Static file serving doesn't involve your app at all, so you can't filter the output.


If your need happens to be (like mine) to make GAE add certain http response headers for static HTML files, you can do this by declaring them as static resource in appengine-web.xml like this:

<static-files>
  <include path="/my_static-files" >
    <http-header name="Access-Control-Allow-Origin" value="http://example.org" />
  </include>
</static-files>

I found this in the GAE documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号