[Help] GWT + GAE + Android - Where to start?

186 views
Skip to first unread message

Bruno Brito

unread,
Feb 10, 2014, 7:31:23 PM2/10/14
to google-we...@googlegroups.com
Hey guys, this is my first post here, so I'm sorry if I'm not clear enough about my question.

Well, basically what I want to do is:
- Create a website using GWT and deploy it to App Engine in order to use the datastore. I've already done it, nothing wrong about it.
- The second part of this project is about building an Android App which can access the same datastore that I use for my GWT project. Read the entities and retrieve them to display on the screen. And also use Google Cloud Messaging.


The problems are:
- I've noticed that there is Google Mobile Backend Starter which already deploys a backend to AppEngine and allows Cloud Messaging and many other features. But, how would I link GWT to this same application at GAE? If I deploy my GWT project, I lose the Android one.
- I was also following this guide here: https://developers.google.com/appengine/docs/java/endpoints/getstarted/backend/setup in order to create my own backend, deploy it to AppEngine and then use the client endpoints with Javascript. However, if I do this, I can't deploy my GWT website to this app engine application.

I don't know if I was clear enough. I've searched the group and saw some posts similar to my question, but none was very clear about it.

I'll be glad if anyone can help.

Thanks!

Bruno Brito

unread,
Feb 11, 2014, 10:45:56 AM2/11/14
to google-we...@googlegroups.com
So, I found this video from Google I/O


And that is basically what I needed. However, as I found out, Google Cloud Endpoints came to replace this Appengine Connected Android Project. And if I start one using the current GPE, I don`t have the same projects and classes.
Any tips on how to use Android and GWT as clients with Appengine as server?

Andrew Mackenzie

unread,
Feb 11, 2014, 1:56:14 PM2/11/14
to google-we...@googlegroups.com
You just need to "layer" GWT on top of the GAE/J "servlet/jsp" application by including web pages that load the JS generated by the GWT compiler.

I.e. you build ONE app that does it all, with server code and GWT generated JS all in one combined /war dir. You then debug locally on the devserver or deploy to a GAE app id.

You develop GWT modules with client/shared/server code. Server code must be servlet code with no GWT calls. Shared code must be pure Java. Client code uses GWT jars and using the .get.XML module description files get compiled to JS in your /war Dir. Then load the generated "loader" for the JS code in an HTML file you put in /war also.

There are GWT sample projects on App Engine you can follow.

I have tried using the GWT RPCs from Android code and it works but is tricky and unduly couples your API for the mobile app to GWT. So I suggest you develop a core set of server API calls that you can call from (thin) GWT RPC services and an XML/JSON API you expose to your mobile apps (if you decide not to use endpoints).

I will dig out a presentation I did on out experiences (SlideShare) and post a link....but you can find many tutorials and sample code.

Andrew Mackenzie

unread,
Feb 11, 2014, 1:57:43 PM2/11/14
to google-we...@googlegroups.com

Bruno Brito

unread,
Feb 11, 2014, 2:13:56 PM2/11/14
to google-we...@googlegroups.com
Andrew Mackenzie,

Firstly, thank you very much for your answer.
I'm very new to using AppEngine and GWT, so I'm not very sure I understood everything. I still got a lot of homework to do.

I'm following a GWT + AppEngine tutorial and so far I'm able to create the web client and use the datastore with no problems.
Now, Google provides many ways to deploy a backend to GAE. Including now, they have a Mobile Backend Starter.

So, where do you think I should start from? GWT or Android? I got a bit confused when you said I should build one app with the server code and GWT generated JS combined. Did you mean a GWT app or Android one?
I'm sorry if my questions don't make much sense. But, I'm just starting working with it.

Once again, thank you very much.

Andrew Mackenzie

unread,
Feb 11, 2014, 2:47:19 PM2/11/14
to google-we...@googlegroups.com
No worries. I mean one server wepapp (GAE plus GWT) that exposes an API to your Android app. You might want to chose JSON for API format and use gson library in GAE and Android projects.

The Google Cloud Platform Mobile Backends Starter Project might be a good learning ground as it generates GAE and Android projects for you.

See my post at
http://devcon5.blogspot.com.es/2013/12/google-cloud-platform-mobile-backends.html

If you structure by our code just right, you can have one Pure Java SHARED project (eclipse, would be a module in IntelliJ or maven) that is used by main Android app project and by GAE/GWT webapp project.....but maybe not worthy your effort. It can have common model objects....but you might want to JDO annotate on GAE and not on Android - that will break Android compile.... :-(

If you dont use Endpoints or some other library to help you create REST API then in your GAE project you will have to implement API using servlets mapped to paths (in web.XML) that your Android client uses.

Bruno Brito

unread,
Feb 11, 2014, 2:56:46 PM2/11/14
to google-we...@googlegroups.com
Ok, I believe that now I understood a bit better.

I'll try to finish coding my GWT + GAE project, at least a simple version of it. And later on, I'll start the Android part.
I'll definetely come back and post many more questions.


For now, I'll take a look at the links you sent and do my homework on it all.

Thank you very much.

Bruno Brito

unread,
Feb 14, 2014, 6:51:20 PM2/14/14
to google-we...@googlegroups.com
Andrew Mackenzie,

This is what I've acomplished so far:

- Created my entity class with JDO annotations.
- Created Endpoint class using GPE.
- Created Client Endpoint Libraries using GPE.
- Deployed to App Engine.
- Created an Android App, imported the necessary client libraries and I was able to do basic CRUD operations on my datastore.

GREAT!

Now comes the GWT part. Here's what I've done.
First, I used my backend project with the APIs, created a simple HTML file and used Google Cloud Endpoint support to Javascript to create and use some CRUD operations. Succeed.

My next step was to copy my endpoint classes and libraries to my GWT project and depploy it to my App Engine account.
I tested my Android App and had success with my crud operations.

But now comes the problem. I don't have access to my HTML file to make the CRUD. I had to insert the Javascript code directly to my Java code of GWT. And no matter what I tried, I simply didn't succeed.
Is there an easier way to do this? Because Google Cloud Endpoints supports Javascript client. I know GWT is basically JS, however, it doesn't sound that trivial to me.

Do you have any sample or tips?

Once again, thank you very much.

Em terça-feira, 11 de fevereiro de 2014 17h47min19s UTC-2, Andrew Mackenzie escreveu:

Andrew Mackenzie

unread,
Feb 15, 2014, 7:15:17 AM2/15/14
to google-we...@googlegroups.com
Hi Bruno,
            well you've made a lot of progress, so congratulations.

I think we need to overcome a basic misconception before going further.... 

On the server side, you should only have ONE project, a combined GAE and GWT project, not two.
No need to copy classes and files between projects, etc.
Just think about appengine being the application server that runs your GWT (Javascript) web app.....as if it was TomCat or some other app server.

The only difference over a "GAE only" project is that the GWT compiler will generate JavaScript for you (from your Java code in your /client subfolders for each GWT Module), and if you use GWT-RPCs, then you will have server side code and should include the GWT jars (gwt-user.jar) to receive those RPC requests and respond to them.

To "load" your GWT generated javascript you just need to add a normal <script> tag in your html files to the JS loader generated by GWT compiler.
All that is described in the GWT documentation.

You should be able to build that project to your /war folder (compiled .class files for GAE code, any jsp or html files, web.xml deployment descriptor, appengineweb.xml descriptor, and loader JS files and sub-folders for each GWT Module you compile, etc etc).

Then you can run it all locally with the devserver. Make sure that works before deploying.

Then deploy that project's /war folder to appengine (App engine deploy tools do this for you, packaging your /war folder and uploading).

You should be able to find MANY examples of such a combined project on the web, including the developer samples.
Here are some:

Andrew


--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/UtGnEusj0ig/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Bruno Brito

unread,
Feb 20, 2014, 4:01:48 PM2/20/14
to google-we...@googlegroups.com
Hello everybody,

I've been making a lot of progress in my project, however, once again I faced many problems.

When I chose to use GWT, I didn't think that I would have so much trouble facing Javascript codes.
Just to be clear, I'm using Google Cloud Endpoints APIs + GWT, and as you know, Google Endpoints API access is made via Javascript.

So, here is my problem.
I have an API that should retrieve a list of objects. Example of code:

@ApiMethod(name = "listDeviceInfo")
public CollectionResponse<DeviceInfo> listDeviceInfo(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {

EntityManager mgr = null;
Cursor cursor = null;
List<DeviceInfo> execute = null;

try {
mgr = getEntityManager();
Query query = mgr
.createQuery("select from DeviceInfo as DeviceInfo");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}

if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}

execute = (List<DeviceInfo>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();

// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (DeviceInfo obj : execute)
;
} finally {
mgr.close();
}

return CollectionResponse.<DeviceInfo> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}


But how do I access this API through Javascript?
Well, with a little help from a Google API, I can simply call: 
gapi.client.deviceinfoendpoint
        .listDeviceInfo()
        .execute(
            function(deviceInfoItems, deviceInfoItemsRaw) {
              errorResult = checkErrorResponse(deviceInfoItems, deviceInfoItemsRaw);
              if (errorResult.isError) {
                showError("There was a problem contacting the server when attempting to list the registered devices. " 
                    + "Please refresh the page and try again in a short while. Here's the error information:<br/> "
                    + errorResult.errorMessage);
              } else {
                //Do something with deviceInfoItems.items               
              }
            });

I know how to call this javascript function inside my GWT code using a native method. However, I want to create a List of DeviceInfo objects with the results of this Query inside my GWT Java code, and then I'll be able to manipulate them into a Flex or Grid. 
Is that even possible? How could I do that?


I appreciate any help.
Best Regards.


Em segunda-feira, 10 de fevereiro de 2014 22h31min23s UTC-2, Bruno Brito escreveu:
Reply all
Reply to author
Forward
0 new messages