【发布时间】:2014-11-21 10:41:29
【问题描述】:
我正在构建一个 GAE 支持的应用程序,它能够存储数据集。外部应用程序可以使用 Google Cloud Endpoints 访问此数据集。
当外部应用程序编辑这个数据集(PUT POST DELETE)时,我想在我的 GAE 上运行一个脚本。我可以通过将此代码添加到 PUT/POST/DELETE api 方法来做到这一点;示例:
/**
* This inserts a new entity into App Engine datastore. If the entity already
* exists in the datastore, an exception is thrown.
* It uses HTTP POST method.
*
* @param sensor the entity to be inserted.
* @return The inserted entity.
*/
@ApiMethod(name = "insertSensor")
public Sensor insertSensor(Sensor sensor) {
PersistenceManager mgr = getPersistenceManager();
try {
if (containsSensor(sensor)) {
throw new EntityExistsException("Object already exists");
}
mgr.makePersistent(sensor);
########RUN SCRIPT HERE########
} finally {
mgr.close();
}
return sensor;
}
但我想知道 GAE 是否针对此类问题提供更好的解决方案?
【问题讨论】:
-
您是否正在寻找数据存储区 PrePut 和 PostPut 回调 (docs) 之类的东西?
-
确实如此。虽然他们不提供 PostGET 以及 PrePOST 和 PostPOST 的回调?
-
也许我误解了你的问题:这些回调用于数据存储区 put 和 get 操作。这不是你所追求的吗?
标签: java rest google-app-engine google-cloud-datastore