I am trying to follow the tutorial given at; https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial
I am also modifying it for my needs along the way. I managed to follow the tutorial project but when I tried my own entity classes in the backend, I get some errors. For example;
Here is the entity class I created called User;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
private String name;
private String imageType;
private Blob image;
public Key getKey() {
return key;
}
public String getName() {
return this.name;
}
public String getImageType() {
return imageType;
}
public byte[] getImage() {
if (image == null) {
return null;
}
return image.getBytes();
}
public void setName(String name) {
this.name = name;
}
public void setImageType(String imageType) {
this.imageType = imageType;
}
public void setImage(byte[] bytes) {
this.image = new Blob(bytes);
}
}
Then I am defining an AsyncTask as it is explained in the tutorial. I want to take a photo, capture its path in the device and upload that photo to Datastore. Here is my doInBaackground method;
@Override
protected Void doInBackground(Void... params) {
User user = new User();
user.setName("Burak Çopur");
Userendpoint.Builder builder = new Userendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
null);
builder = CloudEndpointUtils.updateBuilder(builder);
Userendpoint endpoint = builder.build();
try {
endpoint.insertUser(user).execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Finally I call this after camera activity returns like following;
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
// Handle activity resulting from IMAGE_CAPTURE
if(requestCode == REQUEST_IMAGE_CAPTURE){
new UserTask().execute(getApplicationContext());
File myFile = new File(mCurrentPhotoPath);
if(myFile.exists())
myFile.delete();
}
}
I checked some similar questions but I could not find the solution. I want to see name field stored first. Then I can move on. Here is the part of error code I am getting;
07-22 02:21:28.941: W/System.err(4852):
com.google.api.client.googleapis.json.GoogleJsonResponseException:
503 Service Unavailable
And here is the problematic line of code;
endpoint.insertUser(user).execute();
I am not trying to do this in local debug server as it is explained in the tutorial. I wanted to see how it works on cloud so deployed my backend project through eclipse. My admin page says my app is running. I also set LOCAL_ANDROID_RUN to false so that it won't try to use local debug server. May problem be that I am not calling new EndpointsTask().execute();
from onCreate method as it is done in the tutorial? Some of the past questions may suggesting something like this but I can't see the reason.
Thanks for any help.
I think I got this. This is actually pretty straightforward. If you are getting this error, that means you backend connection is problematic. Most of the time, it is because you did not provide full information about your project while generating the backend. Make sure you have entered;
-API key from you project page's Credentials
-Project number
-Project name
-Project version
correctly. Othervise you are out of luck. Or you can also work on local server by following the tutorial given at my original post. In either case, make sure to comment out the section specified in the tutorial. I don't know why but it does not work otherwise.
Also you might be trying to store a data type that is not supported by the Datastore API. For that look at;
com.google.appengine.api.datastore.DataTypeUtils
Storing a Blob that is bigger than 1MB is also not allowed. These are all the bits that I can find about this problem. Make sure you have a valid connction with your backend and make sure you satisfy above rules.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments