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

run.sh -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.

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

/Library/LaunchDaemons/org.jivesoftware.openfire.plist
/usr/local/openfire
/Library/PreferencePanes/Openfire.prefpan


Your openfire is kicked (uninstall) out of your Mac.
==========OR=============
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
  |  |  |  |  +- MyEntity.java
  |  |  +- resources
  |  |  |  +- META-INF
  |  |  |  |  +- persistence.xml
  |  +- test
  |  |  +- java
  |  |  |  +- mypackage
  |  |  |  |  +- MyPersistenceTest.java
 
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 {
  @Test
  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.getTransaction().begin();
    manager.persist( entity );
    manager.getTransaction().commit();
 
    MyEntity result = ( entity ) manager
      .createQuery("SELECT e FROM MyEntity e WHERE e.attributeOne = :attributeOne")
      .setParameter("attributeOne", attributeOne )
      .getSingleResult();
 
    Assert.assertEquals(firstName, result.getAttributeOne());
    Assert.assertEquals(lastName, result.getAttributeTwo());
 
    manager.close();
    factory.close();
  }
}
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.
======================================================================

============================
POM.XML
============================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>paperless-client-rest-api</groupId>
<artifactId>simple-ws-client-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Simple Client REST Aplis for Java
</description>

<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/
</url>
<layout>default</layout>
</repository>
<repository>
<id>maven-repository.dev.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1
</url>
<layout>legacy</layout>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.1.0-ea</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.1.0-ea</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver
</artifactId>
<version>1.9.9</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<!-- <executable>${env.JAVA_HOME}/bin/javac</executable> -->
<compilerVersion>1.6</compilerVersion>
<fork>true</fork>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project><


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 org.paperless.client.rest.example;

  2. import javax.ws.rs.GET;
  3. import javax.ws.rs.Path;
  4. import javax.ws.rs.PathParam;
  5. import javax.ws.rs.Produces;

  6. /**
  7. * @Author Chiradip Mandal
  8. * @Copyright © Chiradip Mandal 2009
  9. * @License Apache License v2.0 http://www.apache.org/licenses/LICENSE-2.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 org.paperless.client.rest.example;

  2. import java.io.IOException;
  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 http://www.apache.org/licenses/LICENSE-2.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( "com.sun.jersey.config.property.packages", "org.paperless.client.rest.example" );

  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 ) );
  22. System.in.read();
  23. threadSelector.stopEndpoint();
  24. System.exit( 0 );
  25. }
  26. }


Notice Line number 22. initParams.put( "com.sun.jersey.config.property.packages", "org.paperless.client.rest.example" ); 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".

=======================
ENHANCEMENT OF THE ABOVE CODE
=======================

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 HelloWorldResource.java



@GET
@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.


@GET
@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 SimpleDescription.java - 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.


package org.paperless.client.rest.example;

import javax.xml.bind.annotation.XmlRootElement;

/**
* @Author Chiradip Mandal
* @Copyright © Chiradip Mandal 2009
* @License Apache License v2.0 http://www.apache.org/licenses/LICENSE-2.0
*
*/
@XmlRootElement
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.

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

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"
connectionTimeout="20000"
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 http://www.objectengineering.org/bpel.html

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.

Examples
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

Sunday, December 28, 2008

Tuesday, November 25, 2008

Kicking ESB functions out from the box (read container)

Routing and mediation are the important features of ESB and it happens within the container. The ways to communicate and collaborate with outside world (read outside the container) is to have WS interface publishes by a system outside or through different adapters. What can be done for a data collection requirement using ESB? Let me toss a problem; a collection agent - managed by third party proprietary system - collects data, zips it, and stores in a network connected computer in a designated directory. Requirement is to collect the zip files from the designated directory, send to to a processor machine to process the files inside the zip files send the process reports to another central repository and update the database about their URI/URL locations and relationships with collected zips. How can we solve this? how can we fit (?) ESB here? 

Friday, August 8, 2008

JVM level clustering, Network Attached Memory - Terracotta

Off late I have found a good JVM clustering solution with certain degree of tolerable intrusiveness. It can wash away many existing datacentre application if implemented carefully. Period. Has CISCO heard it? Incidentally I am a CISCO employee though in this blog I express my personal opinions only and may or may not be aligned with CISCO vision. Read a tutorial on terracotta at http://frameworkfactory.org/Framework_Factory/Flog/Entries/2009/8/26_Open_source_JVM_Clustering_and_Network_Attached_Memory_using_Terracotta.html

Thursday, July 31, 2008

Servlet 3.0 - A comprehensive study and example

Servlet 3.0 is an overhaul to the ageing servlet technology. The features I liked in the servlet 3.0 are:
- Making web.xml optional, I really dislike handling 'BOILER PLATE' XML while coding. By using declarative style of programming(To java 5/6/7 people this is pretty old now) it is much easier and fun writing a servlet - bootstrappers will like it much. I will just show you one code snippet using servlet 3.0 that just works.

package org.objectengineering.exp.servlet3;
import javax.servlet.http.annotation.*;


@Servlet(urlMappings={"/foo"})
public class MyFirstServlet3 {
}

Thats it. Try it on a servlet 3.0 capable container like jetty 7.0. While writing this post the latest jetty was 7.0.0-pre1. Your servlet writing is over - can't believe ;) - go and deploy it now - you can skip the web.xml part. done.

Greg Wilkins proposal for asynchronous servlet is interesting and I am looking for its adoption by JSR expert commitee. The proposal can be found at http://dist.codehaus.org/jetty/misc/AsyncServlet3.0-draft0.html.

Saturday, July 12, 2008

Spring Integration: the new kid on the block (of ESB?!!)

I just started exploring Spring Intrgration just day after it was released - the version 1.0.0.M5. Here I will share my first impression with Spring Integration followed by subsequent trials and experimentations. Enforcement for speration of concerns without being intrusive is something at the core of Spring philosophy and it is further extended in Spring Integration. Not to be vary theoritical but to communicate some important points about Spring Integration - I am directly copying some excerpts from officila Spring Integration reference; those are goals and principles of Spring Integration.

Goals:
• Provide a simple model for implementing complex enterprise integration solutions.
• Facilitate asynchronous, message-driven behavior within a Spring-based application.
• Promote intuitive, incremental adoption for existing Spring users.

principles:
• Components should be loosely coupled for modularity and testability.
• The framework should enforce separation of concerns between business logic and integration logic.
• Extension points should be abstract in nature but within well-defined boundaries to promote reuse and portability.

Sunday, March 9, 2008

RUP Academy

=== lets make this happening ===