我知道连接是有效的,因为我正在拉/插入没有问题的对象
然而,当我尝试使用各种方法删除时,我得到了相同的异常
java.lang.illegalArgumentException:DELETE with non-zero content length is not supported
方法1(使用原始数据存储区服务和插入项目时存储的密钥):
@ApiMethod(name = "removeRPurchase")
public RPurchase removeRPurchase(RPurchase purchase) {
NamespaceManager.set(purchase.getAccount());
DatastoreService d=DatastoreServiceFactory.getDatastoreService();
Key k=KeyFactory.stringToKey(purchase.getKeyrep());
try {
d.delete(k);
} catch (Exception e) {
e.printStackTrace();
purchase=null;
}
return purchase;
}
方法2
@ApiMethod(name = "removeRPurchase")
public RPurchase removeRPurchase(RPurchase purchase) {
NamespaceManager.set(purchase.getAccount());
Key k=KeyFactory.stringToKey(purchase.getKeyrep());
EntityManager mgr = getEntityManager();
RPurchase removed=null;
try {
RPurchase rpurchase = mgr.find(RPurchase.class, k);
mgr.remove(rpurchase);
removed=rpurchase;
} finally {
mgr.close();
}
return removed;
}
我还尝试了实体管理器和Id的各种变体,但都具有相同的异常
我传入的对象确实包含帐户中的命名空间,并且它包含与对象关联的键的“KeytoString”
在AsyncTask端点中调用端点.removeRPurchase(p).execute();
赞赏任何帮助建议
答案 0 :(得分:1)
使您的API方法成为这样的POST方法:
@ApiMethod(name = "removeRPurchase" path = "remove_r_purchase", httpMethod = ApiMethod.HttpMethod.POST)
public RPurchase removeRPurchase(RPurchase purchase) {
NamespaceManager.set(purchase.getAccount());
DatastoreService d=DatastoreServiceFactory.getDatastoreService();
Key k=KeyFactory.stringToKey(purchase.getKeyrep());
try {
d.delete(k);
} catch (Exception e) {
e.printStackTrace();
purchase=null;
}
return purchase;
}
我有同样的问题,因为我是using httpMethod = ApiMethod.HttpMethod.DELETE
。它给出的错误是正确的。只需将其更改为POST并在该API方法中执行任何操作,例如删除实体,返回实体等。
答案 1 :(得分:0)
如何尝试以下内容:
@ApiMethod(
name = "removeRPurchase",
httpMethod = HttpMethod.DELETE
)
public void removeRPurchase(@Named("id") String id) {
//Now take the id and plugin in your datastore code to retrieve / delete
}