【发布时间】:2015-06-03 18:51:01
【问题描述】:
如何将 servlet 映射到 cron url?这个问题来自对以下帖子中答案的评论:Use Cron jobs with Appengine Endpoints API
在我的项目中,cron 作业被调用,如 Google App Engine 中的日志所示,并且 URL https://[url-commented-out].appspot.com/_ah/api/stocksApi/v1/stocks 在 Web 浏览器中测试时正确执行并返回正确的值。
但是当我尝试在 GAE 中运行它时,我收到错误 405:此 URL 不支持 HTTP 方法 GET。我已阅读 https://cloud.google.com/appengine/docs/java/config/cron 我在 cron.xml 文件中的代码是:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/_ah/api/stocksApi/v1/stocks</url>
<description>Backend Process Stocks</description>
<schedule>every 1 minutes from 11:10 to 11:30</schedule>
<timezone>America/New_York</timezone>
</cron>
</cronentries>
我的 web.xml 是:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>
[package].StocksEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>cron</web-resource-name>
<url-pattern>/_ah/api/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>ObjectifyFilter</filter-name>
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ObjectifyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我正在使用 Android Studio,并通过关注 HelloEndpoints 添加了一个后端模块,并且我有一个 StocksEndpoint.java 带有 getStocks() 的文件;返回股票的方法。
【问题讨论】:
标签: google-app-engine servlets android-studio cron google-cloud-endpoints