Skip to content

Get GWT working in WebSphere with details

I had to deploy a GWT application (2.x) based on GWT-platform into IBM WebSphere (6.1 and 7) and that was not piece-of-cake at all. It has been tested on JBoss (4.x) first without any issue. So what is wrong with WebSphere (or GWT) ?

Available information in forums sounds more like magic than engineering: one thread about Guice, another about GWT Dispatch.

As I am not satisfied when something falls into function [hum, my favorite expression in french: "tomber en marche"] without deep understanding, I have investigated why GWT/Guice does not work out-of-the-box on WebSphere and how it should work.

  • First, WebSphere does not trigger your Guice ServletContextListener at application initialization without additional Web Container Custom Properties. Here it is:
    com.ibm.ws.webcontainer.invokeFiltersCompatibility = true
    from WebSphere v7 InfoCenter
  • Second, WebSphere only triggers the listener at first request on a Servlet only, but not for resources like generated GWT html/javascript content. With a GWT application, you get the initial content from a JSP and then a RPC call to /dispatch. I have not checked if the ServletContextListener is already called because of the request to the JSP, which is a specific kind of Servlet. The call just fails with 404, as if the listener has not been triggered.
  • Conclusion part 1: even if your application does not require any JavaEE Servlet, you have to register one, with the option load-on-startup to enforce the listener to be really called at application deployment.

But it is not enough. When a new servlet mapping is added with the Servlet API, WebSphere does not honor it. It still answers 404 about /dispatch.

So the fake servlet you have to use to initiate the context and trigger the listener at application deployment MUST be mapped to /dispatch to reserve the servlet mapping in WebSphere. Then the DispatchServletModule will replace the fake servlet by the real DispatchServiceImpl when invoking the method serve on /dispatch.

Next trouble: the gwtapplication.jsp page is registered as a welcome file list in web.xml. So when you use /myappcontext/ in your browser, you get the gwtapplication.jsp content. Great it works ! Until a RPC call to a SecuredAction is invoked. It fails with a security failure because of the lack of the security cookie at client side. Why ? The Guice filter is not invoked, the pattern *.jsp has not been matched. To ease diagnostic, the DispatchService answers a blank page with status code 200. Thank you guys for the non-ending wait progress in the browser, why not return a 403 status ? Here is the bug report.

Now how to get WebSphere to behaves like others, I mean Tomcat the reference implementation ? Just add the following custom property to the Web Container:
com.ibm.ws.webcontainer.mapFiltersToAsterisk = true

In case of doubt or failure, just directly browse /myappcontext/gwtapplication.jsp to get your security cookie set.

Here I am. All that work to get a GWT/Guice/gwt-platform application just work in WebSphere. Hope it may save you some hours.

Bonus: during my tests, I have made a mistake in servlet name reference for servlet-mapping tag. Guess what: you just get a NullPointerException in SystemOut with any obvious cause in stack trace. The IBM guy has forgotten to handle human failure in its web.xml configuration parsing ! I would expect a clean error message like the servlet name « foobar » referred in servlet-mapping at line X is unknown. It may help.

Digikam does not start ? Do not drop your database (yet) ! It may be fixed.

Here is a post to give some hope to Digikam users in trouble with their metadata database.

Under some tricky conditions, Digikam may « corrupt » its SQLite database and then refuse to start with such messages:
$ digikam
QSqlDatabasePrivate::removeDatabase: connection 'ConnectionTest' is still in use, all queries will cease to work.
QPainter::end: Painter ended with 2 saved states

That ConnectionTest message may be normal and expected. But the error window displays more valuable information:

The schema updating process from version 4 to 5 failed, caused by an error that we did not expect. You can try to discard your old database and start with an empty one. (In this case, please move the database files « digikam3.db » and « digikam4.db » from the directory « /home/yma/Pictures »). More probably you will want to report this error to the digikam-devel@kde.org mailing list. As well, please have a look at what digiKam prints on the console.

In my case, I am aware of what went wrong: I have started two Digikam processes almost in the same second and I have decided to kill them both because of my CPU at 100%. Then it denies to start again.

Browsing for a solution in forum leads to the definite action: delete the database and restart from scratch. That was not satisfying for me, my last database re-init was three years ago and my fear to loose my tag indexing makes me investigate.

Based on this SQLite how-to, I have first checked that the SQLite database itself is not « corrupted ». Run the integrity checking and try to export its content:
$ sqlite3 digikam4.db
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma integrity_check;
ok

$ echo .dump | sqlite3 digikam4.db > archive-digikam4.sql

That operations have passed successfully, there is hope. At least I have a complete or partial backup in SQL format.

Using SQLite browser, I have simply discovered that the DBVersion row in table Settings has the value 0 instead of the expected 5 version, which is consistent with the error message displayed.

Then the fix: set 5 instead of 0 there, save the database and restart Digikam. Here it is !

Now I am pleased to have found the way to get my Digikam database back… and I hope this post may help anyone with the same trouble or something close to get his issue fixed.

My own Firefox Sync – Weave server

Hello,

I am still reluctant to store my personal information online or use free services provided by company that already claims it may stop for any reason (Google, Microsoft). So I do not make an exception for Mozilla for Firefox Sync service.

As I do not have an online server at home and have no other needs to pay for a hosted VM, I want Weave to deploy and run at Free.fr.

The official weave server which consists in User and Sync components requires Alias directive in Apache2 but Free.fr does not allow that directive in htaccess file.

The minimal weave server is now maintained but uses SQLite with PDO interface as a storage. As Free.fr provides a MySQL service, why would I bother with SQLite. It is straightforward to switch to PDO:mysql but Free.fr does not enable this backend. In fact, the only PDO backend supported at the moment is SQLite…

OK, so it is open-source, I have never written PHP yet but it is just another language to learn and the only source I have to change is « weave_storage.php ».

Job done:

  • Prefix tables with weave_ to prevent collision with other services, typically for user table
  • Port SQL create statements and indexes to MySQL
  • Rewrite weave_storage code to replace PDO and exception handling by old-school mysql_* methods and error handling
  • Use class.JSON.php instead of recent included json_(en|de)code methods

In N900 Firefox, open about:config to set your own URL as value of services.sync.serverURL.

After some code cleanup, creation of a sql file, a short documentation in README, here is a package, including a patch based on latest version on date of 2011.03.23. This release should work with Sync plugin versions 1.6.x and 1.7 in Firefox 3.6, 4 or 5:
weave_minimal_server_20110626_mysqlJSON.tar.gz

Additional note for free.fr users, in case of mixed PHP 4 and 5 hosting: you have to create a .htaccess file with content php 5 to enforce PHP 5 usage.