使用端点删除/删除Google数据存储区,非法争用例外,不支持非零内容长度的删除

时间:2022-10-30 23:12:06

I'm trying to delete objects from the datastore (using cloud endpoints)

I know the connection is valid because I'm pulling/inserting objects with no problem

我知道连接是有效的,因为我正在拉/插入没有问题的对象

However when I try to delete using various approaches I get the same exception

但是,当我尝试使用各种方法删除时,我得到相同的异常

java.lang.illegalArgumentException:DELETE with non-zero content length is not supported

approach 1(using the raw datastore service and the key I stored when inserting the item):

方法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;
}

Approach 2

方法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;
}

Ive also tried various variations with the entity manager and the Id, but all with the same exception

我还尝试了实体管理器和Id的各种变体,但都有相同的例外

The object that i've passed in does contain the namespace in the account, and it does contain the 'KeytoString' of the key associated with the object

我传入的对象确实包含帐户中的命名空间,它确实包含与对象关联的键的“KeytoString”

the endpoint is called as it should in an AsyncTask endpoint.removeRPurchase(p).execute();

端点在AsyncTask端点中应该被调用.removeRPurchase(p).execute();

Any help suggestions are appreciated

任何帮助建议表示赞赏

2 个解决方案

#1


1  

Make your API method a POST method like this:

使您的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;
}

I had the same problem because I was using httpMethod = ApiMethod.HttpMethod.DELETE. The error it gives is correct. Simply change it to a POST and do whatever you want inside that API method like delete entities, return entities, etc.

我遇到了同样的问题,因为我使用的是httpMethod = ApiMethod.HttpMethod.DELETE。它给出的错误是正确的。只需将其更改为POST并在该API方法中执行任何操作,例如删除实体,返回实体等。

#2


0  

How about trying out the following :

如何尝试以下内容:

@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 }

@ApMethod(name =“removeRPurchase”,httpMethod = HttpMethod.DELETE)public void removeRPurchase(@Named(“id”)String id){//现在获取数据存储区代码中的id和插件来检索/删除}

#1


1  

Make your API method a POST method like this:

使您的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;
}

I had the same problem because I was using httpMethod = ApiMethod.HttpMethod.DELETE. The error it gives is correct. Simply change it to a POST and do whatever you want inside that API method like delete entities, return entities, etc.

我遇到了同样的问题,因为我使用的是httpMethod = ApiMethod.HttpMethod.DELETE。它给出的错误是正确的。只需将其更改为POST并在该API方法中执行任何操作,例如删除实体,返回实体等。

#2


0  

How about trying out the following :

如何尝试以下内容:

@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 }

@ApMethod(name =“removeRPurchase”,httpMethod = HttpMethod.DELETE)public void removeRPurchase(@Named(“id”)String id){//现在获取数据存储区代码中的id和插件来检索/删除}