如何在Google App Engine的app.yaml文件中配置一个Servlet过滤器?

huangapple go评论88阅读模式
英文:

How do you configure a servlet filter in Google App Engine's app.yaml file?

问题

以下是您要的翻译内容:

我正在编写一个用于部署到Google App Engine的Kotlin应用程序。我正在使用Gradle插件来执行实际的GAE部署操作。一切都运行得很好;我已经成功将一个hello-world应用程序部署到了GAE。

然而,现在我需要添加一个过滤器,具体而言是com.googlecode.objectify.ObjectifyFilter。但是,一旦我将这个过滤器添加到我的app.yaml文件中,应用程序将无法再部署。相反,它会给我一个错误,告诉我"filter"不是预期的属性。

这是我的app.yaml文件:

runtime: java11
handlers:
- url: /*
  filter: com.googlecode.objectify.ObjectifyFilter

这是错误信息:

> 任务:webservice:appengineDeployAll 失败
错误:(gcloud.app.deploy) 解析文件时出错:[C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml]
对于类型为URLMap的对象,出现了意外的属性'filter'。
  在"C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml"中,第4行,第11列

我做错了什么?如何在GAE应用程序中配置过滤器?

英文:

I am writing a Kotlin app to be deployed on Google App Engine. I am using a Gradle plugin to do the actual deploy to GAE. Everything had been working fine; I successfully deployed a hello-world application to GAE.

However, now I need to add a Filter, specifically the com.googlecode.objectify.ObjectifyFilter. But once I add this filter to my app.yaml file, the app will no longer deploy. Instead, it gives me an error telling me that "filter" was not an expected attribute.

Here is my app.yaml file:

runtime: java11
handlers:
- url: /*
  filter: com.googlecode.objectify.ObjectifyFilter

Here is the error:

> Task :webservice:appengineDeployAll FAILED
ERROR: (gcloud.app.deploy) An error occurred while parsing file: [C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml]
Unexpected attribute 'filter' for object of type URLMap.
  in "C:\Users\mathew\Documents\fooApp\webservice\build\staged-app\app.yaml", line 4, column 11

What am I doing wrong? How do I configure a filter in a GAE app?

答案1

得分: 1

你必须在部署描述文件中指定 Filter 类。然后,您可以在该过滤器类中设置您的标头。您可以在此处找到有关App Engine中过滤器的更多详细信息。

需要注意的是,这些过滤器不适用于对css和js文件的静态资源请求。

英文:

You must specify the Filter class in your deployment descriptor file. Then you can set your headers inside that filter class. Here you can find more details about Filters in App Engine.

Something to keep in mind is that these filters do not work for static resources requests for your css and js.files.

huangapple
  • 本文由 发表于 2020年9月10日 01:43:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63816878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定