Saturday, March 7, 2009

After Wisdom Teeth Removal Taste



The title is likely to put it rather unfortunate, which is why I again explain the initial situation a little more detail:

   

Ausganslage


The JBoss (version 4.2.3) is an EAR application (MyApp.ear). Included in her some Libs, an EJB jar file (MyAppEJB.jar) and a web application WAR (MyAppWeb.war) are. The web application knows the EJB jar (in the manifesto published) and communicates with the EJBs using local calls.


working order to keep the user can configure a method within a stateless session bean (SLSB) with a more "normal" configuration class, which is also in MyAppEJB.jar. The helper class called "Config" has a

static method with a configuration file is read. This happened with Using the Apache API Commons Configuration (Configuration configuration = new
PropertiesConfiguration (filePath)
). The configuration file is within MyAppEJB.jar in the directory META-INF (filePath = "META-INF/config.properties)

should (no files are loaded from the file system volume EJB spec or it will not use any classes from java.io be. The file could be in a clustered environment on different nodes look different. After this the file but still not fixed / changed in the EAR or EJB archive is, this is actually wrong. More on this later).

Where does here everything!


Now another web application exists outside of the EARs (The WebApp is a maintenance application that should also be deployed separately). The Maintenance WebApp but also communicate with EJBs in the application described above. Since both applications are on the same server communication takes place via the local interface (JNDI).


problem

   
If, after the server started the maintenance webapp first EJB calls method in turn calls the helper class called "Config" and thus initializes it comes to the following error message:
...
Caused by:
org.apache.commons.configuration.ConfigurationException
: Can not locate configuration source META-INF/config.properties ...


The order is relevant in this case, because the configuration is initialized only when you first access the class. Until one has located the "order problem," it looks stupid as look as if the whole thing goes sometimes, sometimes not ... stupid thing!

background PropertiesConfiguration tried if it will find nowhere else to read the file from the classpath. In this case, the MyAppEJB JAR archive at META-INF, which is so far correctly.


However, as are accessed on a file within a JAR file?


thread.

CurrentThread

(). GetContextClassLoader.getResource (filePath)

And so it makes Apache Common Configuration API .

After it is a local call, the whole call stack is logically the same thread and thus also the

WAR classloader
as

context class loader.


Local access through a Web application within the enterprise archive (EAR)
A call to on MyAppWeb, located within MyApp.ear, it works, the VM searches the classpath for

filePath (= META-INF/config.properties)

. This is always first in

Parent class loader

searched (this occurs recursively). In the following this process in more detail:
The request startup still in the web of MyAppWeb thread (the thread name is for example about: http-127.0.0.1-8080-5, while the WAR classloader is used Name = "WebappClassLoader"). The search is now only in the parent class loader searched recursively:
WAR classloader
à
EJB classloader

à

Application Server class loader
à

system class loader

à Extension Class Loader à
bootstrap class loader

The search therefore begins in the bootstrap class loader - but here is the file "META-INF/config.properties" not found . Play then so on to the EJB class loader. Here, the class loader Resource Search find and return the desired file as a URL.

The configuration can be loaded

!

Local access through an "independent" web application outside of the Enterprise Archives
Here is the same above, at a local call you are in the same thread. The class path is again searched recursively. This looks here like this:

WAR classloader à Application Server Class Loader
à

system class loader

à Extension Class Loader à bootstrap class loader

In any of the searched classloaders resources is the file "META-INF/config.properties" found. The file is indeed in MyAppEJB.jar that will be searched at all here. The configuration

can not be loaded!

Classes "Config" is supported by the AppServer or EJB initialized with its own class loader (

org.jboss.mx.loading.UnifiedClassLoader3 @ 1be513c ). However, the class loader from the current thread ( thread. CurrentThread (). GetContextClassLoader
) is still the WAR class loader (

WebappClassLoader

) is.
Troubleshooting
The problem can be circumvented in several ways:

The Apache Commons Configuration
also provides a way to configure the DB read (
database configuration

) , so that absolutely no configuration in the form of property files is no longer necessary.


The problem can of course also be circumvented, in which one makes sure that the configuration is initialized after the start of the server always

first application of the EAR is
(works, but according to Spec not really clean ...)


The Maintenance application accesses per remote access to the EJBs. This ensures that not the Maintenance thread / class loader tries to load the configuration file.
to initialize PropertiesConfiguration are not you the relative path (META-INF/config.properties) but the same URL within the EJB

Archives

( new PropertiesConfiguration (CONFIG class
. getResource ("/ META-INF/config.properties" ));

)

In this project, I chose the pragmatic approach and opted for the latter variant

0 comments:

Post a Comment