2016-03-27 13 views
0

私はGoogle Cloud Endpointsを使用してアプリケーションのバックエンドを設定しようとしていましたが、実際にデータストアにエンティティを挿入しようとするまでうまくいっていたようでした。Google Cloud Endpointの挿入がクライアントから機能しない

GenericBikeオブジェクトを生成されたエンドポイントを使用してデータストアに挿入しようとしていますが、コードがコンパイルされて正常に実行されている間に、プロジェクトWebページをチェックすると実際に挿入されるものは何もありません。

実際に挿入するためのコードです。

private class AddGenericBikeAsyncTask extends AsyncTask<GenericBike, Void, Void> { 
    @Override 
    protected Void doInBackground(GenericBike... params) { 
     GenericBikeApi.Builder builder = new GenericBikeApi.Builder(AndroidHttp.newCompatibleTransport(), 
       new AndroidJsonFactory(), null) 
       .setRootUrl("https://banded-coder-125919.appspot.com/_ah/api/"); 
     GenericBikeApi service = builder.build(); 
     try { 
      GenericBike bike = params[0]; 
      Log.e("Debug", "Inserting bike..."); 
      service.insert(bike); 
      Log.e("Debug", "Done inserting bike."); 
     } catch (IOException e) {e.printStackTrace(); } 
     return null; 
    } 
} 

そして、ここで私はそれが助け場合

if (mGenericBikes == null) { // we need to preload the database still 
     for (int i=0; i<10; i++) { 
      GenericBike bike = new GenericBike(); 
      bike.setId(new Long(i+1)); 
      new AddGenericBikeAsyncTask().execute(bike); 
     } 
    } 

それを呼び出すところで、ここで私のGenericBikeのentitiyです。

@Entity 
public class GenericBike { 

@Id Long mId; 
boolean mAtStation; 

public GenericBike() { 
    mAtStation = true; 
} 

public Long getId() { 
    return mId; 
} 

public void setId(Long id) { 
    mId = id; 
} 

public boolean isAtStation() { 
    return mAtStation; 
} 

public void setAtStation(boolean atStation) { 
    mAtStation = atStation; 
} 

編集:ここでは、あなたのクライアントからの要求を起動していないよう

/** 
* Inserts a new {@code GenericBike}. 
*/ 
@ApiMethod(
     name = "insert", 
     path = "genericBike", 
     httpMethod = ApiMethod.HttpMethod.POST) 
public GenericBike insert(GenericBike genericBike) { 
    // Typically in a RESTful API a POST does not have a known ID (assuming the ID is used in the resource path). 
    // You should validate that genericBike.mId has not been set. If the ID type is not supported by the 
    // Objectify ID generator, e.g. long or String, then you should generate the unique ID yourself prior to saving. 
    // 
    // If your client provides the ID then you should probably use PUT instead. 
    ofy().save().entity(genericBike).now(); 
    logger.info("Created GenericBike."); 

    return ofy().load().entity(genericBike).now(); 
} 
+0

問題を説明するのに気をつけますか? – Gendarme

+0

@Gendarme、申し訳ありません、私の脳は今は少し揚げられています。エンドポイントを使用してデータストアにGenericBikeオブジェクトを挿入しようとしていますが、コードがコンパイルされて正常に実行されているように見えますが、プロジェクトWebページをチェックすると実際に挿入されるものは何もありません。 – noblera

+0

"GenericBikeApi.Insert"メソッドコードを投稿できる場合にのみ、それを理解することができます。 –

答えて

1

が見えるのインサート()メソッド用に生成されたエンドポイント・コードがあります。実際にリクエストを開始するには、クライアント・オブジェクトに.execute()を追加する必要があると思います。

service.insert(bike).execute(); 

service.insert(bike); 

を交換する。また、あなたのApp Engineのログをチェックすると、要求が実際に通過したことを確認するための良い出発点です。

+0

それはまさに問題でした。私はlist()メソッドで正しく行ったので、どのように私がそれを見逃したのか分かりません...ああ、ありがとうございました。あなたは私に頭痛のトンを救った。 – noblera

関連する問題