[英]Invoke endpoint class from Cron Job App Engine - Java
In my app engine app, i want to update datstore entites from cron service, which will use endpoint method call to update data. 在我的App Engine应用程序中,我想从cron服务更新datstore实体,该服务将使用端点方法调用来更新数据。 But whenever
cron job
is executed, it returns HTTP 405 status code
. 但是,无论何时执行
cron job
,它都会返回HTTP 405 status code
。 I am not getting where i am going wrong. 我没弄错我要去哪里。 If anybody has any idea regarding then please help me to solve this problem.
如果有人对此有任何想法,请帮助我解决这个问题。 Thank you
谢谢
cron.xml cron.xml
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/cron/gaevalidatecronjob</url>
<description>Cron Job that autoreset validity of poster.</description>
<schedule>every day 00:00</schedule>
<timezone>Asia/Kolkata</timezone>
</cron>
</cronentries>
web.xml web.xml中
<servlet>
<servlet-name>ValidityCheckerCron</servlet-name>
<servlet-class>com.jobaka.dekhbhai.ValidityCheckerCron</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidityCheckerCron</servlet-name>
<url-pattern>/cron/gaevalidatecronjob</url-pattern>
</servlet-mapping>
@SuppressWarnings("serial")
public class ValidityCheckerCron extends HttpServlet {
private static final Logger _logger = Logger
.getLogger(ValidityCheckerCron.class.getSimpleName());
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doGet(req, resp);
try {
_logger.log(Level.INFO, "Cron Job has been executed");
PosterMasterEndpoint endpoint = new PosterMasterEndpoint();
CollectionResponse<PosterMaster> response = endpoint
.getStarRatedPoster(null, null, null);
if (response != null && response.getItems() != null
&& response.getItems().size() > 0) {
Collection<PosterMaster> collResult = response.getItems();
ArrayList<PosterMaster> lstResult = new ArrayList<PosterMaster>(
collResult);
Date today = new Date();
for (PosterMaster posterMaster : lstResult) {
Date validityDate = posterMaster.getValidityDate();
Calendar c = Calendar.getInstance();
c.setTime(validityDate);
c.add(Calendar.DATE, posterMaster.getValidity());
validityDate = c.getTime();
if (validityDate.getTime() < today.getTime()) {
posterMaster.setValidity(0);
posterMaster.setStarRated(false);
endpoint.updatePosterMaster(posterMaster);
}
_logger.log(Level.INFO, "Cron Job has been executed for = "
+ posterMaster.getPosterUrl());
}
}
} catch (Exception ex) {
_logger.log(Level.INFO, "Problem in ValidityCheckerCron");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
doGet(req, resp);
}
}
Removing super.doGet should fix this issue. 删除super.doGet应该可以解决此问题。 The default implementation of servlet methods is to return a method not allowed error (405).
Servlet方法的默认实现是返回方法不允许错误(405)。
According to the Article Scheduled Tasks With Cron for Java 根据文章Cron for Java的计划任务
Calling Google Cloud Endpoints
呼叫Google Cloud端点
You cannot call a Google Cloud Endpoint from a cron job.
您无法通过cron作业调用Google Cloud Endpoint。 Instead, you should issue a request to a target that is served by a handler that's specified in your app's configuration file or in a dispatch file.
相反,您应该向由应用程序的配置文件或调度文件中指定的处理程序服务的目标发出请求。 That handler then calls the appropriate endpoint class and method.
然后,该处理程序将调用适当的终结点类和方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.