2

For my app engine application, I want to assign a servlet to a url pattern, but also set up the Objectify filter as described here: https://code.google.com/p/objectify-appengine/wiki/Setup.

In my app.yaml I've got

handlers:
  - url: /v1/*
    name: v1
    servlet: org.restlet.ext.servlet.ServerServlet
    ...etc...

which is routing requests to my servlet just fine, but I can't figure out how to arrange for the Objectify filter to run on the same requests that the servlet is handling.

The GAE docs say "A filter is a class that acts on a request like a servlet, but may allow the handling of the request to continue with other filters or servlets."

OK, good, that's what I want. But the docs also say "A single URL mapping can include either a filter or a servlet, but not both."

So... how do I do this?

4

1 回答 1

3

过滤器在 servlet 之前运行,它们不是独占的。通常,对于一个请求,所有过滤器都会运行,然后选择并执行给定 Url 的一个 servlet。

在您的 yaml 中创建一个新的过滤器部分:

handlers:
  - url: /v1/*
    name: v1
    servlet: org.restlet.ext.servlet.ServerServlet
  - url: /*    
    name: ObjectifyFilter
    filter: com.googlecode.objectify.ObjectifyFilter

注意:最好让 ObjectifyFilter 在所有请求(url: /*)上运行,以确保始终初始化 objectify。

于 2013-10-24T19:31:41.503 回答