Case study: Google maps

The purpose of this tutorial is to illustrate SemiSpace usage and space interaction, by making a server able to query and use Google maps API. In order to query Google, you need have a Google maps key.You can still follow the example, even if you do not have a key yet; You can see the interaction in the logs.

The tutorial explains how you can set up a server that takes care of the google communication. It also demonstrates how you can limit which clients that are allowed to use the server.

The swing client also demonstrates how you can use the actor pattern for internal communication.

None of the examples are particularly refined, but they should offer a starting point of understanding the SemiSpace technology, and what you can do with it.

The webapp server

The purpose of the webapp server, is to create the a control application for google map search. Since all searches are performed on a single server, you can:

  • Keep your google application key private
  • Cache content lookup
  • Refine existing search result by modifying the cache
  • Control which clients that are allowed to connect and use the service
  • Control to content lookup rate, for instance disallow more than 1 lookup per second

The swing client

The swing client offers a simple interface, which allows you to log in onto the webapp server. Once logged in, you can perform address lookup queries that are performed on the server. The communication is performed over web services.

The swing setup is performed with SwiXML, which is a sensible and pragmatic XUL framework.

Starting the webapp and client

The following explains startup of a standalone (development) server without terracotta. Presumably you have, in the top level directory, successfully run

mvn clean install

Starting the webapp

In order to start the webapp, either put the war file in a suitable webapp container, or run the following:

cd semispace-tutorials/semispace-google-webapp
mvn jetty:run

When you look at http://localhost:8080/semispace-google/ you should see an entry page. This page allows you to enter users and google key. Notice the link to the WSDL file: http://localhost:8080/semispace-google/services/tokenspace?wsdl This is the endpoint when connecting to the webapp from the standalone application.

Alternative to mvn jetty:run

A standalone application has been created as part of the build. Take a peek in the Jetty / Terracotta integration chapter for how to run it.

Starting the client

Enter the directory where the client reside, and find the target directory:

cd semispace-tutorials/semispace-google-client/target

You should find a zip file in this directory, which can be used in the following manner:

mkdir some_directory
cd some_directory
unzip ../google-client.zip
chmod a+x gclient.sh 

If you do not run a unix-based operating system, you need to create your own startup script.

Start the client with:

./gclient.sh http://localhost:8080/semispace-google/services/tokenspace

This shall give you the login page.

Client / server interaction

Without having registered neither users nor google key in the webapp, try enter a (spurious) name and password in the login box, and press login. Notice the log messages.

Now, register a name and password in the webapp. Then try to log in again with the client. The screen should change to allow search expressions.

Enter an address to search - the same way you would do it in Google maps for and press submit. Try, for example,

Kongensgate 14, Oslo, Norway

The server should log the query, but as no google map key has yet been registered, you naturally do not get a search result. On the client, the query times out because not answer is received.

Register a key and try to search again. You should see the search expression in the server log, and the client should display the information that was retrieved from google.

Notice that if you try to search again with the same key, you receive the cached version from the server.

Try and remove the user by registering a user with the same name as an existing user, but with an empty password. When you try to search in the application, the login box appears again, as the user is no longer authenticated.