GWT 2.0.4 now available in maven central

Posted by David Chandler - Friday, July 16, 2010 at 12:45:00 PM

I'm pleased to announce that the GWT 2.0.4 jars are now available in the maven central repository. Better maven support has been frequently requested on the issue tracker and mailing list, and this is a first step in that direction. In the future, Google will publish GWT releases to maven central as part of the release process.

The GWT 2.0.4 jars currently in the repository include gwt-user, gwt-dev, and gwt-servlet. Please note that gwt-soyc-vis as a separate jar has been deprecated and soyc (story of your compile) is now bundled with gwt-dev.

GwtRpcCommLayer - Extending GWT RPC to do more than just basic serialization

Posted by Fred Sauer, Developer Advocate - Wednesday, July 14, 2010 at 4:23:00 PM

Would you like to have unit tests for your server code which exercise the same call sites which are used by your users? Would you like to do batch processing using these same RemoteService APIs, without having to drive a web browser? If so, this article is for you. Jeff McHugh, from Segue Development, has offered to share his work, which builds on the RPC capabilities that ship with GWT.

Extending GWT RPC to do more than just basic serialization

If are you currently working with GWT and require serialization, this article might be a great interest to you. GWT RPC is an API provided by the GWT SDK that makes client/server communication easy to implement and support. I developed GwtRpcCommLayer, a library that sits on top of of GWT RPC, that:

  1. makes performance-testing (a.k.a. stress-testing) simple to execute without any changes to your existing code
  2. makes unit-testing possible from within a command-line scripting framework such as Maven or Ant
  3. makes it very possible to have a “web service” type interface to your backend server, but instead of having to restrict access to just browsers, the very same servlet code can support Java clients implemented in Swing, AWT, or other servlets

This post will explain how GwtRpcCommLayer makes this possible. The entire codebase is available for download and can be used with your GWT projects.

Background

As you already know, the GWT SDK contains a very powerful serialization mechanism that can be easily leveraged to make AJAX RPC calls. This serialization mechanism is called GWT RPC. The API reflects the overall spirit of Java's RPC mechanism, which allows you to call remote objects' methods just as if they were running within the local JVM. In either case, there's no need to handle any of the marshaling/un-marshaling (serialization/de-serialization) details. That is all taken care of by the underlying framework of the API.

What makes GWT RPC so powerful is that it enables Java developers to be more productive, by allowing them to stay grounded with their existing implementation model, i.e. no conversions to and from JSON, XML, CSV. If you already have objects in your model such as UserAccount, LineItem, etc., you don't need to spend the extra effort building a mapping to and from JSON or XML.

Taking advantage of GWT RPC requires no additional libraries outside of the standard GWT SDK, and it is straightforward to use, making it a great solution for serialization.

GwtRpcCommLayer

My extension to GWT RPC takes advantage of the underlying foundation of how GWT RPC is designed, but swaps out the standard GWT “serialization engine” with one that uses simple Object serialization via java.io.ObjectStream.

The design of the code-base is naturally separated into two distinct parts:

  • Client side code – code executes within a JVM (replacing the JavaScript Engine), which could be a command-line app, Swing/AWT app, ANT task, intermediate servlet, etc.
  • Server side code – code executes on your server, within your servlet container, and fits seamlessly within your existing servlet code

The following requirements were part of the design goals when I started working on the project:

  1. The syntax of usage should exactly mirror the calls the developer is already using in his/her client side application. Examine the following client-side code:
    UserAccount ua = gwtRpcServerImpl.getUserAccount('x@xyz.com');

    when using GwtRpcCommLayer on the client side, things should work the same:
    UserAccount ua = gwtRpcCommLayerServerImpl.getUserAccount('x@xyz.com');
  2. The footprint on the server side must be as close to invisible as possible. The existing server methods had to be left untouched.
  3. The developer must be able to utilize this codebase without making any changes to existing servlet code. GwtRpcCommLayer could be added retro-actively, without any need for servlet modification.

All three of these requirements were met, which will hopefully encourage developers to not only try this library out for themselves, but perhaps even contribute to the development of further enhancements and functionality.

How it works

The basic premise of the design follows the same design pattern used by GWT RPC, but instead of using a delimited/ASCII format, I simply swapped that out with Java's standard Object serialization. Since both GWT RPC and Java RPC mandate that Objects intended to be serialized must implement the java.io.Serialization interface, the process was straightforward.

Additionally, I took took advantage of the Java Reflection API which allows for runtime compilation of “proxy” classes. Using reflection, it is possible to shield the developer from any awareness of the “serialization engine”, which satisfied one of my three requirements: purity of syntax.

Below is a very basic diagram of (#1) how the GWT RPC interaction works and (#2) how the GwtRpcCommLayer interaction works. Keep in mind that from the developer's point of view, nothing changes in terms of how the code executes, both on the client and server side.

Server Implementation

In order to take advantage of GwtRpcCommLayer, you can choose one of two options. Both options work well. The choice comes down to style more than anything else.

Option 1

Create an instance of GwtRpcCommLayerServlet in your web.xml file. Specify your own servlet as an initialization parameter:

<servlet> <servlet-name>GwtRpcCommLayerServlet</servlet-name> <servlet-class>gwtrpccommlayer.server.GwtRpcCommLayerServlet</servlet-class> <init-param> <param-name>GwtRpcCommLayerServletImplClass</param-name> <param-value>example.server.GreetingServiceImpl</param-value> </init-param> </servlet>

Choose option 1 if you don't want to alter your servlet classes.

Option 2

Servlet classes which extend com.google.gwt.user.server.rpc.RemoteServiceServlet should instead extend gwtrpccommlayer.server.GwtRpcCommLayerServlet. Since GwtRpcCommLayerServlet itself extends RemoteServiceServlet, all the same methods are available to your servlet and your server code will continue to operate normally. Upon review of the associated source code, you will observe that the main service method has been overridden to provide branch logic to handle both normal GWT RPCs and the newly supported GwtRpcCommLayer RPCs.

Client Implementation

Client implementation is simply a matter of instantiating a “proxy class” and making the same remote service calls your client code would normally make. Here is a simple example:

//STEP 1: create the URL that points to your service/servlet URL url = new URL("http://127.0.0.1:8888/example/greet"); //STEP 2: create an instance of GwtRpcCommLayerClient GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url); //STEP 3: ask the client for a reference to the client-side proxy of your remote service GreetingService stub = (GreetingService) client.createRemoteServicePojoProxy(GreetingService.class); //STEP 4: any call you execute against this proxy will ultimately execute on your servlet String echoResponse = stub.greetServer("hello world");

As you can see from the above fictitious service, it only takes 3 lines of code to gain access to your remote service and it will behave just as if these were regular GWT RPC calls.

Usages

  • Encapsulate the above calls in some more sophisticated threading and you should be able to see how easy it is to create a “stress test” for your server code.
  • Encapsulate the above calls into unit tests and you can suddenly perform a client/server unit test for each and every exposed remote method.
  • It should also be obvious that this class lends itself to doing backend processing. Perhaps you have the need to do batch processing using a CSV file. Instead of having to develop another interface (or web service), you could instead simply use your existing codebase and existing servers.
  • As time advances for a particular project, you might develop the need to expose some of these services to a client other than a browser. Your codebase can easily serve as a starting point for that, hopefully cutting down on your implementation time.


GWT 2.1 Milestone 2 is now available

Posted by Chris Ramsdale - Friday, July 02, 2010 at 12:07:00 PM

It’s been a busy week for the GWT team. We released an updated GWT Gadgets library, GWT 2.0.4, and to cap things off pushed the second milestone release of GWT 2.1 today. In this milestone we simplified the process of configuring a RequestFactory, made record creation within a RequestFactory more extensible, and properly moved ourselves out of bikeshed. A full list of features and fixes can be found here.

With the release of GWT 2.1 M2, we’re continuing to evolve the integration between Google and VMware that was announced at this year’s Google I/O. Each milestone release of GWT, Spring Roo, and STS fleshes out more of the envisioned feature set, and overall stability of the stack.

GWT 2.1 M2 is available on our Google Code download site. We’d love to hear your feedback and thoughts on this release, and our GWT Developer Forum would be the best place to post this information.

GWT 2.0.4 is now available

Posted by Chris Ramsdale - Wednesday, June 30, 2010 at 2:09:00 PM

Recently Apple released Safari 5, which included a bug where non-integral right-shifts were not being evaluated properly. There were several reports, both internally and externally, of GWT-based applications unexpectedly crashing when running in Safari 5 (including Google Wave). Upon further inspection of the crash, we determined that the bug is triggered when calling several of GWT's array sorting methods, which in turn perform non-integral right-shifts as part of the compiled code.

That's the bad news. The good news is that we have a fix for this issue, plus several other house keeping items that we've rolled into a 2.0.4 release, which can be downloaded from GWT’s main download site.

If you’re experiencing the Safari crash, you’ll need to recompile and deploy your GWT app. The changes in 2.0.4 are completely compatible with your existing 2.0 app, and should have no negative impact. To that extent we’ve already dogfooded 2.0.4, verifying that it fixes the Wave crash that was originally reported.

Google API Libraries for Google Web Toolkit - Gadgets Update

Posted by Eric Z. Ayers - at 9:57:00 AM

Although its only been a few weeks since the previous release of the open source gadgets library for Google Web Toolkit (GWT), a major overhaul to the gwt-gadgets project has been underway and we are excited to announce that these changes are ready to be released as gwt-gadgets-1.2.0.

Gadgets allow a developer to create applications that can be embedded in another website. Sites that support gadgets include iGoogle, My Space, Orkut, Linked In or Google Wave. These sites all adhere to the Open Social Foundation specifications for gadgets and the Open Social API. This release incorporates the following features into the GWT bindings:

  • Updates the API to make use of the gadgets.* JavaScript API namespace. Previously only the legacy gadgets API was supported.
  • Adds OS Lite API (1.0) core support.
  • Updates the Gadget RPC sample and provided a utility class to simplify use of GWT-RPC.
  • Adds support for gadget Locale settings.
  • HTML strict or quirks mode can be selected.
  • Gadget manifest names can be generated with short or long format.
  • Changes the Feature classes to interfaces to allow mocking for unit testing.
  • Adds a new sample application with demonstrates the use of Open Social, OAuth, App Engine and the Maps API together in a gadget.

We would like to recognize Hilbrand Bouwkamp for helping update the GWT-RPC support in the library. Hilbrand is the author of cobogwave which adds Google Wave specific support for GWT based gadgets.

This new release is now available for download at Google Code

The Google API Library for GWT Team

Sharing Code - Online and Offline

Posted by Chris Ramsdale - Thursday, June 10, 2010 at 11:29:00 AM

Update: Patrick Chanezon, Google Developer Advocate, has supplied us with a video interview with Matthias, which can be found here.

Today's guest blog post comes from Matthias Büchner, Software Engineer at digital security company, Gemalto along with his colleagues: Colin Gormley, Jonas Pärt and Ella Segura. Here they discuss their Device Administration Service, and the recent port to GWT.

Introduction

The Device Administration Service (DAS) solution allows you to manage the personalization and lifecycle of smart card devices. It was developed using ASP .NET and native JavaScript as a hosted web application. Our team was asked to port the solution for deployment as both a hosted and an offline standalone system.

We had three major goals for the re-design:

  1. Use the same code base for both the hosted and offline solutions. A single code base would reduce the cost of maintenance and support in the future without increasing too much the upfront cost of development. In order to achieve this we needed a solution that was not dependent upon any server based technology.
  2. Improve testability. One of the biggest problems for the existing DAS solution was the lack of sufficient automated unit and functional tests. A large amount of time and resources was required to manually validate the solution.
  3. Enhance usability. The existing DAS was still using the submit/refresh page approach of web 1.0 and definitely needed modernizing. The re-design was a good opportunity to select a technology that offers a more desktop-like experience.

Here was our strategy:

  1. Identify which features require a serve-side component. These were going to be our problem areas.
  2. Look for a solution that will run inside a browser offline. We wanted to keep the interface the same for both hosted and standalone deployment.
  3. Select our technology carefully, keeping in mind testability and cross-browser compatibility.

GWT was the obvious choice. It addresses all the goals we had outlined, plus we really looked forward to writing Java code again after living and breathing complex native JavaScript for so long. The prospect of using JUnit had us practically salivating. In this article, we will discuss how we designed our application with GWT and give a few tips that we learned while developing it.

A Smart Card Driven Architecture

A smart card is a secured electronic chip typically embedded in a plastic card or inside a USB dongle. Two examples of what a smart card can do are managing physical and logical access, and securing electronic transactions. Despite their small size, they offer a self-contained operating system and can run very advanced applications. The card is connected to the PC using a smart card reader and the low level communication between the reader and the smart card is done via an APDU.

Traditionally, you are required to install some platform-specific software on your computer before you can communicate with a smart card. This software is known as middleware, and typically takes up a large footprint and must be developed for specific environments. Gemalto developed a browser extension, called SConnect™ , which allows communication with a smart card using JavaScript. SConnect is available on most major operating systems and browsers. SConnect™ is to the smart card what AJAX is to the web. SConnect communicates asynchronously with a smart card, eliminating latency problems on the user interface. We anticipated that this feature would have a strong impact on our design approach.

We investigated the GwtEvent class and its callback mechanism to manage the asynchronous communications. An event is fired just once, and it is handled by one or more handlers. The one-to-many model fits perfectly with how we wanted to manage the notification mechanism when the card is either inserted or removed from the reader. We created card insertion and removal events and utilized an event bus to manage the event firing. Unfortunately, we found difficult to follow and debug event-driven code.

Callback mechanisms are better suited for one-to-one relationships between the callers and the callees. We opted to use callbacks to manage most of the business and low level logic, since they are mostly one-to-one relationships.

When several callbacks, that required data sharing, were chained in sequence things got a little ugly. We started with nested callbacks. As you can see in the AsyncCallbackExample class, the code flow can be difficult to follow and decipher. To solve the problem, we created the following Wrapper class. This class allows us to create a final instance of the data we need to share. Separate callbacks no longer had to be nested to access and change the data we are passing around.

 
public class Wrapper {
    private T value;
 
    public Wrapper() {}
 
    public Wrapper( T value ) {
        this.value = value;
    }
 
    public void setValue( T value ) {
        this.value = value;
    }
 
    public T getValue() {
        return value;
    }
}

This class allowed us to improve the readability and ease the maintenance of our code. You can see in details how to use it in our class example.

Rebuilding the User Interface

Our goal was to move all our source code to Java/GWT; this includes the entire user interface that was designed originally with ASP controls. We looked for an existing widget library since we did not want to spend a lot of time developing custom components. ExtJs GWT was a library that some of us were already familiar with, so it was a natural choice.

From a bird's eye view, most of the interface looks the same. Take a closer look, and you'll find that much of the details have been improved.

Data are loaded and updated asynchronously. Status messages and popup dialogs are now more like a desktop application. One of our goals was to keep the source code modular and easy to maintain. We were all excited at the prospect of writing code in a single language. The benefits of moving from source code written in ASP .NET + native JavaScript + CSS + HTML to Java are many. We especially were attracted to compile time checks, unit tests and writing all our code in a professional IDE.

We knew we wanted to structure our code in a way that would allow us to decouple the interface from the business logic. The video from Google I/O 2009 on best practices for architecting GWT app pointed us in the right direction. We adopted the MVP pattern and divided our UI code into presenters and displays using the gwt-presenter library.

In the DAS application, there is more than one presenter at work on any single screen. We needed the presenters to interact with each other but did not want them too tightly coupled. To address this issue, we brought in the event bus. Instead of presenters listening to events being fired by other presenters, now everyone alerts the event bus when something significant happens and registers themselves to the event bus for any events they are interested in.

The DAS application is currently localized for three languages. Implementing the Constants and Messages interfaces was very straightforward. We put all the text in an Excel spreadsheet for delivery to our translators and converted it into Property files.

We hit a small bump in the road when we realized that GWT does not take language settings of the browser into account for localization. You have to pass in ?local=xx in the URL when launching the application. To solve this problem, we had to take two approaches. For the hosted solution, we can easily parse the request header for language information and pass that into GWT using the Meta tags. For the standalone solution, where we cannot send any HTTP request, we settled for reading the system language settings from JavaScript and passing that information into GWT.

A Testing Strategy

There is a consensus in the developer community on the great benefits that unit tests provide. Unfortunately there is no good JavaScript unit test framework. In the ASP .NET version of the project, validation was done manually. A device configuration issue or similar problem would put the result off its intended target. Achieving measurable test coverage was not possible. Porting our application to GWT helped solve this problem. We just lost our last argument for not writing unit tests.

One aspect of the DAS user interface which is different from traditional web applications is that we have to interact with a smart card. Almost every function of the application requires a smart card to be inserted and some features require two smart cards. The smart card itself is a difficult device to test, it needs to be inserted into a smart card reader and much of the website is driven by smart card removal and insertions. Automating the device would require some sort of smart card or reader emulator that would trick the system into believing that the device was inserted. The technology involved is very low level, and emulating the interface is not a trivial task. We had to look for another solution.

Here is an overview of our application architecture.

We abstracted the Smart Card Layer to mock device interactions to higher layers and kept some of the manual (or semi-manual) tests for the lower layers. It divided out tests into two categories; unit tests and integration tests. Unit tests would use mocked Smart Card layer while the integration tests would require real smart cards to be inserted into readers during test execution.

Designing the Smart Card Layer

To enhance the testability of our code, we wanted to be able to mock parts of it that requires a smart card. To be mock-able, the Smart Card Layer needed a contract with the upper layer, we put in place an abstract base class that would expose functional methods and at the same time lock down how the result and potential errors were to be reported. Any class inheriting from the base class would be responsible for the device interaction.

Here is an extract of the base class:

 
protected abstract void getSerialNumber();
 
public final void getSerialNumber(AsyncServiceCallback callback) {
    ...
    getSerialNumber();
    ...
}
 
protected void onGetSerialNumberFailure(ServiceError error) {
    getSerialNumberCallback.onFailure(new GetSerialNumberResult(error));
}
 
protected void onGetSerialNumberSuccess(String serialNumber) {
    getSerialNumberCallback.onSuccess(new GetSerialNumberResult(serialNumber));
}

This contract would allow us to write an implementation for every type and variation of smart cards we needed to support, with the added bonus of allowing us to add a mock smart card layer implementation. The mock smart card implementation doesn't actually perform any smart card operations. Instead, we configure in the setup code of a unit test the expected input and return values for the test case.

Here is an extract of the mocked class extending the abstract class shown above.

 
public MockConfiguration getSerialNumberConfig = new MockConfiguration();
 
@Override
protected void getSerialNumber() {
    getSerialNumberConfig.execute(new RunMe(){
    @Override
    public void run() {
        if (getSerialNumberConfig.isSuccess()) {
                onGetSerialNumberSuccess(getSerialNumberConfig.returnValue);
            } else {
                onGetSerialNumberFailure(getSerialNumberConfig.serviceError);
            }
        }
    });
}

Unit tests

A unit test sets up the underlying mock classes for the test scenario and then makes the call to the subject of the test. These tests allowed us to validate our business logic in different use cases independent of a smart card. In effect we were able to make sure that our application would fail gracefully if the smart card behaved in an unexpected manner.

We used the code coverage tool EMMA to assert that every anticipated (and unanticipated) failure condition worked properly.

Here is how we configure the mocked class:

 
ConfigurableMscmMock mscmMock = new ConfigurableMscmMock();
mscmMock.getSerialNumberConfig.returnValue = "112211221122112211221122";

Using the above techniques, we exceeded our expectations of automated test coverage.

Conclusion

Overall, we are impressed and excited about what is possible with GWT. We were able to rebuild a complex browser-based application and deliver a consistent product for both the offline and hosted solutions with improved user experience and testing methodology.

The new DAS is one of the first smart card applications built with GWT at Gemalto. This project has proved to be a great learning experience for the team. We hope the foundation we built here will be a spring board for many more GWT applications to come.

Thank you for reading our article - for more information about DAS, please visit http://www.gemalto.com.

Google Maps API for GWT 1.1.0 released

Posted by Fred Sauer, Developer Advocate - Tuesday, June 01, 2010 at 11:03:00 AM

We are pleased to announce the Google Maps API for the Google Web Toolkit 1.1.0 release. The Google Maps API library provides a way to access the Google Maps API from a GWT project without having to write additional JavaScript code. The library gives you full control using the standard Maps components such as InfoWindows, Markers, MapTypes, Overlays, StreetviewPanorama and Geocoding service. You can even use advanced features such as adding GWT widgets to the Map, creating custom overlays, custom map types, and other components.

The changes since 1.0.4 include:

  • Library updated for compatibility with GWT 2.0
  • Added support for Street View
  • Improved support for AdsManager
  • Added support for Aerial and Mapmaker map types
  • Improved support for TrafficOverlay through addition of GTrafficOverlayOptions equivalent
  • Added support for ZIndexProcess for Markers
  • Added support for LatLonBox bounds for Placemark
  • Added Eclipse project files and ant script to HelloMaps
  • Other issues noted in the issue tracker

This release is now available for download at the Google API Libraries for GWT project, hosted on Google Code.

The Google API Library for GWT Team