Archive

Archive for August, 2009

Spring – Oracle Connection Pool Configuration

August 27, 2009 5 comments

Problem Statement: Configure Oracle Connection Pool in Spring

This is basic data source (Only testing)

<bean id="datasource1"
 class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
         <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
<property name="url">
         <value>ORACLE URL</value>
    </property>
<property name="username">
         <value>user id</value>
    </property>
<property name="password">
         <value>user password</value>
    </property>
</bean>

This is dbcp data source (Preferred for Testing.)

<bean id="datasource2"
 class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
         <value>org.apache.commons.dbcp.BasicDataSource</value>
    </property>
<property name="url">
         <value>ORACLE URL</value>
    </property>
<property name="username">
         <value>user id</value>
    </property>
<property name="password">
         <value>user password</value>
    </property>
<property name="initialSize" value="5"/>
<property name="maxActive" value="20"/>
</bean>

This is Oracle Connection Pool (Production Quality)


<bean id="connectionPool1" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL">
         <value>ORACLE URL</value>
    </property>
<property name="user">
         <value>user id</value>
    </property>
<property name="password">
         <value>user password</value>
    </property>
<property name="connectionCacheProperties">
      <value>
		MinLimit:1
		MaxLimit:5
		InitialLimit:1
		ConnectionWaitTimeout:120
		InactivityTimeout:180
		ValidateConnection:true
      </value>
   </property>
</bean>

Oracle Connection Pool is better than DBCP and C3P0
http://www.lambdaprobe.org/d/oracle.shtml

-o-

OSGi issues – Converting Big Jar (100+ Dependency jars) to Bundle

August 26, 2009 Leave a comment

Problem Statement: There is a project with around 100+ third party jar files. How can we convert this spring project X jar to OSGi X Bundle? It is painful process.

We have two approaches.
1. Convert all third party jars to bundles. (few are available on public repositories, few we need to package manually. This is painful process)
2. Make one big X Bundle by embedding all jars in its lib folder. Make is work. Slowly push out jars as bundles. This is also painful process

Failed to achieve success in both ways. Spring DM is giving problems with XML parsers in between and lot of other issues.

Final Solution: Prepare Big X Bundle by embedding all jars. Dont depend on Spring DM to expose services. We need to do on our own using API.

This code is working

private static void loadBeanFactory(BundleContext context) {
		try {
			OsgiBundleXmlApplicationContext applicationContext = new OsgiBundleXmlApplicationContext(
					new String[] { "/META-INF/abcd-context.xml" });
			applicationContext.setPublishContextAsService(false);
			applicationContext.setBundleContext(context);
			applicationContext.refresh();

			SuperMessage dataProcessor = (SuperMessage) applicationContext.getBean("messageBean");
			System.out.println("message from bean:==>"
					+ dataProcessor.getMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

Quick Check: Call printClassPath from activator and see what is there in classpath.

public static void printClassPath() {
		System.out.println("------------ printClassPath Begin ------------");
		// Get the System Classloader
		ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();

		// Get the URLs
		URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();

		for (int i = 0; i " + urls[i].getFile());
		}
		System.out.println("------------ printClassPath End ------------");
	}

The following code never works in OSGi. Because OSGi wont expose jar, file resources. We never get those files on classpath.

private void loadBeanFactory1() {
		try {
			XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(
					"Test-context.xml"));
			SuperMessage dataProcessor = (SuperMessage) factory
					.getBean("messageBean");
			System.out.println("message from bean:==>"
					+ dataProcessor.getMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	private void loadBeanFactory2() {
		try {
			String[] configFiles = new String[] { "META-INF/Test-context.xml" };
			ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext(
					configFiles);

			SuperMessage dataProcessor = (SuperMessage) factory
					.getBean("messageBean");
			System.out.println("message from bean:==>"
					+ dataProcessor.getMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	private static void loadBeanFactory3() {
		try {
			GenericApplicationContext ctx = new GenericApplicationContext();
			ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(
					ctx);
			scanner
					.scan(new String[] { "org.apache.felix.example.servicebased.circle.DefaultMessage" });
			ctx.refresh();

			SuperMessage dataProcessor = (SuperMessage) ctx
					.getBean("messageBean");
			System.out.println("message from bean:==>"
					+ dataProcessor.getMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	private static void loadBeanFactory4() {
		try {
			GenericApplicationContext ctx = new GenericApplicationContext();

			XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
			xmlReader.loadBeanDefinitions(new ClassPathResource(
					"META-INF/Test-context.xml"));
			// PropertiesBeanDefinitionReader propReader = new
			// PropertiesBeanDefinitionReader(ctx);
			// propReader.loadBeanDefinitions(new
			// ClassPathResource("otherBeans.properties"));
			ctx.refresh();

			SuperMessage dataProcessor = (SuperMessage) ctx
					.getBean("messageBean");
			System.out.println("message from bean:==>"
					+ dataProcessor.getMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

-o-
Please share your ideas.

Categories: OSGi

OSGi Bundle Repositories

August 19, 2009 Leave a comment
Categories: OSGi Tags:

Distributing Java Swing Application

August 18, 2009 Leave a comment

Soon I need to distribute Java Swing Application. As part of this process here is my notes.

For distributor
Step 1: Identify least version required for the application.

Step 2: Compile and build self executable Jar. (Do code obfuscation if required.)
JSmooth is good to convert jar to exe. http://jsmooth.sourceforge.net/

Step 3: Distribute executable Jar.
1. Give Jar, so user can run in system.
2. Give source, so user can build his own jar.
3. Provide Java Webstart using JNLP. (We need to have server instance to run this.)
4. Convert jar to .exe and provide. (still issues with viruses)

For Users:

Step 1: Check java version in system.

Step 2: If system dont have required version, update to required version using sun site.

Step 3: Double Click on Jar and start using application.

-o-
Links:
What version of Java we are using: http://www.javatester.org/version.html

-o-

MySQL – Pain with port 3306 error message

August 15, 2009 Leave a comment

While trying to setup MySQL 5.x on windows getting following error.
Running zone alarm. Later frustrated with Zone Alarm Free Edition and moved to comodo fire wall. It looks good and having many options to configure.

Problem:

Error Nr. 1045…. Please make sure you have opened the TCP port 3306.

mysql port 3306 error

Solution: Port 3306 is opened. Still getting error
solution

First first time setup dont enter root password. This is causing problem and mysql is giving wrong error message.

-o-

Problem 2: MySQL Browser is wrong name. It permits to do database schema creation, table creation, enter data in editable grid and similar. But Coming from MySQL CC to this environment is painful. Also it is little bit confusing for first few minutes.

Default user name is: root
mysql admin

Default Schema is : test
mysql browser

To edit data in grid, we need to do following steps
Step 1:
mysql enter data - Step 1

Step 2:
mysql enter data - Step 2

Now ready to play with MySQL….

-o-

OSGi – Felix / Spring DM / Logging / Environment Variables

August 7, 2009 Leave a comment

>pax-run “–platform=felix” “–log=DEBUG” “–profiles=spring.dm”
Using standard felix is painful. We need to identify and install all spring dm files.
This way we need not to do anything. Pax runner starts felix with log level debug and installs all spring dm files.

-o-

How to set environment variables in OSGi?

http://felix.apache.org/site/apache-felix-configuration-admin-service.html

https://opensource.luminis.net/wiki/display/SITE/OSGi+Configuration+Admin+command+line+client

-o-

OSGi – is Fun to play, difficult to work on big projects

August 5, 2009 Leave a comment

Today I am frustrated with OSGi Technology….Somebody got great idea….they released half cooked tools and software into market. Somebody likes the idea and simply say go and use it…without doing proper analysis. OSGi is good for project that is having very few jars (bundles) and they should available on spring source. Otherwise life is screwed up in stitching bundles and respective versions. Soon it will become great technology…it becomes like butterfly….for now it is caterpillar …looks ugly and difficult to appreciate…

If you have 100+ jars to be bundles, then you can realize the pain behind it.

Categories: OSGi
Follow

Get every new post delivered to your Inbox.