私は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();
}
問題を説明するのに気をつけますか? – Gendarme
@Gendarme、申し訳ありません、私の脳は今は少し揚げられています。エンドポイントを使用してデータストアにGenericBikeオブジェクトを挿入しようとしていますが、コードがコンパイルされて正常に実行されているように見えますが、プロジェクトWebページをチェックすると実際に挿入されるものは何もありません。 – noblera
"GenericBikeApi.Insert"メソッドコードを投稿できる場合にのみ、それを理解することができます。 –