Wednesday, May 20, 2009

Using Unit Testing to Test GWT RCP Calls

This is a short note. I'm working on a GWT application and ran into a problem with an RPC call which gets some objects from the database using Hibernate and passes them back to the client. I'm going to solve the problem using Dozer, but I needed to confirm this was the problem and simplify the testing of this in future. So, I decided I want to unit test this service from the client's perspective. Here are my notes from this exercise:
  • The easiest way to create a GWTTestCase is using the GWT's jUnitCreator. Creating it by hand is possible but tricky.
  • The asynchronous test needs to use delayTestFinish(delayMs) and finishTest(). In my case, I had to set 5000 Ms. For some reason, 500Ms, which I thought would be more than enough was timing out.
  • The good news is, that when using Eclipse plugin for GWT, starting initiating Run as JUnit Test on the GWTTestCase test starts for you also the server. And doing the same with Debug as JUnit Test allows to debug the client as well as server code.
Note: the similar test is supported in Flex application!

Tuesday, May 12, 2009

Developing Flex Applications with Java Middle-Tier

Intro
In my job we are using Flex with Java to develop web applications that support the activity of the agency I'm working for. It's my first experience with Flex and I'd say, I'm duly impressed. I had experience of developing using GWT and I must say, that Flex is an equally good tool.

A Simple Way
Just follow this tutorial.

Tools Used
We use the following toolset:

  • eclipse with FlexBuilder plugin (plugin is not free)
  • jBoss
  • Java for back-end
  • LCDS to communicate between Flex and Java (not free, but there are free alternatives: BlazeDS and the LCDS Express is also free, I think).
  • Cairngorm pattern for Flex client structure

Tips and Gotchas

  • A great intro to Cairngorm (and Flex itself) is one by David Tucker.
  • He is using ColdFusion for the back-end, so switch to this or this for how to do it with Java.
The Cairngorm pattern for calling a remote service is a bit complex. Here's how it goes:
  • In the main mxml file (the one where you define mx:Application): instantiate the ServiceLocator: . The id "services" is irrelevant, it seems. And instantiate the FrontController.
  • Let say, the command LOGIN is to be handled by the back-end. Dispatch the command by initiating the LoginEvent and calling dispatch() on it.
  • Each event is mapped onto a command in the FrontController. Let say, in this case, onto a LoginCommand.
  • In loginCommand, instantiate a delegate, say LoginDelegate and call the login(event)
  • In LoginDelegate, obtain the service proxy using:
    ServiceLocator.getInstance().getRemoteObject("myRemoteObject");
    and call the login(args) on it.
  • Now, two additional files need to be setup: Services.mxml and remoting-config.xml
  • In the first one, Services.mxml, define a mx:RemoteObject with id="myRemoteObject" and the destination="myRemoteClass".
  • In the second, the remoting-config.xml, define a destination with id="myRemoteClass" and the Java class package+classname in the source tag.
  • In the Flex Server properties (access through project properties), set the Root Context as the /YourProjectName.
If you need to pass an object between client and the server, create two corresponding value objects (usually named *VO, like LoginVO), one in ActionScript in flex branch and one in Java branch:

  • The ActionScript version, needs to have an annotation above the class definition: [RemoteClass(alias=org.sjb.LoginVO)].
  • The Java version needs to be public and have public setters.
If you want to debug not only Flex (which is done the usual "eclipse" way), stop the JBoss server and start it in Debug mode. That's all that is needed.

Conclusion
Altogether, using Flex with Java is very simple. Enjoy it!

Wednesday, April 29, 2009

How to Deploy a GWT Application to Tomcat?

Intro
OK, so you have tried the GWT (Google Web Toolkit), decided that it's cool, and you created your first application, precisely a module. You have tried it locally on your development machine, using the hosted mode and, may be, in the web mode by using the Compile/Browse button on the hosted-mode preview window. Now, you can either deploy it to Google App Engine, which is a way to try it online free and easily (make sure that your app doesn't become the IP of Google! I haven't looked at the terms of use myself.) or you decide yo want to go for it, and publish it for real. You purchase a Java hosting plan (google for it; you can find some within $12/mo.), and you're ready to deploy your application to your Tomcat server.

Deploying It
I used this re
source to help me with. Basically, follow the steps ( is the root of your GWT application,):
  • create a staging folder (let's call it deploy)
  • copy contents of /www/com.meography.EntryScreen into /deploy
  • create /WEB-INF with folders classes and lib in it
  • create web.xml file in WEB-INF. See the above resource for how to.
  • copy contents of /bin folder to deploy/WEB-INF/classes
  • copy all needed jars into deploy/WEB-INF/lib (you don't need gwt-user.jar nor gwt-dev-windows.jar, though)
  • compress all of the conents of deploy folder into a zip file and rename the file to .war.
  • upload the file to Tomcat, which can be done via browser using Tomcat manager, which is usually already installed for you by your Java hosting vendor. Once the upload finishes, the manager will show your application with options to Start, Stop, Reload and Undeploy it. The name of the app, is the base URL for your app.
Point your browser to the main .html file of the module (URL indicated by Tomcat manager + YourMainScreen.html). And, voila, you should be on. Well, if there are any problems, for example with your database setup, you'll find errors in the catalina.log file in the /tomcat/logs folder on your production server.

Re-Deploying It
To redeploy, after you have done some changes, simply repeat the steps above, but remember to preserve files you had to tweak or create for your production environment like web.xml and possibly hibernate.cfg.xml, if you happen to use Hibernate and use different database on your development machine and on your production server (Java hosting plan will usually have MySQL and PostgreSQL databases included). And, one more thing. I have found that I have to do Undeploy, upload the new .war file and then Deploy for the changes to post correctly. The reason may be, that GWT application is compiled into JavaScript cache files with random names, so the file names will be different each time you compile it, and so, just copying the new .war file over will not replace all of the old files.

Any feedback? Feel free to let me know.

Thursday, April 23, 2009

Developing for Android Platform

Why Android?
I'm a Java developer. Yes, I could enhance my C/C++ skills, get an iPhone and develop for the iDevices. But, I guess, I wasn't motivated enough. Also, I'm a strong supported of open source development. So, first, I noticed OpenMoko platform. But their development slowed down and stopped. Never got to the point when I'd be able to get a phone and develop for it. Finally, I noticed the Google's Android initiative in late 2007. Yes, I'm afraid of humongous corporations like Micstosoft and now Google. Still, I didn't see a more attractive choice. So, I waited for Google to release the Android phone. I could switch to Windows Mobile platform, but this, somehow, didn't attract me. Finally, in Jan 2009, after living with Palm for good 7 years, and I'm a heavy user of the personal organizers (several years ago, I'd create my own notebooks/calendars, so they'd fit my needs; out of paper and cardboard; I did this for good 2-3 years), finally in Jan 2009, I decided it was time to do the move and I purchased a black G1 (for the picture and a story of my other organizers, see this blog).

Does It Fulfill The Promise?
In short, yes. Is it perfect? No. I can suggest several improvements of the top of my head, even just for hardware. And for software, too, of course. Would I recommend it? Definitely. Does it have a potential? Oh, yes, sure. This section could be a topic on its own, but, it will have to wait for another time. Let's move.

So, to Cut To The Chase, How Do I Develop for Android
Simple. The list of tools I use:
  • Eclipse (3.4.2)
  • JDK (1.6)
  • ADT (0.8.0) - great tool. Can even deploy to the device over USB and monitor the app.
  • Positron aka Autoandroid - for integration testing. Unit testing doesn't work that great for fat clients. This is a great tool except for a few hick-ups.
  • jUnit - for the pieces that can be unit testing without reaching to your left year with your right foot.
Do you want more details, technical details? Sure. Here they're:

Where can I find some sample Android applications?
Well, one good sample is the Android platform itself. For example, to see the source code for the native Android calendar application, you can view it here.

Deploying onto the Device:
  • an unsigned .apk file installs with a "Application installation unsuccessful"
  • log a application crash,,, where can I find it? The ADT displays LogCat.

Using Positron aka Autoandroid:
  • If getting an error about Autoandroid "java.net.SocketException: Connection reset" problem, either:
    • rerun the Android Application and run stories again or
    • application crashed on Android
  • If you get error "Internal Error ... ShouldNotReachHere", do
    • go to the jUnit relevant run configuration, //Classpath// and remove the Android Library from Bootstrap.
    • do //Advanced//, //Add Library// and choose JRE System Library
    • add JUnit library the same way

Tuesday, February 3, 2009

To Refinance or Not To Refinance

OK. Mortgage interest rates are falling. Everyone is refinancing or at least trying to do it to benefit from the lower rates. So, I did a research myself as well. There were three distinct ways to do it. I'm describing them below.

No-Cost Refinancing Offer From My Current Mortgage Bank
The WaMu offered to reduce my mortgage by 0.25%, for no cost. The savings looked fabulous (down to $500's from almost $1200 a month), but after I looked at it carefully, it was primarily because they calculated as if for a new 15-years loan, while on my current loan I have only 10 years left. The actual savings would be only about $40 a month.

Best Deal I Was Able To Find on The Internet
I did a search for the best rates. The website (don't remember which one), took me into a lender search instead of giving me a rate. When I clicked the button that said Get Your Rate, I've got a list of lenders instead, and after 5 minutes (yes! even though it was Saturday night, around 8pm), my phone rang and one of the lenders from the list wanted to talk to me. So, in a way it worked smoothly. The thing is, that the best deal the lender had was a rate lower by 0.75% for a closing cost of some $4500. And, no, it wasn't because of my credit score. Mine is over 800, and it was him who checked and told me the score.

ING Direct EasyOrange Refinancing Deal
This deal is about a 5 year loan based on a 30-year period. So, I'd have to payback the whole loan after 5 years. But that wouldn't be a problem in our situation. Anyway, they're giving a rate of 4.75%, which is pretty good right now, for closing costs of $1750 only. Seemed a great deal. Just to make sure it makes even sense to refinance if we don't plan to live in this house more than 2-3 years, I went to timevalue.com website and compared my current mortgage with th EasyOrange deal. The image below shows the results:

It seems after all, that the EasyOrange doesn't save as any money after all.

That was it. I guess, the no-cost 0.25% is the best deal after all. But it will lock me for a year at least. What is rates go down a lot within months?

Tuesday, January 20, 2009

Brief Visual History of PDA's

Today, I had to stay home and take care of our youngest one for a couple of hours. He was very busy playing out the story of Joseph being almost killed and then sold by his loving brothers, that I decided to do some cleanup. Since my G1 phone is more or less setup, I decided to trash the older PDA I used to use and which I still kept in my drawer. I had a moment of nostalgia and so I ended up saving for some of my memories for the generations to come.

Most of my adventure with PDA's is captured by the following picture:


I have been using all these PDA's, including Treo 90, the most fun one, in addition to the cell phone. Finally, with G1, I have one device instead of two. I didn't stress it: I was actually carrying the two devices always with me, wherever I went. One in my pocket and another in a little holster. I got rid of the holster now, which made my wife happy. She never liked this extra decoration. And, besides the two functions being one fullfilled by a single gadget, I must say I enjoy the G1 a lot. It's appearance doesn't give it justice. Really.

There is much more to say about this little brief history topic, but my time is limited while I want to have some left to play with extending WikiNotes app into a more fully developed wiki application. Yes, for G1, or I should rather say, for Android.

Friday, January 2, 2009

Search Web Services or API for Commercial Use

Suppose, you need to collect some data based on Internet search for your business. What options are there to use existing web search services? Google? Yahoo? Anyone else? Here's what I have found.

Google
Here's what I have found:

  • Google SOAP search web services seem not to be available for new applications any more. In 2006, Google seems to have stopped issuing new API keys.
  • There is another option from Google: API not SOAP based. The terms don't exclude commercial use, but there is a restriction on caching the results of the search. I guess, if we process the results and store the processed data, it wouldn't be considered caching.
  • The API services have exclusivity requirement: you are not supposed to use on the same site any other search provider.
Yahoo
Here's what I have found:
  • Y! makes the search available via web services (REST but not SOAP webservices).
  • Each application has to use Application ID, which Y! issues for free. There is a rate limit for each application id.
  • Allowed usage: web search API is available to commercial use, however a form of exclusivity restraint is imposed: you are not supposed to integrate the results with results from other search providers.
  • Storage restrictions: "you may not store any user data collected through the Yahoo! APIs for more than 24 hours". Again, would storing the processed, for example aggregated data, be subject to this restriction? I suppose, not.
MSDN: Live Search WebServices API
Terms of use summary:
  • SOAP-based webservices call Silky Road.
  • No restrictions other than an application ID needed. But their license is more complex and I might have missed something.
Other
I'm sure there are/may be other search web services available, and some of them may be free. DoubleClick? I didn't analyze other options.