Archive for the ‘Tech’ Category

Cool Books

Saturday, December 12th, 2009

Sometime back I was asked by Manning Publications to review proposal for a new book on Drools titled ‘Drools in Action’. The book looks promising and should be useful for those interested in incorporating an open source and standards based Rule Engine into their applications or services.

Open Source SOA is another great resource for Java architects looking at implementing SOA-based solutions with open source products without expensive commercial products.

Introducing Famree

Thursday, November 6th, 2008

Famree is a web based application intended to bring family members together. The application is an open source project written in Java/Groovy and Grails framework. Famree allows you to build your family tree starting with the root of the family and working your way down.

Features

  • Manage family tree
  • Rich User Interface
  • RSS feeds of upcoming events
  • Timeline chart indication key events in the family
  • Charts for family composition
  • Administer Announcements, events, and FAQ
  • Configure multiple site administrators with different authorization
  • Template management

Drools Plugin for Grails Application

Monday, August 4th, 2008

I have just released a Grails Plugin for Drools. The plugin details can also be found at http://www.grails.org/Drools+Plugin.

Drools is a business rule management system (BRMS) and an enhanced Rules Engine implementation, ReteOO, based on Charles Forgy’s Rete algorithm tailored for the Java language.

Features

  • Easy implementation of Drools
  • Rules can be stored in file or in database
  • Rules can be dynamically changed without rebuilding or restarting application

Installation

grails install-plugin drools

Usage

  • Install the plugin
  • Verify example rules: http://localhost:8080/your_app/drools/example
  • Create your own rules: http://localhost:8080/your_app/drools and use droolsService in your code

Components

  • DroolsController: Provides CRUD functionality for Drools Rule
  • DroolsService: Fires all rules

DroolsService
droolsService.fireRules(resource, ruleKey, objList)

  • resource: specifies where the rules are stored. ‘file’ or ‘db’
  • ruleKey: identifier for the rule. For ‘file’ resource, this would be the name of the file (eg:ticket_example.drl). For ‘db’ resource, this is the Drools Rule key
  • objList: list of objects that need to be put in session

Example

A simple Ticket processing system is available in the plugin. This example shows how tickets are processed based on their subscription plan.

Run the example: http://localhost:8080/your_app/drools/example

Your console output should be:

Start processing Ticket # 3
Start processing Ticket # 2
Start processing Ticket # 1
Firing rule Bronze Priority for Ticket # 3
Firing rule Silver Priority for Ticket # 2
Firing rule Gold Priority for Ticket # 1
Firing rule Special Discount for Ticket # 1

Display on your browser should be:

Tickets due for processing:
Ticket #1: Customer[Name:Jack, Subscription:Gold, Discount:0%] Status[New]
Ticket #2: Customer[Name:Tom, Subscription:Silver, Discount:0%] Status[New]
Ticket #3: Customer[Name:Bill, Subscription:Bronze, Discount:0%] Status[New]
Firing rules now …
Tickets after processing:
Ticket #1: Customer[Name:Jack, Subscription:Gold, Discount:5%] Status[Escalate]
Ticket #2: Customer[Name:Tom, Subscription:Silver, Discount:0%] Status[Escalate]
Ticket #3: Customer[Name:Bill, Subscription:Bronze, Discount:0%] Status[Pending]

Grails 1.0.3 upgrade issues

Tuesday, July 29th, 2008

Recently, we upgraded our application running in Grails 1.0.1 to 1.0.3. Just to give you an idea, the application is pretty complicated involving multiple data sources, complex hibernate mappings with JPA annotations, legacy system, linking tons of external services etc. We had to overcome few significant hurdles to get our application to run in Grails 1.0.3.

1. Update hibernate-entitymanager.jar (3.3.2 GA) in /lib

2. Add hibernate-validator.jar (3.0.0 GA) in /lib. Grails 1.0.1 did not require this jar

3. Changes to g:render taglib.
used to work in Grails 1.0.1 template file in _templates/my_template.gsp under grails-app/views/mycontroller/. Now, for Grails 1.0.3 you need to have the template in template/_my_template.gsp.

4. Issues with domain properties.
my_domain.properties = another_domain.properties. This doesn’t work anymore in Grails 1.0.3, at least in some cases. Had to manually copy properties.

5. There are definitely issues with complex hibernate mapping involving legacy system. A particular hibernate relationship was throwing javax.persistence.PersistenceException with Grails 1.0.3. We couldn’t figure out the actual reason, had to make the relationship transient and manually manage it.

6. Changes to taglib g:actionSubmitImage.
The following works fine in Grails 1.0.1.


In Grails 1.0.3, you will need to change to

7. Issues with blank spaces in directories in Windows:
This is the nasty one and can drive you crazy. You may have problems running the app or executing tests. Errors such as java.util.zip.ZipException: The system cannot find the path specified or error trying to scan etc could be noticed. These errors are due to blank spaces in JAVA_HOME(c:\Program Files\..) and user.home (c:\Documents and Settings\..). To fix this:

* Re-install Java in directory without blank spaces (c:\Java\..)
* By default, the project is built in ${user.home}/.grails. We can change this location by specifying the user.home property in command-line such as grails -Duser.home=c:\ run-app or grails -Duser.home=c:\ test-app

Grails 1.0.3 seems much faster than Grails 1.0.1 and is probably worth the trouble.

Hosting Services for Grails Application

Thursday, June 12th, 2008

I was looking for a hosting service for running my Grails and other Spring enabled Java applications. I was looking at both shared and virtual private servers. My Budget was $20.

GoDaddy: I was already using GoDaddy hosting services with Java support for about $7/month. While they claim to support Java applications, in practice it can run only simple ‘Hello World’ applications. They do not allow Spring/Hibernate enabled applications. So, this is not an option.

EATJ: They have a free service that allows you to upload war, restart your Tomcat. (But the server is automatically shutdown every 6 hours). This run Grails application. The Basic service with no server shutdown is $10/month. They offer only 64MB. What can you run with only 64MB? The next level of service offers 128MB and costs $20/month. You can upload your WAR, restart server. Nothing more.

RimuHosting: Offers VPS and runs Grails applications. Costs $20/month for 96MB. Lot of features, good support. I have also read good feedback on their service.

EAPPS: Offers VPS and supports Grails applications. Costs $20/month for 288MB. Tons of features – Tomcat, MySQL, Ruby on Rails, Subversion, Wordpress, ssh/sftp, Apache, mod_jk, mod_proxy, root access etc. I dumped GoDaddy and have been using eapps for last few months. Great customer service.

My recommendation is eapps.

License management plugin for Grails application

Saturday, March 22nd, 2008

I have been recently working on a plugin that provides ability to securely create, install and verify license for closed source grails applications. This plugin utilizes TrueLicense Library Collection (TLC). You can download the plugin here.

Installation

grails install-plugin

Usage

* Generate license file: grails generate-license
* Start app: grails run-app
* Instal/verify license at http://localhost:8080/your_app/license. If you try to access your app without installing license, you will be redirected to this page.

Components

* /plugins/license-0.1/etc/privateKey.store – private key file. This never gets included in your WAR. (You should generate your own private/public keys with keytool command. see tips section below)
* /plugins/license-0.1/etc/LicensePrivateConfig.properties – holds all necessary configuration to create a license such as issuer, holder, validity etc. Again not included in WAR
* /plugins/license-0.1/conf/publicCerts.store – public key file. This is included in WAR
* /plugins/license-0.1/conf/LicensePublicConfig.groovy – holds all necessary information required for the client. Included in WAR
* /plugins/license-0.1/controller/LicenseController – Install, verify license
* /plugins/license-0.1/services/LicenseService – Install, verify license
* /plugins/license-0.1/conf/LicenseFilter – defines which controllers, actions need to be protected.

Tips

* To generate private key:
keytool -genkey -alias privatekey -keystore privateKeys.store
* To generate public key
keytool -export -alias privatekey -file certfile.cer -keystore privateKeys.store
keytool -import -alias publiccert -file certfile.cer -keystore publicCerts.store
* The system preferences are stored in the registry in windows and file system (/etc/.java/) in Linux. You may need appropriate permissions to be able to do this.

Triple boot – Mac OS X, Windows XP & Ubuntu Linux on Intel PC

Monday, November 5th, 2007

Okay! You decided to have three OS on your machine. After experimenting with various procedures, this worked well for me. Here are the steps:

Note: This procedure involves re-partioning your system, hence you would lose your data. Please BACKUP your data before you try any of these.
I. Instal Mac OS X 10.4

* Boot your machine with Mac CD. From the Disk Utilities menu, make 3 partitions. I created partitions with sizes 16GB for Mac, 8GB for Windows and 13GB for Ubuntu.
* Format Mac partition with Mac OS X journaled, Windows partition with NTFS and Linux partition with Linux types.
* Instal Mac OS X on Mac partition.

II. Instal Windows

* Insert windows CD, make sure you select the windows partition.
* Just follow the instructions and complete the installation.

III. Instal Ubuntu Linux

* Restart the machine with Ubuntu Feisty CD.
* Select the linux partition. You may also need to create a 1GB partition for swap
* Follow instructions and complete installation.

Now restart the system. GRUB starts and you will have options to choose Ubuntu and Windows. But where is Mac option? Don’t panic! Log into Ubuntu. Add the following entry to /boot/grub/menu.lst

title Mac OS X (Tiger)
root (hd0,0)
makeactive
chainloader +1

Restart now. Hopefully you now have options to choose all three OS.

Setting Wireless Network in Ubuntu Feisty 7.04

Friday, September 7th, 2007

Recently I installed Ubuntu Feisty 7.04 on my Dell Latitude D600 laptop, but still had to do some work to get wireless working.
For those interested, here are the steps involved:

* Determine your Wireless card.

lspci | grep -i network
02:03.0 Network controller: Broadcom Corporation BCM4306 802.11b/g Wireless LAN Controller (rev 03)
* Disable BCM43XX Driver

sudo -s
echo blacklist bcm43xx >> /etc/modprobe.d/blacklist
exit
* Instal ndiswrapper. This enables wireless network cards on Linux by implementing the Windows kernel and NDIS APIs and dynamically linking the vendor’s Windows drivers

sudo apt-get install ndiswrapper-utils
* Get your windows driver

wget http://ftp.us.dell.com/network/R151517.EXE
* Extract driver to MYDRIVER directory

unzip -a R151517.EXE
* Install the driver

cd MYDRIVER
sudo ndiswrapper -i bcmwl5.inf
* Verify driver, hardware

sudo ndiswrapper -l
* configure ndsiwrapper

sudo ndiswrapper -m
sudo modprobe ndiswrapper
sudo -s
echo ndiswrapper >> /etc/modules
exit

* Reboot now!

* Test wireless

sudo iwlist scanning

If this is your lucky day, you should have your wireless up and ready.

Licence Management for Java Web Applications Using Aspects

Wednesday, December 13th, 2006

This post provides step by setp instruction on implementing license management for Java web applications. I have used open source product TrueLicense for license management and aspects to weave the license verification into the code.

TrueLicense Library Collection(TLC) is a collection of Java packages to securely create, install and verify license for closed source products. TLC is rich in features – License can be perpetual or temporary, bound to users, systems or other entity, free trial period implementation, privacy of license content using password based encryption provided by Java Cryptography Extension (JCE), authenticity of license using digital signature mechanism provided by Java Security API etc.

How to implement License management

What you (Developer) need to do:

1. You already have your web application (say HelloWorld) and you would like to implement License Management. If this is your case, read on.
2. You may want to add a new page for licene management. The client should be able to see the validity of the current license, and instal new license from this page.
3. Write an ascpect to verify license. The pointcut will specify the critical areas of the application. The right approach is to have the licence verification done in every critical functionality of the application. License verification is a ‘cross-cutting’ concern, and hence we can effectively use aspects to weave license verification into our code.
4. Generate private and public key using keytool command.
5. Generate license file. A license file contains encrypted, digitally signed information.
6. Use AspectJ compiler to compile your application.
7. Use a good Code Obfuscator, such as Proguard to guard against Decompilation tools. This is a very important step in real life situtation. If this step is skipped, hackers could exchange your public key and KeyStoreParam implementation with their their own code and bypass the license verification. Since this is a demo app and I’m lazy, this step is skipped. :)
8. Build your application along with the public key.
9. Distribute application and license file to your client. (NEVER give your private key)

What your client needs to do:

1. Pays $$$ and buys your HelloWorld application
2. Fires up the app, navigates to the licenese management page, instals the license file.
3. Uses the app. If the license is expired or not installed, he will not be able to use the application.

Demo Application
The demo application can be used with Tomcat. Download LicenseDemo. Please refer README before using the demo app.

How to use this Demo

1. Unzip HelloWorld-Licensed.zip
2. Run ‘ant clean generateLicense’ from /buildtools folder. This creates a file called sample.lic
3. Run ‘ant clean dist’. This creates HelloWorld-Licensed.war in dist folder.
4. Drop the HelloWorld-Licensed.war file in your webapps folder of Tomcat installation. You are all done!
5. Access the application by http://localhost:8080/HelloWorld-Licensed

First, access the Greetings page without installing license. The error message should be dislayed.
Next, instal sample.lic from the License management page and then access Greetings page. Later, allow the license to expire and access the Greetings page again.

Running multiple JBoss instances on the same machine

Wednesday, August 30th, 2006

Did you ever had the requirement to run multiple JBoss instances on the same machine? Its a trivial task if you exactly know the parameters to be tweaked.

Carryout the following steps with your second instance (This is applicable for JBoss 4.0.3):

* default/deploy/jbossweb-tomcat55.sar/server.xml
o change 8080 to 18080

* default/conf/jboss-service.xml
o change 1099 to 11099
o change 1098 to 11098
o change 4445 to 14445
o change 4444 to 14444

* default/conf/jboss-minimal.xml
o change 1099 to 11099
o change 1098 to 11098

* default/deploy/jms/uil2-service.xml
o change 8093 to 18093

Voila! You’re done!!

Update (04/24/2008):

Many of you requested steps for current release of JBoss 4.2.2 GA, here it goes:

* deploy/jboss-web.deployer/server.xml
o change 8080 to 18080
o change 8443 to 18443
o change 8009 to 18009
* deploy/http-invoker.sar/META-INF/jboss-service.xml
o change 8080 to 18080
* deploy/jbossws.sar/jbossws.beans/META-INF/jboss-beans.xml
o change 8080 to 18080
o change 8443 to 18443
* deploy/ejb3.deployer/META-INF/jboss-service.xml
o change 3873 to 13873
* deploy/jms/uil2-service.xml
o change 8093 to 18093
* conf/jboss-service.xml
o change 8083 to 18083
* conf/jboss-minimal.xml
o change 1099 to 11099
o change 1098 to 11098
* conf/jboss-service.xml
o change 1099 to 11099
o change 1098 to 11098
o change 4444 to 14444
o change 4445 to 14445
o change 4446 to 14446

There can be many entries of these port numbers in these files. Make sure you change all of them.