Friday, November 20, 2009

Terracotta quick tutorial

I think the quickest way to grasp the concept and get started using Terracotta. Find it here Terracotta quick start

Spring 3 file upload

I could not find a consolidated and everything works kind of Spring fileupload example using Spring 2.5.x or 3.x. I have written tested and uploaded it here. Framework Factory blog on Spring 2.5/ Spring 3 Fileupload

Monday, November 2, 2009

increasing tomcat JVM heap size

    export CATALINA_OPTS="-Xms16m -Xmx256m"

Tuesday, October 27, 2009

running multiple instances of jboss -Djboss.service.binding.set=ports-01

Friday, August 21, 2009

Openfire 3.6.4 on mac - admin console login issue SOLUTION

I installed Openfire 3.6.4 on my mac and ran into admin console login problem without any 'google' solution. Do not know whether this is a mac only problem. Simply I was not able to log in using the password I provided during set up. Re-setup as suggested by others did not help. The solution ultimately I traded is to switch embedded database to mysql (other non embedded will work too). In order to switch from embedded to mysql I reinstalled open fire but it can be done by re-setup too and is discussed later in this post. Uninstalling is tricky and can be done in this way.

Uninstalling openfire on Mac.
Remove the files/folders listed below


Your openfire is kicked (uninstall) out of your Mac.
Resetup can be done in this way.
open /usr/local/openfire/conf/openfire.xml

Change the line (hopefully last but one line) true to false
==========END EITHER/OR=======
Then open the admin console at http://localhost:9090/index.jsp or you can do it in Mac way by opening openfire in System Preference and click on "Open Admin Console".

Follow the instructions in the admin console. Select mysql (or oracle or something else other than embedded one) as the database. Provide all the required info make sure you create the database that you specify and credentials are correct. Complete the setup. I was not able to log in using the password I have provided for admin during setup. No worry. Go to terminal and run
mysql -u -p and use the database for that used by openfire. Execute this sql command update ofuser set plainpassword = 'admin123' where username = 'admin'; use password of your choice. Done. Restart openfire from "Openfire" System Preference (you will find an entry 'Openfire' in System Preference) by clicking 'Stop Openfire' button and then 'Start Openfire'. Login to admin console using the changed (in database) password with user name 'admin. Fin.

Thursday, June 11, 2009

Handy command to see whether a class file exists in your lib/dir

$find ~chiradip/.m2/repository/ -name *.jar -exec jar tvf {} \; egrep 'Spring'
Another command that does the similar thing
$for line in `ls *.jar`; do echo $line; jar tvf $line egrep 'Spring'; done

Running JPA test cases in Maven

First thing first. The directory structure should look like this.
  +- pom.xml
  +- src
  |  +- main
  |  |  +- java
  |  |  |  +- mypackage
  |  |  |  |  +-
  |  |  +- resources
  |  |  |  +- META-INF
  |  |  |  |  +- persistence.xml
  |  +- test
  |  |  +- java
  |  |  |  +- mypackage
  |  |  |  |  +-
second thing second ;)
package mypackage;
import org.junit.Assert;
import org.junit.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class MyPersistenceTest {
  public void testBasicPersistence() throws Exception {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("myunitname");
    EntityManager manager = factory.createEntityManager();
    String attributeOne = "AttributeOne";
    String attributeTwo = "AttributeTwo";
    MyEntity entity = new MyEntity();
    entity.setAttributeOne( attributeOne );
    entity.setAttributeTwo( attributeTwo );
    manager.persist( entity );
    MyEntity result = ( entity ) manager
      .createQuery("SELECT e FROM MyEntity e WHERE e.attributeOne = :attributeOne")
      .setParameter("attributeOne", attributeOne )
    Assert.assertEquals(firstName, result.getAttributeOne());
    Assert.assertEquals(lastName, result.getAttributeTwo());
Third thing. Make sure all the dependencies are in the pom like JPA, hibernate, or db pool (c3p0 kind of).
Thats it.
Regards, Chiradip

Friday, May 8, 2009

Jersey on embedded grizzly (another tomcat like server) and then on tomcat 6

<< It is about JAX-RS - JSR 311. Simply getting up and running with restful webservices quickly> >
<<remember running it on tomcat 5.x is a bit different> >
First thing first. Lets write the application first. To show the dependencies the library versions that worked for me is listed below in the form of POM file.

For NON MAVEN USERS: Do not worry about the pom content just look at the dependencies to get the jar files with right versions and this also says that my dev environment is Java 6 but it should work well with Java 5. You may skip the pom if you wish.

<?xml version="1.0" encoding="UTF-8"?>
<description>Simple Client REST Aplis for Java

<name> Repository for Maven</name>
<name> Maven 1 Repository (legacy)</name>


<!-- <executable>${env.JAVA_HOME}/bin/javac</executable> -->

We will have only 2 files to start with a basic and a good and a complete sample
CODE: The resource class - this class will decide what you get once you access the specific URI. The uri here is /helloworld on the server root. e.g. if your server runs on localhost:9998 then the resource will be accessible at http://localhost:9998/helloworld. If you open http://localhost:9998/helloworld on your browser you will see the message helloworld - of course you have to implement the service - it is just one block away.

  1. package;

  2. import;
  3. import;
  4. import;
  5. import;

  6. /**
  7. * @Author Chiradip Mandal
  8. * @Copyright © Chiradip Mandal 2009
  9. * @License Apache License v2.0
  10. *
  11. */
  12. // The Java class will be hosted at the URI path "/helloworld"
  13. @Path( "/helloworld" )
  14. public class HelloWorldResource {

  15. // The Java method will process HTTP GET requests
  16. @GET
  17. // The Java method will produce content identified by the MIME Media
  18. // type "text/plain"
  19. @Produces( "text/plain" )
  20. public String getMessage() {
  21. return "Hello World";
  22. }
  23. }
CODE: The RESTful service goes below. It uses the resource (HelloWorldResource).

  1. package;

  2. import;
  3. import java.util.HashMap;
  4. import java.util.Map;

  5. import com.sun.grizzly.http.SelectorThread;
  6. import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;

  7. /**
  8. * @Author Chiradip Mandal
  9. * @Copyright © Chiradip Mandal 2009
  10. * @License Apache License v2.0
  11. *
  12. */
  13. public class Main {
  14. public static void main( String[] args ) throws IOException {

  15. final String baseUri = "http://localhost:9998/";
  16. final Map<> initParams = new HashMap<>();

  17. initParams.put( "", "" );

  18. System.out.println( "Starting grizzly..." );
  19. SelectorThread threadSelector = GrizzlyWebContainerFactory.create( baseUri, initParams );
  20. System.out.println( String.format( "Jersey app started with WADL available at %sapplication.wadl\n"
  21. + "Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri ) );
  23. threadSelector.stopEndpoint();
  24. System.exit( 0 );
  25. }
  26. }

Notice Line number 22. initParams.put( "", "" ); The second part of this line is crucial. This the name of the package where all the resource (classes) will be available, either directly or under subpackage of this package.

Guess what? Just run the the above java and point your browser at http://localhost:9998/helloworld and voila you see the message appears on you browser "Hello World".


This is pretty static code. Lets add some dynamism here. Lets say if we access http://localhost:9998/helloworld/print/{myname} - substitute {myname} by your actual name - and we get our name printed on the browser or the caller http client.

Lets add the following lines in

@Produces( "text/plain" )
@Path( "print/{myname}" )
public String getTestReply( @PathParam( "myname" ) String name ) {
return "Your name: " + name;

One more thing is done. Lets jump into the next thing - returning a java object. Trick is here - at the server side we can return an object but at the browser or httpclient side java object does not make sense but XML does. Lets see how we can return a java object at the server side to get an XML at the client.

@Produces( "application/xml" )
@Path( "desc" )
public SimpleDescrption getDescription() {
SimpleDescrption desc = new SimpleDescrption();
desc.setMyDescOne( "My Description One" );
desc.setMyDescTwo( "My Description Two" );
return desc;

You guessed it right. If you access browser http://localhost:9998/helloworld/desc and you will see an XML appearing on your browser or curl or any httpclient.

One thing is left the - it is simple just follow me below. It's a simple bean except it is marked as @XMLRootElement and thats it. Remember this marking is must to get this working.


import javax.xml.bind.annotation.XmlRootElement;

* @Author Chiradip Mandal
* @Copyright © Chiradip Mandal 2009
* @License Apache License v2.0
public class SimpleDescrption {
private String myDescOne;
private String myDescTwo;

public void setMyDescOne( String myDescOne ) {
this.myDescOne = myDescOne;

public String getMyDescOne() {
return myDescOne;

public void setMyDescTwo( String myDescTwo ) {
this.myDescTwo = myDescTwo;

public String getMyDescTwo() {
return myDescTwo;

Use your favorite browser (I dont use my favorite browser for this as safari is bad in handling XML output ;) ). The output in firefox is as below.

<myDescOne>My Description One</myDescOne>
<myDescTwo>My Description Two</myDescTwo>

Tuesday, May 5, 2009

Running 2 tomcats on a single machine

Very simple thing but very important and needed many a times. The simple to follow steps.
1) Download tomcat and unpack it in 2 different directories. Lets say /sfw/tomcat1 and /sfw/tomcat2 or if it is windows c:\sfw\tomcat1 and c:\sfw\tomcat2.
2) Edit the conf/server.xml file in both the tomcat installations and make sure the ports are different. For example if tomcat1 has the following config snippet -

<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectport="8443">

Then tomcat2 should have something like
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8081" protocol="HTTP/1.1" connectiontimeout="20000" redirectport="8444">
<Connector port="8010" protocol="AJP/1.3" redirectport="8444">

Thats it for the basic config.

Simple BPEL Tutorial

Here is the link for the article

Spring Framework tutorial

Here goes the link of my article Spring Framework tutorial

Thursday, March 19, 2009

SUN - up for sale

This is inevitable that SUN is looking for selling itself as consecutively 4 quarters they reported loss. I wish I could buy SUN ;) It has huge assets used and unused and lots of stuffs that another company may take decades and billions to recreate. IBM is preying on SUN. I am calling it preying as IBM has that bad boy attitude to acquire and kill the way they did with Rational likes. As a SUN admirer I do not wish to see IBM buying SUN. My solely personal opinion is - CISCO should buy it. I am a CISCO employee incidentally but this is my solely personal opinion. What benefits CISCO may get out this buy out and what we SUN admirers may get.
1) CISCO is foraying into server market - if CISCO buys SUN, CISCO can use SUN's mature server ranges along with legendary Solaris. Data center will be sexier than ever with all CISCO+SUN products.
2) Virtualization - CISCO needs it and working on it but in my opinion CISCO will take decade to reach what SUN has already reached if at all it reaches there.
3) Software development legacy - SUN has sound software development legacy and CISCO can not afford to sale only hardware so this can be inherited from SUN.
4) Intellectual Properties - do I need to say anything here!!
5) Love - through Solaris and then mighty Java, SUN acquired huge number of lovers worldwide. CISCO may get that love by buying SUN.
6) Benefit we (SUN admirers) get - IBM would kill SUN's philosophy if it buys it. CISCO I believe will not, rather will allow SUN to grow on its own and leverage the SUN's deeds and we will still get the SUN flavors undistorted.
7) CISCO has strong sales force with very good connections to governments and big industries worldwide. This would play a pivotal role to lift SUN sales up fueling its growth and continuing the R&D thats at the heart of SUN philosophy.

If it has to be sold out SUN should consider selling it to CISCO. If at all they can not afford selling it to Chiradip ;)

Tuesday, March 17, 2009

Soft hardware ;)

Software products are getting complex everyday in terms of setting up, configuration, operation and maintenance. What if working on software gives us the feel of working like a well packaged hardware like iPod?

What is my definition of soft hardware?
1) Of the shelf usable.
2) Works with my laptop or desktop or server just upon connecting them.
3) No installation of software and no configuration for general use.

1) An integrated development environment with 1 or 2 test servers integrated with it (think of websphere integration developer - if you are aware). It is pain to install manage and work daily mainly due to the configuration. Now if that can be obtained in a USB stick and you just have to connect it with your computer and you are all set to go, you can do whatever you want. Not working! just remove the media and start afresh.
2) Pre configured webserver on a card