|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -29,47 +29,57 @@ import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* Reflective wrapper around a WebSphere 7 class loader. Used to |
|
|
|
* Reflective wrapper around a WebSphere 7+ class loader. Used to |
|
|
|
* encapsulate the classloader-specific methods (discovered and |
|
|
|
* encapsulate the classloader-specific methods (discovered and |
|
|
|
* called through reflection) from the load-time weaver. |
|
|
|
* called through reflection) from the load-time weaver. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Costin Leau |
|
|
|
* @author Costin Leau |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
* @since 3.1 |
|
|
|
* @since 3.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class WebSphereClassLoaderAdapter { |
|
|
|
class WebSphereClassLoaderAdapter { |
|
|
|
|
|
|
|
|
|
|
|
private static final String COMPOUND_CLASS_LOADER_NAME = "com.ibm.ws.classloader.CompoundClassLoader"; |
|
|
|
private static final String COMPOUND_CLASS_LOADER_NAME = "com.ibm.ws.classloader.CompoundClassLoader"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String CLASS_PRE_PROCESSOR_NAME = "com.ibm.websphere.classloader.ClassLoaderInstancePreDefinePlugin"; |
|
|
|
private static final String CLASS_PRE_PROCESSOR_NAME = "com.ibm.websphere.classloader.ClassLoaderInstancePreDefinePlugin"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PLUGINS_FIELD = "preDefinePlugins"; |
|
|
|
private static final String PLUGINS_FIELD = "preDefinePlugins"; |
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader classLoader; |
|
|
|
private ClassLoader classLoader; |
|
|
|
|
|
|
|
|
|
|
|
private Class<?> wsPreProcessorClass; |
|
|
|
private Class<?> wsPreProcessorClass; |
|
|
|
|
|
|
|
|
|
|
|
private Method addPreDefinePlugin; |
|
|
|
private Method addPreDefinePlugin; |
|
|
|
|
|
|
|
|
|
|
|
private Constructor<? extends ClassLoader> cloneConstructor; |
|
|
|
private Constructor<? extends ClassLoader> cloneConstructor; |
|
|
|
|
|
|
|
|
|
|
|
private Field transformerList; |
|
|
|
private Field transformerList; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public WebSphereClassLoaderAdapter(ClassLoader classLoader) { |
|
|
|
public WebSphereClassLoaderAdapter(ClassLoader classLoader) { |
|
|
|
Class<?> wsCompoundClassLoaderClass = null; |
|
|
|
Class<?> wsCompoundClassLoaderClass; |
|
|
|
try { |
|
|
|
try { |
|
|
|
wsCompoundClassLoaderClass = classLoader.loadClass(COMPOUND_CLASS_LOADER_NAME); |
|
|
|
wsCompoundClassLoaderClass = classLoader.loadClass(COMPOUND_CLASS_LOADER_NAME); |
|
|
|
cloneConstructor = classLoader.getClass().getDeclaredConstructor(wsCompoundClassLoaderClass); |
|
|
|
this.cloneConstructor = classLoader.getClass().getDeclaredConstructor(wsCompoundClassLoaderClass); |
|
|
|
cloneConstructor.setAccessible(true); |
|
|
|
this.cloneConstructor.setAccessible(true); |
|
|
|
|
|
|
|
|
|
|
|
wsPreProcessorClass = classLoader.loadClass(CLASS_PRE_PROCESSOR_NAME); |
|
|
|
this.wsPreProcessorClass = classLoader.loadClass(CLASS_PRE_PROCESSOR_NAME); |
|
|
|
addPreDefinePlugin = classLoader.getClass().getMethod("addPreDefinePlugin", wsPreProcessorClass); |
|
|
|
this.addPreDefinePlugin = classLoader.getClass().getMethod("addPreDefinePlugin", this.wsPreProcessorClass); |
|
|
|
transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD); |
|
|
|
this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD); |
|
|
|
transformerList.setAccessible(true); |
|
|
|
this.transformerList.setAccessible(true); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
"Could not initialize WebSphere LoadTimeWeaver because WebSphere 7 API classes are not available", |
|
|
|
"Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex); |
|
|
|
ex); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
Assert.isInstanceOf(wsCompoundClassLoaderClass, classLoader, |
|
|
|
|
|
|
|
"ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]"); |
|
|
|
|
|
|
|
this.classLoader = classLoader; |
|
|
|
this.classLoader = classLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ClassLoader getClassLoader() { |
|
|
|
public ClassLoader getClassLoader() { |
|
|
|
return this.classLoader; |
|
|
|
return this.classLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -79,9 +89,8 @@ class WebSphereClassLoaderAdapter { |
|
|
|
try { |
|
|
|
try { |
|
|
|
InvocationHandler adapter = new WebSphereClassPreDefinePlugin(transformer); |
|
|
|
InvocationHandler adapter = new WebSphereClassPreDefinePlugin(transformer); |
|
|
|
Object adapterInstance = Proxy.newProxyInstance(this.wsPreProcessorClass.getClassLoader(), |
|
|
|
Object adapterInstance = Proxy.newProxyInstance(this.wsPreProcessorClass.getClassLoader(), |
|
|
|
new Class<?>[] { this.wsPreProcessorClass }, adapter); |
|
|
|
new Class<?>[] {this.wsPreProcessorClass}, adapter); |
|
|
|
this.addPreDefinePlugin.invoke(this.classLoader, adapterInstance); |
|
|
|
this.addPreDefinePlugin.invoke(this.classLoader, adapterInstance); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (InvocationTargetException ex) { |
|
|
|
catch (InvocationTargetException ex) { |
|
|
|
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause()); |
|
|
|
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause()); |
|
|
|
@ -93,9 +102,9 @@ class WebSphereClassLoaderAdapter { |
|
|
|
|
|
|
|
|
|
|
|
public ClassLoader getThrowawayClassLoader() { |
|
|
|
public ClassLoader getThrowawayClassLoader() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
ClassLoader loader = cloneConstructor.newInstance(getClassLoader()); |
|
|
|
ClassLoader loader = this.cloneConstructor.newInstance(getClassLoader()); |
|
|
|
// clear out the transformers (copied as well)
|
|
|
|
// Clear out the transformers (copied as well)
|
|
|
|
List<?> list = (List<?>) transformerList.get(loader); |
|
|
|
List<?> list = (List<?>) this.transformerList.get(loader); |
|
|
|
list.clear(); |
|
|
|
list.clear(); |
|
|
|
return loader; |
|
|
|
return loader; |
|
|
|
} |
|
|
|
} |
|
|
|
|