How does Android and App Engine interact?

Well, that might seem like a silly question, but I'm really a newbie when it comes to Cloud Computing / Google App Engine, etc. To get a better look at it, I started working with some tutorials from developers.google.com, mainly following the tutorials, and then trying to make small changes to the provided code snippets to make sure that I really understood how it works, and not just copy / paste and take everything for granted.

The problem is that I am a bit stuck with the following: the way Android and App Engine interact. I am currently doing this tutorial ( https://developers.google.com/eclipse/docs/endpoints-addentities ). The problem is the following code snippet (client side, on Android):

public class EndpointsTask extends AsyncTask<Context, Integer, Long> { protected Long doInBackground(Context... contexts) { Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder( AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() { public void initialize(HttpRequest httpRequest) { } }); Noteendpoint endpoint = CloudEndpointUtils.updateBuilder( endpointBuilder).build(); try { Note note = new Note().setDescription("Note Description"); String noteID = new Date().toString(); note.setId(noteID); note.setEmailAddress("E-Mail Address"); Note result = endpoint.insertNote(note).execute(); } catch (IOException e) { e.printStackTrace(); } return (long) 0; } } 

As far as I understand, at the moment, from the point of view of Cloud Computing, I assumed that the connection between Android and the cloud is through the end object, where the end point is:

  Noteendpoint endpoint = CloudEndpointUtils.updateBuilder (endpointBuilder).build(); 

In addition, the updateBuilder () method looks like this:

  public static <B extends AbstractGoogleClient.Builder> B updateBuilder( B builder) { if (LOCAL_ANDROID_RUN) { builder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID + "/_ah/api/"); } // only enable GZip when connecting to remote server final boolean enableGZip = builder.getRootUrl().startsWith("https:"); builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { public void initialize(AbstractGoogleClientRequest<?> request) throws IOException { if (!enableGZip) { request.setDisableGZipContent(true); } } }); return builder; 

}

I understand that inserting into the Data Warehouse is done through insertNote () - which basically does the basic standard insert method.

My problem is that I cannot figure out where, in the cloud, the information that I sent from my Android device is caught. To be more specific, I am sending an object, and I cannot see where this object is received in the Cloud. It’s probably not that important with such a basic application, but I want to develop an application with the following structure: I send data from my Android device using REST. I am developing my server code) (which will be located in the Cloud). In my server code, they will receive the data that I send from Android → process this data → add something to the database (a database stored in the cloud) (this is the basic principle explained by VERY primitive terms). That's why I really want to understand how this works, and so far I really don't see where my data is received on the server side. I suggested that there is probably some kind of automatic mechanism behind this? If so, I'm really curious if you could tell me how I can do this programmatically.

In addition, I would like to mention that this code works very well, so there are no errors in it, I just have problems understanding all the details associated with it.

Thanks.

LATER CHANGE: My database will be the App Engine data store. The main problem is that I can’t understand how the connection is made between my Android application and the Google App Engine application (where I will do all the necessary calculations with the data received from Android). I could use a more “obvious” / explanatory (for dummies) code snippet where I really see that the object I'm sending from Android is received in the Google App Engine application. Of course, I saw the result using the Datastore Viewer, which shows that the data is inserted into the database. What interests me is how I can simply send data to the Google App application, get it there and perform some operations on it, and ONLY after I add it to the database.

+4
source share
2 answers

The updateBuilder() method is not located on the server side. This is part of the Android code. CloudEndpointUtils is part of the android. This is the class that you create to process the template code for you, so you do not need to enter it every time you need to access the server. You see the code

 Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder( AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() { public void initialize(HttpRequest httpRequest) { } }); 

It is assumed that your api is called Noteendpoint and that you are "creating" an object to access it. You could call endpointBuilder.build() to start a request to your api. If you look closely in the CloudEndpointUtils.updateBuilder method, you will see that what it does is redirect your calls to your localhost, and not to your deployed code in appengine.

Let me know if you need clarification.

RESPOND IMAGE:

Forget for a moment that this is a Google endpoint application. You basically develop a system that accepts input, works with inputs, and then stores the result in a database.

Now let's assume that it doesn't matter if the input comes from a terminal or file or to an api endpoint call. You absolutely need to create a layer that will manipulate the data, and then transfer that data to your save level (i.e. database). So you need it (still ignoring all the google / appengine stuff):

  • JPA entity (POJO only with metrics and setters and only JPA annotations)

  • Data Access Level: This is a class with methods for executing queries on your JPA POJO (using EntityManagerFactory ).

  • Business layer: this is the class in which you manipulate the data you received and then transfer the result to the data access layer.

Therefore, you have Business logic layer => Data access layer => JPA POJO . So create anything that doesn't bother you, whether it will work on your local glass fish or anywhere.

AFTER you finish, add endpoint annotations to your Business layer methods. These annotations basically mean that after creating the android endpoint library your android will be able to call your Business layer methods as if they were in your Android application codes.

Did you understand? It will be as if your android and your server were like that. Are you using the Google Eclipse plugin for this project?

+5
source

I really do not understand your question. "Cloud" represented by Google App Engine. This lives on Google’s servers and is served by the URL that you assign when you create the project. It is assumed that the database will be either the App Engine datastore or the Google Cloud SQL service that uses the version of MySQL.

+2
source

All Articles