Saturday, September 29. 2012
Couchbase Manager for Glassfish: JavaEE examples
After the announce for the couchbase-manager-0.1 this post is going to show how it deals with some JavaEE sample applications. Before the releasing I made it work with some of them in order to make the manager compatible with part of the typical JavaEE elements (EJB, CDI, JSF Managed Beans, JavaEE security and so on). As it is said in the release notes for 0.1 version the manager is still not fully tested but, at least, some applications work.
JSF Beans, CDI and EJBs.
JSF and EJB are two important technologies in the JavaEE world and I recovered the old CertSecurityCustom project for the occasion. If you remember that project lets us login using a certificate or a typical username/password form and checks the user against an LDAP repository. The project mainly consists in a EJB and a session JSF bean. After making all the objects to implement the Serializable interface and fixing some issues with the manager (mainly the memcached transcoder must use a special glassfish Input/Output object stream) it worked like a champ.
Here I realized another thing, an application can get and attribute from the session, change it and not set it back (it is supposed that it is the same object and no set is necessary). So in 0.1 version the manager marks as dirty any session when any attribute is got (that means mainly all sessions are always set or cas, for the moment touch is only used when the attribute retrieved is a simple object -Integer, String and some other classes that cannot be changed internally-).
Besides I inject the JSF bean using CDI (@Named) and typical bean (@ManagedBean), and same with the ldap ejb (@EJB and @Inject). The four combinations worked after the commented changes.
JavaEE security
JavaEE security is another hard issue I wanted to be functional in the first realease. The application that I chose was the CertSecurityJavaEE project (the second example in the certificate login series which uses again an LDAP server but doing standard JavaEE security).
More problems here were found. Glassfish declares the principal property of the session as transient (keyword that means the property has to not be serialized and therefore saved). Looking at the replicated glassfish implementation, I saw that only the username property is kept replicated. If the session is used in another server (in which the user did not logged in), the replicated implementation logs the used silently using a special method in the realm (createFailOveredPrincipal). I did the same trick. Now the manager session has a username property that is saved in couchbase with the other data, when the session is filled that property is checked and if it is different from the principal in the session (null mainly) the principal is recovered from the realm calling the same method.
That was very nice but it didn't work with the LDAP realm. I opened a bug with the issue but silence is the only answer til the moment (some collaboration please!). Changing the realm from ldap implementation to file (users and groups are stored in a plain file) my solution works as expected. The user logins to one application server and if it changes (non-sticky load balancing or a failure in sticky configuration) the user is logged in the background. Take in mind that this happens the first time the user access a new server (the manager sees the principal is null but the username is filled and it uses the realm to reassemble the principals of the logged user).
With all those changes my little application started working using the couchbase manager.
Java Pet Store 2.0EA
Finally I tested the typical Pet Store application. This application was for along time a kind of a reference application for JavaEE, now it is abandoned and its last version 2.0EA is only JavaEE4 compliant (not 5). Nevertheless I think it is a good test cos it mixes several technologies of the JavaEE specification.
With the pet store application I faced with a glassfish issue when using mod_jk and mod_deflate in the apache. But after fixing that issue the manager started to work smoothly. All the session beans were transformed into serializable objects (in version 0.1 the manager uses standard java serialization to convert the session into a byte array, that means all the objects that are going to be saved inside the session should implement the Serializable interface).
And here it is the video. First the custom ldap login application is shown (the application refused to change me from one server to the other but finally it did), you can see how the couchbase console shows one session and, as soon as I log out, the session disappeared. Then the standard JavaEE security application is accessed. Both servers maintain my logged session using the file realm. Finally I enter Pet Store application and click over some of the pages which work smoothly.
Well, the couchbase-manager-0.1 is working with some (more or less) complicated JavaEE applications. I am conscious that there are more tests to do, and that is the reason to release the first version, let more people testing it. If anyone of you is interested in the manager please install it and test it with your applications (use github or this blog to report issues). Of course I guarantee nothing about the fix.
ciao!
Comments