Friday, April 30, 2010

Inter portlet co-ordination (JSR 286)

Prior to JSR 286, the support for inter portlet communication was rather minimal and information sharing between different portlets was accompalished primarily using application scoped session objects or vendor specific APIs. Both of above methods were rather problematic as in the former maintaining the uniqueness of the session attribute over a complex aaplication was a concern and in the later portability of the portlet was hampered. In order to provide coordination between portlets the Java Portlet Specification v2.0 (JSR 286) introduces the following mechanisms:
  1. public render parameters in order to share render state between portlets.
  2. portlet events that a portlet can receive and send.
Also JSR 286 specifies about Portlet Events..
An example where a portlet may want to offer receiving events is for state changes triggered by simple user interactions, e.g. adding an item to a shopping cart. By offering this as an event to other portlets these can trigger adding items to the shopping cart based on the user interactions happing inside these portlets.

More details here:
http://blog.xebia.com/2009/04/19/inter-portlet-coordination-with-jsr-286/

Wednesday, April 21, 2010

SCRUM

Thursday, March 25, 2010

JDK hidden treasures

Couple of tools we occasionally use but knowing them is useful esp. when we want to peek into JVM.

jps  -List the java process running.
eg: jps -m -l

jvisualvm - Visualize all the VMS running. Seems to be a better option than jconsole. Comes with jdk1.6+ i think
http://java.sun.com/javase/6/docs/technotes/guides/visualvm/intro.html

jconsole -
eg: TODO: remotely manage Mbeans??

jar
eg: jar xvf --to extract, jar cvf -- to create ?

jarsigner  --useful for signing applets.
jstack --??

java  - The jvm ...
javac  - The compiler

javaw  - As far as I know useful to run a process without sticking it to the console which is opening it. eg: javaw eclipse




Friday, March 19, 2010

Good tools for web developers

Must have tools for web developers Xrefresh which works with firebug. Basically you install 2 things , a firefox addon and a system specific xreferesh server. the addon behaves like a client and refreshes the page when you save a html/css/js in your editor Fireshot An excellent plugin to take screenshots and edit them all easily in the plugin.

Thursday, March 18, 2010

Fun with XML on Oracle - XMLTypes

To register a schema in oracle do below:
1. drop directory XMLDIR;
2. create directory XMLDIR as 'C:\';
3. select * from ALL_DIRECTORIES
4.
DBMS_XMLSCHEMA.registerSchema(
SCHEMAURL => 'C:\oracle9i\admin\TEST\utl_file\test.xsd',
SCHEMADOC => bfilename('XMLDIR','test.xsd'),
CSID => nls_charset_id('AL32UTF8'));
5. desc DBMS_XMLSCHEMA confirms that registerSchema exists

Gotchas:
error: ORA-01031: insufficient privileges


Wednesday, March 17, 2010

Clip chain - copy mulitple words at one go!

Clip Chain:
The separator can be changed as often as you'd like while building the text chain—Caps Lock+Esc resets the separator to the default (nothing).

Use the Caps Lock+C shortcut to copy the currently selected text and Caps Lock+V to paste Once the chain has been pasted using Caps Lock+V, the chain is moved to the clipboard and reset.

To paste the chain again, use the standard Ctrl+V shortcut. The chain can also be reset at any time by pressing Caps Lock+Backspace.

More : http://lifehacker.com/5337238/clipchain-copies-multiple-text-strings-for-easy-pasting


Tuesday, March 2, 2010

Playing with load - Jmeter

Scenario:
I want to test http web service using distinct samples as it violates primary key constraints on my database.

The solution:
Java Custom Sampler can be easily configured in jmeter by:
1. Implementing JavaSamplerClient interface.
2. Copy this custom jar into [JMETRE_HOME]/lib/ext . Also any related jars if required!
3. Fire up jmeter client. > Thread Group >Add > Sampler > Java Request ..You should see your custom sampler..

The code is below:
public class CustomServiceSampler implements JavaSamplerClient {
public Arguments getDefaultParameters() {
		Arguments params = new Arguments();
		params.addArgument("SERVICE_URI", DEFAULT_SERVICE_URI);
        params.addArgument("XML_TEMPLATE_PATH", DEFAULT_BRANCH_TEMPLATE_PATH);
        params.addArgument("DATA_ENCODING", DEFAULT_DATA_ENCODING);
		return params;
	}

	@Override
	public SampleResult runTest(JavaSamplerContext context) {
		SampleResult result = new SampleResult();
		
		HttpClient client = new HttpClient();
		String url = context.getParameter("SERVICE_URI", DEFAULT_SERVICE_URI);
		String templatePath= context.getParameter("XML_TEMPLATE_PATH", DEFAULT_BRANCH_TEMPLATE_PATH);
		String contentType= context.getParameter("DATA_ENCODING", DEFAULT_DATA_ENCODING);
		
		PostMethod method = new PostMethod(url);
		method.setRequestHeader("Content-Type", contentType);
		try {
			String template = FileUtils.readFileToString(new File(templatePath));
			String id= (System.currentTimeMillis() + "").substring(0, 10);
			result.setSampleLabel("Post xml- " + id);
			logger.info("Sending POST request to "+url +" with id:"+id);
			String xml = template.replaceAll("\\{ID\\}", branchId);
			xml = xml .replaceAll("\\{DATE\\}", new Date() + "");

			RequestEntity requestEntity = new StringRequestEntity(xml );
			method.setRequestEntity(requestEntity);

			result.setRequestHeaders(ToStringBuilder.reflectionToString(method.getRequestHeaders()));
			result.setSamplerData(xml );
			
			result.sampleStart();
			client.executeMethod(method);
			result.sampleEnd();
			
			String response = new String(method.getResponseBody());
			int code = method.getStatusCode();
			logger.info("Recived response .. status code "+code +" response xml :"+response);
			boolean success= code ==201 ? true:false;
			result.setSuccessful(success);
			result.setResponseData(response);
			result.setResponseCode(code+"");
			result.setResponseMessage(response);
			
			
		} catch (Exception e) {
			logger.error(e,e);
			result.sampleEnd();
			result.setResponseMessage(e.getMessage());
			result.setSuccessful(false);
		}
		return result;
	}
}

References:
http://www.scribd.com/doc/23029283/Using-JMeter-to-Performance-Test-Web-Services

Sunday, February 28, 2010

Google app engine

An interesting read on when big table is better than RDBMS :http://highscalability.com/how-i-learned-stop-worrying-and-love-using-lot-disk-space-scale
An interesting post on full text search is here But its not so reliable.

An attempt to run few web service using spring 3 is here :
http://jshoutbox.appspot.com/




Friday, February 26, 2010

Spring 3 samples

A good collection can be found here : https://src.springsource.org/svn/spring-samples/

Spring 3 with JSON (lib jackson) here
Another useful link : http://springbyexample.org/



Monday, February 22, 2010

linux - the difference between hard and soft links

Follow http://linuxgazette.net/105/pitcher.html By Lew Pitcher Thanks to Lew Pitcher. Very well explained..

Saturday, February 20, 2010

tabbed ms dos/putty console

Are you tired of keeping multiple dos/console tabs open (like me .... :D ..... phew!!)
This is quite useful for programmers I think:
Refer for details:
http://www.downloadsquad.com/2006/07/05/console-tabbed-command-prompt-for-windows

To download an opensource tabbed console(support dos, cygwin,etc) follow :
http://sourceforge.net/projects/console/files/

For remote connecting to linux, there is Putty Connection manager. My favourite.. Maybe console developers can learn from them.


Monday, February 15, 2010

SVNKit - subversion online?

* Pure java implementation of subversion client.

Why it is of interest??
Imagine you want to maintain templates in your subversion as well as make it available to the live web application. There is some effort in creating the template, testing it and then syncing it over to the live application..

If we can get the subversion online then this can be done pretty easily saving the sync effort. Pretty much like a CMS.

Java example API usage  http://svnkit.com/feed/ExamplesList.html
Architecture : http://www.svnkit.com/documentation.html

Maven dependency:
    <dependency>
        <groupId>com.svnkit</groupId>
        <artifactId>svnkit</artifactId>
        <version>1.1.0</version>
    </dependency>




Saturday, February 13, 2010

setting up a static ip with SKY broadband

Setting up a static ip on SKY broadband
  • log into the router
  • Navigate to LAN IP SET UP under advanced settings.
  • Click add under address reservation
  • On the screen that appears choose the device you want to give a fixed IP to
  • Select with the radio button to the left
  • Change the IP if you want/need to
  • Click add
  • Click cancel to return to the main screen
  • Click apply
  • Go to WAN setup and setup this IP (which you want to make public)
  • Go to whatismyip.com to get your public ip..
  • Thats it you got a public IP.
Note: going public will make your PC available to anyone...beware

Thursday, February 11, 2010

Virtualization with sun virtualbox


Windows xp crashed again. Luckily I had the stable ubuntu still running..
Its the nth time its happening. Is there a solution at all for windows sh** .


Well I came across Sun VirtualBox and got windows xp running from Ubuntu in just a few clicks and keystrokes.. The clicks are below:

1. From ubuntu download http://www.virtualbox.org/wiki/Downloads 
2. Install virtualBox
3. From command prompt type in VirtualBox to get the virtual box window.
4.  Follow this video http://www.youtube.com/watch?v=ch8X86R6d-g
5. Put xp cd and create a  new instance of virtualbox.
5. Read this for details : http://www.virtualbox.org/manual/UserManual.html#id2495036
6. Thats it you got windows xp running from Ubuntu..

To share a drive across virtual machines you just have to map the drive.

From your host machine(ubuntu) type in console
$ VBoxManage sharedfolder add "Windows XP" -name "fun" -hostpath "/media/fun"

Then from windows command prompt type net use p: \\vboxsvr\fun
Voila you got your shared drive on p:

Whats more !! have fun with virtualization...
Thanks to this thread http://ubuntuforums.org/showthread.php?t=367155
Still cant get drive access? follow this http://ubuntuforums.org/archive/index.php/t-627847.html

The satan windows can now run under the sane hands of ubuntu...lol



 




spring 2.5.6 performance monitoring

1. update the applicationContext.xml as below:

 <!--  Performance monitoring. Log level should be set to TRACE to monitor the performance.  -->
    <aop:config>
           <aop:advisor pointcut="execution(* com.pkg..*.*(..))" advice-ref="performanceMonitor"/>
    </aop:config>
    <bean id="performanceMonitor" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor"/>

2. Modify log4j.properties as below:
log4j.logger.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE

3. The following pom configuration is necessary
<!-- monitor performance dependencies -->
        <dependency>
          <groupId>aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.5.4</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2</version>
        </dependency>

<!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>2.5.6</version>
        </dependency>

4. You will see the logs as below
TRACE - StopWatch 'com.xyz.dao.procedure.StoredProcedureFactory.getStoredProcedure': running time (millis) = 31
......


Wednesday, February 10, 2010

Spring annotations with spring-mock gotchas

Spring version used: Spring 2.5.6 but spring-mock2.0 (as that's the latest version for mock)

Problem: Junits do not run from dos(when using spring-mock) . Throws  weird exceptions:
java.lang.NoSuchMethodError:springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass(Ljava/lang/Class;Ljava/lang/Class; org.)

The cause: spring-mock 2.0 tries to load spring2.0 jars into classpath screwing up junits run using spring annotations.

Solution:  Tried excluding all the spring-mock dependencies. This should have ideally worked. But I was not able to get it exclude it ...dont know could be a  maven version bug?? Hence had to modify the local pom.xml of spring-mock and removed all spring 2.0 dependencies. Put it into our local maven mirror(archiva).

How did i find this out: By using mvn -X test one can see all the jars loaded in classpath
Details: See a similar problem well explained here




Friday, February 5, 2010

Oracle thin vs OCI(type II/thick) drivers

1. Thin drivers are type 4 and pure java implementations.
Remember to uses classes12.jar instead of ojdbc14 when working with CLOBs.. Or else it throws this
weird exception:
java.sql.SQLException: ORA-00600: internal error code, arguments: [kolaHashFind:hash table], [], [], [], [], [], [], []



2. OCI drivers are thick drivers(type II) and use native libraries to interact with oracle db server.
Usually required when we need to work with XMLType to the oracle db server.


For XMLType its more complicated as it expects xdb.jar and oci jar (ojdbc5.jar i think).

OCI could be a pain:
Check http://myjdbc.tripod.com/basic/jdbcoci.html

I think there could be compatibility issues with OCI esp. as the client driver should match the oracle server version installed. Well that's a guess, will find out and post more here...

The exceptions that were faced with oci driver are below:
java.lang.UnsatisfiedLinkError: no ocijdbc10 in java.library.path >> Guess: must be missing a native dll. does it mean u need a oracle client 10 ?
java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.library.path >> Guess: must be missing a native dll. does it mean u need a oracle client 11 ?
java.lang.NoClassDefFoundError: oracle/jdbc/oci8/OCIDBAccess
java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLParseException
>> occurs when we need to work with XMLType found in xdb.jar which in turn depends on xmlparserv2.jar from oracle...


This is such a pain esp. with cryptic clues what oracle gives.. Oracle DB is good but why are the jdbc clients so bad.. There are so many distributions of oracle driver and the jar names are so confusing..overall we spend lot of time sorting out jdbc drivers of oracle during development i think.. Oracle jdbc folks are u listening....if yes clean up the crap and keep it simple silly...



IMPORTANT:
On different oracle jdbc bundles. Must read:



Tuesday, January 26, 2010

Xpath

XPath uses path expressions to select nodes or node-sets in an XML document.
It contains a library of standard functions and is a major element in XSLT .A W3C recommendation


Several Path Expression Result
//book/title | //book/price Selects all the title AND price elements of all book elements
//title | //price Selects all the title AND price elements in the document
/bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document


Wildcard Path Expression Result
/bookstore/* Selects all the child nodes of the bookstore element
//* Selects all elements in the document
//title[@*] Selects all title elements which have any attribute

Path Expression Result
/bookstore/book[1] Selects the first book element that is the child of the bookstore element.

Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!

/bookstore/book[last()] Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1] Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3] Selects the first two book elements that are children of the bookstore element
//title[@lang] Selects all the title elements that have an attribute named lang
//title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng'
/bookstore/book[price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00
/bookstore/book[price>35.00]/title Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00



Ref:

w3schools
For trying xpath use try me
java xpath http://onjava.com/pub/a/onjava/2005/01/12/xpath.html

Thursday, January 14, 2010

RESTful.........what?

What is REST?
wiki says representational state transfer is a style of software architecture for distributed hypermedia systems..  The constraints described are :
  • Client Server
  • Stateless
  • Cacheable
  • Layered system
  • Code on demand
  • Uniform interface
RESTful web services (aka RESTful web API);
  Comprised of 3 aspects - URI, MIME type supported, operations supported using HTTP methods.

Public implementations : Atom publishing protocol, Suns cloud API etc

Arent all our web applications RESTful then?
So what does it mean for a java developer?
Answers here are quite close
http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/

Everything should be treated as a resouce on the web (not a page). The clear advantage of this is that the same URL can serve content in different formats. Currently most of the sites serve html pages, but they dont work on a mobile or a client expecting xml feeds,etc.

Think of REST as a sentence
• HTTP Methods are verbs
• URIs are nouns
• This grammar is currently being abused by existing websites.

Action implied in the URI
• Implied action conflicts with HTTP method
Conflicting
GET http://addressbook/contacts/destroy/1

Ref:
http://en.wikipedia.org/wiki/Representational_State_Transfer
http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/

Friday, December 25, 2009

The Pareto principle - 80-20 rule

Pareto Principle is the observation (not law) that most things in life are not distributed evenly.
  • 20% of the input creates 80% of the result
  • 20% of the workers produce 80% of the result
  • 20% of the customers create 80% of the revenue
  • 20% of the bugs cause 80% of the crashes
  • 20% of the features cause 80% of the usage
And on and on… References: