Author: davsclaus
Date: Wed Jul 9 09:15:44 2008
New Revision: 675249
URL: http://svn.apache.org/viewvc?rev=675249&view=rev
Log:
CAMEL-636: WebSphereResolverUtil to load annotated @Converter classes in camel
jars for applications deployed on WebSphere as war files. Damm it was nice to
get this one done - my client is an avid WebSphere fanatic.
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=675249&r1=675248&r2=675249&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
Wed Jul 9 09:15:44 2008
@@ -36,6 +36,7 @@
import org.apache.camel.TypeConverter;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ResolverUtil;
+import org.apache.camel.util.WebSphereResolverUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,6 +53,14 @@
private ResolverUtil resolver = new ResolverUtil();
private Set<Class> visitedClasses = new HashSet<Class>();
+ public AnnotationTypeConverterLoader() {
+ // use WebSphere specific resolver if running on WebSphere
+ if
(WebSphereResolverUtil.isWebSphereClassLoader(this.getClass().getClassLoader()))
{
+ LOG.info("Using WebSphere specific ResolverUtil");
+ resolver = new WebSphereResolverUtil();
+ }
+ }
+
public void load(TypeConverterRegistry registry) throws Exception {
String[] packageNames = findPackageNames();
resolver.findAnnotated(Converter.class, packageNames);
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?rev=675249&r1=675248&r2=675249&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
Wed Jul 9 09:15:44 2008
@@ -76,7 +76,7 @@
* @author Tim Fennell
*/
public class ResolverUtil<T> {
- private static final transient Log LOG =
LogFactory.getLog(ResolverUtil.class);
+ protected static final transient Log LOG =
LogFactory.getLog(ResolverUtil.class);
/**
* A simple interface that specifies how to test classes to determine if
@@ -299,7 +299,10 @@
Enumeration<URL> urls;
try {
- urls = loader.getResources(packageName);
+ urls = getResources(loader, packageName);
+ if (!urls.hasMoreElements()) {
+ LOG.trace("No URLs returned by classloader");
+ }
} catch (IOException ioe) {
LOG.warn("Could not read package: " + packageName, ioe);
return;
@@ -348,6 +351,24 @@
}
}
+ /**
+ * Strategy to get the resources by the given classloader.
+ * <p/>
+ * Notice that in WebSphere platforms there is a [EMAIL PROTECTED]
org.apache.camel.util.WebSphereResolverUtil}
+ * to take care of WebSphere's odditiy of resource loading.
+ *
+ * @param loader the classloader
+ * @param packageName the packagename for the package to load
+ * @return URL's for the given package
+ * @throws IOException is thrown by the classloader
+ */
+ protected Enumeration<URL> getResources(ClassLoader loader, String
packageName) throws IOException {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Getting resource URL for package: " + packageName + "
with classloader: " + loader);
+ }
+ return loader.getResources(packageName);
+ }
+
private void loadImplementationsInBundle(Test test, String packageName,
ClassLoader loader, Method mth) {
// Use an inner class to avoid a NoClassDefFoundError when used in a
non-osgi env
Set<String> urls = OsgiUtil.getImplementationsInBundle(test,
packageName, loader, mth);
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java?rev=675249&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
Wed Jul 9 09:15:44 2008
@@ -0,0 +1,56 @@
+package org.apache.camel.util;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+import java.io.IOException;
+
+import org.apache.camel.impl.converter.AnnotationTypeConverterLoader;
+
+/**
+ * WebSphere specific resolver util to handle loading annotated resources in
JAR files.
+ */
+public class WebSphereResolverUtil extends ResolverUtil {
+
+ /**
+ * Is the classloader from IBM and thus the WebSphere platform?
+ *
+ * @param loader the classloader
+ * @return <tt>true</tt> if IBM classloader, <tt>false</tt> otherwise.
+ */
+ public static boolean isWebSphereClassLoader(ClassLoader loader) {
+ return loader.getClass().getName().startsWith("com.ibm");
+ }
+
+ /**
+ * Overloaded to handle specific problem with getting resources on the IBM
WebSphere platform.
+ * <p/>
+ * WebSphere can <b>not</b> load resources if the resource to load is a
folder name, such as a
+ * packagename, you have to explicit name a resource that is a file.
+ *
+ * @param loader the classloader
+ * @param packageName the packagename for the package to load
+ * @return URL's for the given package
+ * @throws IOException is thrown by the classloader
+ */
+ @Override
+ protected Enumeration<URL> getResources(ClassLoader loader, String
packageName) throws IOException {
+ // try super first, just in vase
+ Enumeration<URL> enumeration = super.getResources(loader, packageName);
+ if (! enumeration.hasMoreElements()) {
+ LOG.trace("Using WebSphere workaround to load the camel jars with
the annotated converters.");
+ // Special WebSphere trick to load a file that exists in the JAR
and then let it go from there.
+ // The trick is that we just need the URL's for the .jars that
contains the type
+ // converters that is annotated. So by searching for this resource
WebSphere is able to find
+ // it and return the URL to the .jar file with the resource. Then
the default ResolverUtil
+ // can take it from there and find the classes that are annotated.
+ enumeration =
loader.getResources(AnnotationTypeConverterLoader.META_INF_SERVICES);
+ }
+
+ return enumeration;
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date