Tuesday, November 16, 2010

Java applet logging

The chances are that you are already using Apache commons logging and log4j in your application. A new challenge is how you do logging for Applet. By that I mean, dumping the output to applet Java console.

Good news is that you don't need to change your code at all. In addition, I think it is overkill to include log4j.properties and log4j.jar as part of client code for Java applet. Without them, commons logging will simply pick default Java logging and it works like a charm.
Log log = LogFactory.getLog(getClass());

The catch is to make sure to use the correct logging level. On the client side, Java logging is defined here. The default logging level is info.
C:\Program Files\Java\jdk1.6.0_20\jre\lib\logging.properties

.level= INFO
So you want to use at least log.info(), instead of log.debug(), to see anything in the Java applet console. Otherwise, the setting has to be changed in logging.properties. It is just not realistic to ask every end user to do it.

Compile options in Ant javac task

Recently I was tasked to migrate a code base from JDK 1.4 to 1.6. As part of this work, I need to take care of deprecated methods and unchecked types in collections. To verify, I turned on the options in ANT javac task as below. Note the use of deprecation="on" and <compilerarg value="-Xlint:unchecked"/>.

        <javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
deprecation="on" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
<compilerarg value="-Xlint:unchecked"/>
</javac>

Monday, November 15, 2010

Create a connection pool to MySQL in OC4J

It is quite easy to create a connection pool/datasource to an Oracle database in OAS EM (Enterprise Manager). You simply do that in OC4J > Administration > JDBC Resources. However, it is not that straight forward to do that with a third party database, in my case, MySQL. Basically, you need to provide mySQL jdbc driver and make sure to use the correct parameters.

This is the obscure part. The creation of connection pool/datasource in EM is via the ascontrol application. So we need to let it know how to load mySQL jdbc driver. There are two steps. Firstly, copy mysql-connector-java-5.1.13-bin.jar to
C:\product\10.1.3.1\OracleAS_1\j2ee\home\applications\ascontrol\ascontrol\WEB-INF\lib. Secondly, edit C:\product\10.1.3.1\OracleAS_1\j2ee\home\applications\ascontrol\META-INF\orion-application.xml and comment out the "remove-inherited" section like below.

   <imported-shared-libraries>
<!--
<remove-inherited name="global.libraries"/>
-->
<import-shared-library name="oracle.xml.security"/>
</imported-shared-libraries>



Everything is pretty straight forward after this. To create a connection pool, remember to use "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" for "Connection Factory Class" and similar to "jdbc:mysql://localhost:3306/test" for "JDBC URL". You can create a datasource the same way after a connection pool is created.

Reference:
http://forums.oracle.com/forums/thread.jspa?threadID=680574