3

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 xmlns="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?

Philippe Beaudoin
  • 3,290
  • 1
  • 22
  • 25

2 Answers2

3

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.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • Thanks. I've added the appengine-web.xml up there. Anything missing? – Philippe Beaudoin May 05 '10 at 20:57
  • It looks like your html is being served as a static file, and as I say, that means that it doesn't touch your code at all. You need to create a servlet that serves up your files if you want them to be post-processable. – Nick Johnson May 05 '10 at 22:35
  • so, you cant use filter on html page but it will work on servlet and jsp? – Aedric Apr 10 '20 at 04:39
1

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

Leif John
  • 778
  • 6
  • 21
  • cheers for that as it can save a lot of trouble to people. Unfortunately for me, this is a bit shy of perfect as I want a 301 redirection of domains (from the www. to the naked), so if they supported a domain attribute like they do a path one, it would have been perfect (would serve Location header). but AFAIK (and after reading the rest of the docs) it's not possible – João Antunes May 08 '17 at 11:05