Thursday, March 5, 2009

Log4j Slf4j issues in Spring Dm

If you try to use log4j in any application under Spring DM we may get some ClassNotFound exceptions . The issue could be the following

com.springsource.slf4j.org.apache.log4j-1.5.6.jar - is present in

springsource-dm-server-ee-1.0.2.RELEASE\repository\bundles\ext directory and it shares a package org.apache.log4j

Now when you put your log4j jar into repository\bundles\usr - it also shares the same package
org.apache.log4j .

Hence one in the repository is resolved first . So all requests to classes in the log4j jar within package org/apache/log4j will give ClassNotFound Exceptions as it looks for these classes in slf4j jar .

The easiest way i resolved this was by deleting com.springsource.slf4j.org.apache.log4j-1.5.6.ja from the repository . This change did not affect any logging of the spring Dm server.

Another way to solve this is

Import-Package: org.apache.log4j;bundle-symbolic-name="com.springsource.org.apache.log4j"

http://forum.springsource.org/showthread.php?t=73354

Updating bundle inside a PAR

Currently it is possible to update a bundle within a PAR only through spring tool suite.
This is done through the Deployer MBean - JMX.

This flexibility is not available running a standalone spring Dm server.

May be the future versions of the Spring DM server will support this.

http://forum.springsource.org/showthread.php?t=62293

Tomcat Version In Spring Dm OSGi

Spring DM Server comes with Tomcat 6.0.18, which I believe is the latest one.

You can see the latest version by looking at

DM_SERVER_HOME/repository/bundles/ext/ and

look at Catalina bundles (i.e., com.springsource.org.apache.catalina-6.0.18.jar)

Log4j/Struts Behaviour in OSGi

Log4j/Struts behaves weird if the these jar are put under repository, because this single static instance inside these jars are shared by all other bundles.

Example: Struts(struts properties),log4j(log4/properties)

All the properties are written into static members.Since the single instance is shared by both the bundles applications, the value of static references will be overridden and both the application will use the same settings.

This case is not specific to spring Dm , it will also occur when common configuration object
is put under common lib in tomcat.

Example: log4j/struts jar in tomcat common lib

Struts interceptor code for execution before and after action or result

The code to be executed before and after action class execution needs to be written in the intercept
method of the interceptor.

<code before action invocation>

String result= ActionInvocation(object).invoke();
(By this time the display page is already constructed in memory)

<code after action invocation>

return result

In the above case though the <code after action invocation> will execute it will not be able to modify
the values in the resulting page.

This is beacause the flow is as follows

<Interceptor b4 action> --> Action --> Result Formed(In memory) --> <Interceptor after action>

So the modifications made after the interceptor will only be seen in the next to next pages;

If the interceptor needs to modify the values which is need in the immediate next page
then we need to use

ActionInvocation(object).invokeActionOnly();

this will ensure that the post processing is done before the result object is constructed.Hence ensuring that the
change in the post processing of the interceptor is visible in the next pages

 
Free Domain Names @ .co.nr!