COMP 405
Spring 2014

GAE How-To's

Home  Info  Owlspace  Java Resources  Eclipse Resources  SharePoint  Piazza

 

Logging

Ref: https://developers.google.com/appengine/docs/java/runtime#logging

To enable logging in GAE, you need to instantiate a Logger object which provides methods to log String messages at various severity levels.

import java.util.logging.Logger;

private static final Logger log = Logger.getLogger(MyServlet.class.getName());

Logging in GWT clients

Since GWT client code runs in Javascript, logging needs some extra setup:

In the module's .gwt.xml file, add the following lines:

	   # Gets the GWT logging code
	  # Enables the Logger
	    # Sets the logging level to INFO
	  # disables the pop-up logging display.  Logs to browser's Javascript console.

Note that the Java code still must import java.util.logging.Logger and instantiate a Logger instance as above.   The calls to the Logger object are the same as well.

References:

Adding Additional Developers to a GAE Project

To enable other people to be administrators and thus manage and upload new code to a GAE project, the owner of the project must add them to it.

  1. As the project's owner, log into http://appengine.google.com and go to the desired project.
  2. Go to Administration/Permissions
  3. Under "Invite a user to collaborate on this application", fill in the e-mail address of the new developer you'd like to add.  
  4.  Select "Developer" as the role.

 When the invited developer receives the e-mail, they will be presented with 2 choices:

  1. A link to use if the account is not already a GAE account.
  2. A link to use if the account is already a GAE account.

Critical Point:  To accept an invitation to join a GAE project, be sure your browsers are completely logged out of all other accounts!    Simply closing the browser is not always sufficient because some browsers, like Chrome, maintain their login status in cookies and thus can retain the logged in status across application close/reopen cycle.     Cutting and pasting the acceptance URL into a "private" or "anonymous" browsing session seems to help.

"Unauthorized" error when trying to accept an invitation:   This usually means that you are still logged into a different account somewhere.   Explicitly log out of every browser and try using a "private/anonymous" browser session.

Be sure that you copy the entire invitation response URL!   For instance, MS Outlook auto-generates a hyperlink for the URL, but for some reason, misses the last character of the URL (usually an "=" sign), thus giving an incorrect URL to go to and causing an "Unauthorized" error.    

After succefully accepting an invitation, the accepted project will now show up in the new developer's GAE account.    One can tell that a project is from another person's account because it does not reduce the number of available projects in one's account.   The new developer will have administrator privileges to the accepted project.

 

Dynamically Swapping GWT Widgets

To mutate a GWT user interface, one typically swaps in one widget for another in the user interface, e.g. a panel full of widgets, for another panel of widgets.  Since these panels of widgets are dynamically transferred onto the display, as opposed to being statically defined as part of the display, they are not added to the RootPanel hierarchy in the EntryPoint's onModuleLoad() method.  Instead, they are dynamically added in response to some action, e.g. some user input.

TIP:  Unfortunately, the GWT Designer only shows those widgets that have been added to the RootPanel's hierarchy.   To make it easier to design the code for your dynamic widget, add the following line to your onModuleLoad() or initGUI() methods:

RootPanel.get("").add(dynamicWidget);

The widget should now show up in the GWT Designer.    When doing a GWT compile, simply comment out the above line.

TIP: It is very difficult in GWT to get a reference to a widget that was already installed into a container widget.   Instead, "decorate" the desired widget by placing it inside a SimplePanel, which only holds one widget at a time.    Instead of  addng the widget to the container, add the SimplePanelinstead.

This way, to replace the widget installed into the mirror, all you need to do is to reference the SimplePanel object.  You don't need to hunt around for the widget to remove because it can only be in the SimplePanel's one spot.    Call the clear() method of the SimplePanel to disconnect the installed widget.   Now add the new widget to the SimplePanel.   

 

Dynamically Updating/Refreshing GWT Widgets

Because GWT widgets are part of the HTML of a web page, getting them to update dynamically can be problematic.    For instance, added an item to a ListBox may not automatically update the screen to show the new element in the list.   Whether a widget updates or not may depend on whether the updating is happening synchronously or asynchronously.  That is, suppose the list box is being updated as the result of an asynchronous call to the back-end server.   By the time the server responds, the browser's view has already been redrawn, so any changes to the list box do not show up on the screen.

Unfortunately, GWT does not seem to provide any obviously useful methods to accomplish this updating/refreshing process.

One, very ugly but effective, way to accomplish this is to utilize the "Decorator" pattern used above for dynamically swapping widgets.  Install the widget you wish to dynamically update using a decorator and then whenever you wan to update the widget, simply clear the decorator and add the same widget back in.

 

Connecting to GAE Dev Server (App Launcher) from another laptop

By default, the Google Plugin's Dev Server will bind the apps to "localhost:xxxx" which cannot be accessed from another external machine.   The trick is to get the Google Plugin's App Launcher to bind the app to "0.0.0.0" which will in turn bind it to the host machine's actual IP address.   You can do this by adding an additional "Program argument" to the project's Run Configuration:

  1. In Eclipse, highlight the root of the desired project.
  2. Go to "Run/Run Configurations..."
  3. Under the "Web Application" heading on the left column, click on your project.
  4. In the "(x)= Arguments" tab, add this parameter:   -bindAddress 0.0.0.0
  5. Click Apply or Run.

You should now be able to access your app running on your local machine as A.B.C.D:xxxx where A.B.C.D is the IP address of your machine.

 


© 2013 by Stephen Wong