You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2007/03/22 04:08:40 UTC
svn commit: r521096 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment:
DeploymentClassLoader.java DeploymentEngine.java POJODeployer.java
util/Utils.java
Author: dims
Date: Wed Mar 21 20:08:39 2007
New Revision: 521096
URL: http://svn.apache.org/viewvc?view=rev&rev=521096
Log:
Does this look familiar Deepal? :) Resurrect some old code. Haven't hooked it up yet.
The Groovy aar (with embedded groovy jsr jar) and the Jibx sample in
AXIS2-2343 both work. Will do a bit more testing. We'll have to add a
switch to let user specify the new behavior (where we don't create
temp jars). IMHO, old behavior should be the default for Axis2 1.2.
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java?view=diff&rev=521096&r1=521095&r2=521096
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java Wed Mar 21 20:08:39 2007
@@ -14,16 +14,30 @@
* limitations under the License.
*/
-
package org.apache.axis2.deployment;
-import org.apache.axis2.classloader.JarStreamHandlerFactory;
+import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axis2.classloader.JarFileUrlStreamHandler;
import org.apache.axis2.deployment.util.Utils;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
public class DeploymentClassLoader extends URLClassLoader {
+ // List of URL's
+ private URL[] urls = null;
+
+ // List of jar files inside the jars in the original url
+ private ArrayList embedded_jars;
+
/**
* DeploymentClassLoader is extended from URLClassLoader. The constructor
* does not override the super constructor, but does additional steps like find out
@@ -33,10 +47,191 @@
* @param parent parent classloader <code>ClassLoader</code>
*/
public DeploymentClassLoader(URL[] urls, ClassLoader parent, boolean antiJARLocking) {
- super(Utils.getURLsForAllJars(urls[0], antiJARLocking), parent);
+ super(Utils.getURLsForAllJars(urls[0]), parent);
}
+ /**
+ * Experimental!! Is not hooked up yet.
+ *
+ * @param urls
+ * @param parent
+ */
public DeploymentClassLoader(URL[] urls, ClassLoader parent) {
- super(Utils.getURLsForAllJars(urls[0]), parent, new JarStreamHandlerFactory());
+ super(urls, parent);
+ this.urls = urls;
+ /**
+ * though the URL array can contain one or more urls , we only consider the
+ * first one, since this classLoader is only for Axis2 and the classloader
+ * is created by Deployment, we definitely know that there will be only one url in
+ * the URL array list
+ */
+ embedded_jars = Utils.findLibJars(urls[0]);
+ }
+
+ /**
+ * Finds and loads the class with the specified name from the URL search
+ * path. Any URLs referring to JAR files are loaded and opened as needed
+ * until the class is found.
+ *
+ * @param name the name of the class
+ * @return the resulting class
+ * @exception ClassNotFoundException if the class could not be found
+ */
+ protected Class findClass(String name) throws ClassNotFoundException {
+ Class clazz;
+ boolean foundClass;
+ try {
+ clazz = super.findClass(name);
+ foundClass = true;
+ return clazz;
+ } catch (ClassNotFoundException e) {
+ foundClass = false;
+ }
+ if (!foundClass) {
+ byte raw[];
+ try {
+ String completeFileName = name;
+ /**
+ * Replacing org.apache. -> org/apache/...
+ */
+ completeFileName = completeFileName.replace('.', '/').concat(".class");
+ raw = getBytes(completeFileName);
+ if (raw == null) {
+ throw new ClassNotFoundException("Class Not found : " + name);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ clazz = defineClass(name, raw, 0, raw.length);
+ foundClass = true;
+ return clazz;
+ }
+ if (!foundClass) {
+ throw new ClassNotFoundException("Class Not found : " + name);
+ }
+ return null;
+ }
+
+ /**
+ * Finds the resource with the specified name on the URL search path.
+ *
+ * @param resource the name of the resource
+ * @return a <code>URL</code> for the resource, or <code>null</code>
+ * if the resource could not be found.
+ */
+ public URL findResource(String resource) {
+ URL url = super.findResource(resource);
+ if (url != null) {
+ for (int i = 0; i < embedded_jars.size(); i++) {
+ String libjar_name = (String) embedded_jars.get(i);
+ try {
+ InputStream in = getJarAsStream(libjar_name);
+ ZipInputStream zin = new ZipInputStream(in);
+ ZipEntry entry;
+ String entryName = "";
+ while ((entry = zin.getNextEntry()) != null) {
+ entryName = entry.getName();
+ if (entryName != null &&
+ entryName.endsWith(resource)) {
+ return new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler());
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return url;
+ }
+
+ /**
+ * Returns an Enumeration of URLs representing all of the resources
+ * on the URL search path having the specified name.
+ *
+ * @param resource the resource name
+ * @exception IOException if an I/O exception occurs
+ * @return an <code>Enumeration</code> of <code>URL</code>s
+ */
+ public Enumeration findResources(String resource) throws IOException {
+ ArrayList resources = new ArrayList();
+ Enumeration e = super.findResources(resource);
+ while (e.hasMoreElements()) {
+ resources.add(e.nextElement());
+ }
+ for (int i = 0; i < embedded_jars.size(); i++) {
+ String libjar_name = (String) embedded_jars.get(i);
+ try {
+ InputStream in = getJarAsStream(libjar_name);
+ ZipInputStream zin = new ZipInputStream(in);
+ ZipEntry entry;
+ String entryName = "";
+ while ((entry = zin.getNextEntry()) != null) {
+ entryName = entry.getName();
+ if (entryName != null &&
+ entryName.endsWith(resource)) {
+ resources.add(new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler()));
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ return Collections.enumeration(resources);
+ }
+
+ /**
+ * Access the jars file (/lib) one by one , then for each one create a <code>ZipInputStream</code>
+ * and check to see whether there is any entry eith given name. if it is found then
+ * return the byte array for that
+ *
+ * @param resource <code>String</code> Name of the file to be found
+ * @return byte[]
+ * @throws java.io.IOException <code>Exception</code>
+ */
+ private byte[] getBytes(String resource) throws Exception {
+ for (int i = 0; i < embedded_jars.size(); i++) {
+ String libjar_name = (String) embedded_jars.get(i);
+ InputStream in = getJarAsStream(libjar_name);
+ byte[] bytes = getBytes(in, resource);
+ if(bytes != null) {
+ return bytes;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get a specific entry's content as a byte array
+ *
+ * @param in
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ private byte[] getBytes(InputStream in, String resource) throws Exception {
+ ZipInputStream zin = new ZipInputStream(in);
+ ZipEntry entry;
+ String entryName = "";
+ while ((entry = zin.getNextEntry()) != null) {
+ entryName = entry.getName();
+ if (entryName != null &&
+ entryName.endsWith(resource)) {
+ byte[] raw = IOUtils.getStreamAsByteArray(zin);
+ zin.close();
+ return raw;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the specified embedded jar from the main jar
+ *
+ * @param libjar_name
+ * @return
+ * @throws Exception
+ */
+ private InputStream getJarAsStream(String libjar_name) throws Exception {
+ return new ByteArrayInputStream(getBytes(urls[0].openStream(), libjar_name));
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java?view=diff&rev=521096&r1=521095&r2=521096
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java Wed Mar 21 20:08:39 2007
@@ -198,7 +198,8 @@
DeploymentClassLoader deploymentClassLoader =
new DeploymentClassLoader(
new URL[]{moduleurl},
- axisConfig.getModuleClassLoader());
+ axisConfig.getModuleClassLoader(),
+ false);
AxisModule module = new AxisModule();
module.setModuleClassLoader(deploymentClassLoader);
module.setParent(axisConfig);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java?view=diff&rev=521096&r1=521095&r2=521096
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java Wed Mar 21 20:08:39 2007
@@ -70,7 +70,8 @@
DeploymentClassLoader classLoader =
new DeploymentClassLoader(new URL[]{parentFile.toURL()},
configCtx
- .getAxisConfiguration().getSystemClassLoader());
+ .getAxisConfiguration().getSystemClassLoader(),
+ false);
Thread.currentThread().setContextClassLoader(classLoader);
String className = file.getName();
className = className.replaceAll(".class", "");
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?view=diff&rev=521096&r1=521095&r2=521096
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Wed Mar 21 20:08:39 2007
@@ -117,23 +117,16 @@
}
}
- public static URL[] getURLsForAllJars(URL url, boolean antiJARLocking) {
+ public static URL[] getURLsForAllJars(URL url) {
try {
ArrayList array = new ArrayList();
String urlString = url.toString();
InputStream in = url.openStream();
ZipInputStream zin;
FileInputStream fin = null;
- if (antiJARLocking) {
- File inputFile = createTempFile(urlString.substring(urlString.length() - 4), in);
- in.close();
- array.add(inputFile.toURL());
- fin = new FileInputStream(inputFile);
- zin = new ZipInputStream(fin);
- } else {
array.add(url);
zin = new ZipInputStream(in);
- }
+
ZipEntry entry;
String entryName;
while ((entry = zin.getNextEntry()) != null) {
@@ -150,9 +143,6 @@
}
}
zin.close();
- if (!antiJARLocking) {
- in.close();
- }
if (fin != null) {
fin.close();
}
@@ -162,35 +152,6 @@
}
}
- public static URL[] getURLsForAllJars(URL url) {
- try {
- ArrayList array = new ArrayList();
- String urlString = url.toString();
- InputStream in = url.openStream();
- ZipInputStream zin = new ZipInputStream(in);
-
- array.add(url);
-
- ZipEntry entry;
- String entryName;
- while ((entry = zin.getNextEntry()) != null) {
- entryName = entry.getName();
- /**
- * id the entry name start with /lib and end with .jar
- * then those entry name will be added to the arraylist
- */
- if ((entryName != null) && entryName.toLowerCase().startsWith("lib/")
- && entryName.toLowerCase().endsWith(".jar")) {
- array.add(new URL("jar", "", -1, url.toString() + "!/" + entry.getName()));
- }
- }
- zin.close();
- return (URL[]) array.toArray(new URL[array.size()]);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
public static File createTempFile(String suffix, InputStream in) throws IOException {
byte data[] = new byte[2048];
int count;
@@ -624,5 +585,34 @@
}
}
return filepath;
+ }
+
+ /**
+ * Searches for jar files inside /lib dirctory. If there are any, the
+ * names of those jar files will be added to the array list
+ */
+ public static ArrayList findLibJars(URL url) {
+ ArrayList embedded_jars = new ArrayList();
+ try {
+ ZipInputStream zin = new ZipInputStream(url.openStream());
+ ZipEntry entry;
+ String entryName = "";
+ while ((entry = zin.getNextEntry()) != null) {
+ entryName = entry.getName();
+ /**
+ * if the entry name start with /lib and ends with .jar
+ * add it to the the arraylist
+ */
+ if (entryName != null && (entryName.startsWith("lib/") ||
+ entryName.startsWith("Lib/")) &&
+ entryName.endsWith(".jar")) {
+ embedded_jars.add(entryName);
+ }
+ }
+ zin.close();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return embedded_jars;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org
Re: svn commit: r521096 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment:
DeploymentClassLoader.java DeploymentEngine.java POJODeployer.java util/Utils.java
Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Dims;
Yes
findClass and findResource are familiar to me :) , as I remember correct we had almost similar mechanism at the initial stage. And importantly with your changes we can have a parameter to control child first and parent first scenarios.
(I do agree we need to test some more , Rampart will be a good candidate)
Thanks
dims@apache.org wrote:
>Author: dims
>Date: Wed Mar 21 20:08:39 2007
>New Revision: 521096
>
>URL: http://svn.apache.org/viewvc?view=rev&rev=521096
>Log:
>Does this look familiar Deepal? :) Resurrect some old code. Haven't hooked it up yet.
>The Groovy aar (with embedded groovy jsr jar) and the Jibx sample in
>AXIS2-2343 both work. Will do a bit more testing. We'll have to add a
>switch to let user specify the new behavior (where we don't create
>temp jars). IMHO, old behavior should be the default for Axis2 1.2.
>
>
>Modified:
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java Wed Mar 21 20:08:39 2007
>@@ -14,16 +14,30 @@
> * limitations under the License.
> */
>
>-
> package org.apache.axis2.deployment;
>
>-import org.apache.axis2.classloader.JarStreamHandlerFactory;
>+import org.apache.axiom.attachments.utils.IOUtils;
>+import org.apache.axis2.classloader.JarFileUrlStreamHandler;
> import org.apache.axis2.deployment.util.Utils;
>
>+import java.io.ByteArrayInputStream;
>+import java.io.IOException;
>+import java.io.InputStream;
> import java.net.URL;
> import java.net.URLClassLoader;
>+import java.util.ArrayList;
>+import java.util.Collections;
>+import java.util.Enumeration;
>+import java.util.zip.ZipEntry;
>+import java.util.zip.ZipInputStream;
>
> public class DeploymentClassLoader extends URLClassLoader {
>+ // List of URL's
>+ private URL[] urls = null;
>+
>+ // List of jar files inside the jars in the original url
>+ private ArrayList embedded_jars;
>+
> /**
> * DeploymentClassLoader is extended from URLClassLoader. The constructor
> * does not override the super constructor, but does additional steps like find out
>@@ -33,10 +47,191 @@
> * @param parent parent classloader <code>ClassLoader</code>
> */
> public DeploymentClassLoader(URL[] urls, ClassLoader parent, boolean antiJARLocking) {
>- super(Utils.getURLsForAllJars(urls[0], antiJARLocking), parent);
>+ super(Utils.getURLsForAllJars(urls[0]), parent);
> }
>
>+ /**
>+ * Experimental!! Is not hooked up yet.
>+ *
>+ * @param urls
>+ * @param parent
>+ */
> public DeploymentClassLoader(URL[] urls, ClassLoader parent) {
>- super(Utils.getURLsForAllJars(urls[0]), parent, new JarStreamHandlerFactory());
>+ super(urls, parent);
>+ this.urls = urls;
>+ /**
>+ * though the URL array can contain one or more urls , we only consider the
>+ * first one, since this classLoader is only for Axis2 and the classloader
>+ * is created by Deployment, we definitely know that there will be only one url in
>+ * the URL array list
>+ */
>+ embedded_jars = Utils.findLibJars(urls[0]);
>+ }
>+
>+ /**
>+ * Finds and loads the class with the specified name from the URL search
>+ * path. Any URLs referring to JAR files are loaded and opened as needed
>+ * until the class is found.
>+ *
>+ * @param name the name of the class
>+ * @return the resulting class
>+ * @exception ClassNotFoundException if the class could not be found
>+ */
>+ protected Class findClass(String name) throws ClassNotFoundException {
>+ Class clazz;
>+ boolean foundClass;
>+ try {
>+ clazz = super.findClass(name);
>+ foundClass = true;
>+ return clazz;
>+ } catch (ClassNotFoundException e) {
>+ foundClass = false;
>+ }
>+ if (!foundClass) {
>+ byte raw[];
>+ try {
>+ String completeFileName = name;
>+ /**
>+ * Replacing org.apache. -> org/apache/...
>+ */
>+ completeFileName = completeFileName.replace('.', '/').concat(".class");
>+ raw = getBytes(completeFileName);
>+ if (raw == null) {
>+ throw new ClassNotFoundException("Class Not found : " + name);
>+ }
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ clazz = defineClass(name, raw, 0, raw.length);
>+ foundClass = true;
>+ return clazz;
>+ }
>+ if (!foundClass) {
>+ throw new ClassNotFoundException("Class Not found : " + name);
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Finds the resource with the specified name on the URL search path.
>+ *
>+ * @param resource the name of the resource
>+ * @return a <code>URL</code> for the resource, or <code>null</code>
>+ * if the resource could not be found.
>+ */
>+ public URL findResource(String resource) {
>+ URL url = super.findResource(resource);
>+ if (url != null) {
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ try {
>+ InputStream in = getJarAsStream(libjar_name);
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ return new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler());
>+ }
>+ }
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ }
>+ }
>+ return url;
>+ }
>+
>+ /**
>+ * Returns an Enumeration of URLs representing all of the resources
>+ * on the URL search path having the specified name.
>+ *
>+ * @param resource the resource name
>+ * @exception IOException if an I/O exception occurs
>+ * @return an <code>Enumeration</code> of <code>URL</code>s
>+ */
>+ public Enumeration findResources(String resource) throws IOException {
>+ ArrayList resources = new ArrayList();
>+ Enumeration e = super.findResources(resource);
>+ while (e.hasMoreElements()) {
>+ resources.add(e.nextElement());
>+ }
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ try {
>+ InputStream in = getJarAsStream(libjar_name);
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ resources.add(new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler()));
>+ }
>+ }
>+ } catch (Exception ex) {
>+ throw new RuntimeException(ex);
>+ }
>+ }
>+ return Collections.enumeration(resources);
>+ }
>+
>+ /**
>+ * Access the jars file (/lib) one by one , then for each one create a <code>ZipInputStream</code>
>+ * and check to see whether there is any entry eith given name. if it is found then
>+ * return the byte array for that
>+ *
>+ * @param resource <code>String</code> Name of the file to be found
>+ * @return byte[]
>+ * @throws java.io.IOException <code>Exception</code>
>+ */
>+ private byte[] getBytes(String resource) throws Exception {
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ InputStream in = getJarAsStream(libjar_name);
>+ byte[] bytes = getBytes(in, resource);
>+ if(bytes != null) {
>+ return bytes;
>+ }
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Get a specific entry's content as a byte array
>+ *
>+ * @param in
>+ * @param resource
>+ * @return
>+ * @throws Exception
>+ */
>+ private byte[] getBytes(InputStream in, String resource) throws Exception {
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ byte[] raw = IOUtils.getStreamAsByteArray(zin);
>+ zin.close();
>+ return raw;
>+ }
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Get the specified embedded jar from the main jar
>+ *
>+ * @param libjar_name
>+ * @return
>+ * @throws Exception
>+ */
>+ private InputStream getJarAsStream(String libjar_name) throws Exception {
>+ return new ByteArrayInputStream(getBytes(urls[0].openStream(), libjar_name));
> }
> }
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java Wed Mar 21 20:08:39 2007
>@@ -198,7 +198,8 @@
> DeploymentClassLoader deploymentClassLoader =
> new DeploymentClassLoader(
> new URL[]{moduleurl},
>- axisConfig.getModuleClassLoader());
>+ axisConfig.getModuleClassLoader(),
>+ false);
> AxisModule module = new AxisModule();
> module.setModuleClassLoader(deploymentClassLoader);
> module.setParent(axisConfig);
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java Wed Mar 21 20:08:39 2007
>@@ -70,7 +70,8 @@
> DeploymentClassLoader classLoader =
> new DeploymentClassLoader(new URL[]{parentFile.toURL()},
> configCtx
>- .getAxisConfiguration().getSystemClassLoader());
>+ .getAxisConfiguration().getSystemClassLoader(),
>+ false);
> Thread.currentThread().setContextClassLoader(classLoader);
> String className = file.getName();
> className = className.replaceAll(".class", "");
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Wed Mar 21 20:08:39 2007
>@@ -117,23 +117,16 @@
> }
> }
>
>- public static URL[] getURLsForAllJars(URL url, boolean antiJARLocking) {
>+ public static URL[] getURLsForAllJars(URL url) {
> try {
> ArrayList array = new ArrayList();
> String urlString = url.toString();
> InputStream in = url.openStream();
> ZipInputStream zin;
> FileInputStream fin = null;
>- if (antiJARLocking) {
>- File inputFile = createTempFile(urlString.substring(urlString.length() - 4), in);
>- in.close();
>- array.add(inputFile.toURL());
>- fin = new FileInputStream(inputFile);
>- zin = new ZipInputStream(fin);
>- } else {
> array.add(url);
> zin = new ZipInputStream(in);
>- }
>+
> ZipEntry entry;
> String entryName;
> while ((entry = zin.getNextEntry()) != null) {
>@@ -150,9 +143,6 @@
> }
> }
> zin.close();
>- if (!antiJARLocking) {
>- in.close();
>- }
> if (fin != null) {
> fin.close();
> }
>@@ -162,35 +152,6 @@
> }
> }
>
>- public static URL[] getURLsForAllJars(URL url) {
>- try {
>- ArrayList array = new ArrayList();
>- String urlString = url.toString();
>- InputStream in = url.openStream();
>- ZipInputStream zin = new ZipInputStream(in);
>-
>- array.add(url);
>-
>- ZipEntry entry;
>- String entryName;
>- while ((entry = zin.getNextEntry()) != null) {
>- entryName = entry.getName();
>- /**
>- * id the entry name start with /lib and end with .jar
>- * then those entry name will be added to the arraylist
>- */
>- if ((entryName != null) && entryName.toLowerCase().startsWith("lib/")
>- && entryName.toLowerCase().endsWith(".jar")) {
>- array.add(new URL("jar", "", -1, url.toString() + "!/" + entry.getName()));
>- }
>- }
>- zin.close();
>- return (URL[]) array.toArray(new URL[array.size()]);
>- } catch (Exception e) {
>- throw new RuntimeException(e);
>- }
>- }
>-
> public static File createTempFile(String suffix, InputStream in) throws IOException {
> byte data[] = new byte[2048];
> int count;
>@@ -624,5 +585,34 @@
> }
> }
> return filepath;
>+ }
>+
>+ /**
>+ * Searches for jar files inside /lib dirctory. If there are any, the
>+ * names of those jar files will be added to the array list
>+ */
>+ public static ArrayList findLibJars(URL url) {
>+ ArrayList embedded_jars = new ArrayList();
>+ try {
>+ ZipInputStream zin = new ZipInputStream(url.openStream());
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ /**
>+ * if the entry name start with /lib and ends with .jar
>+ * add it to the the arraylist
>+ */
>+ if (entryName != null && (entryName.startsWith("lib/") ||
>+ entryName.startsWith("Lib/")) &&
>+ entryName.endsWith(".jar")) {
>+ embedded_jars.add(entryName);
>+ }
>+ }
>+ zin.close();
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ return embedded_jars;
> }
> }
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
>For additional commands, e-mail: axis-cvs-help@ws.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org
Re: svn commit: r521096 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment:
DeploymentClassLoader.java DeploymentEngine.java POJODeployer.java util/Utils.java
Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Dims;
Yes
findClass and findResource are familiar to me :) , as I remember correct we had almost similar mechanism at the initial stage. And importantly with your changes we can have a parameter to control child first and parent first scenarios.
(I do agree we need to test some more , Rampart will be a good candidate)
Thanks
dims@apache.org wrote:
>Author: dims
>Date: Wed Mar 21 20:08:39 2007
>New Revision: 521096
>
>URL: http://svn.apache.org/viewvc?view=rev&rev=521096
>Log:
>Does this look familiar Deepal? :) Resurrect some old code. Haven't hooked it up yet.
>The Groovy aar (with embedded groovy jsr jar) and the Jibx sample in
>AXIS2-2343 both work. Will do a bit more testing. We'll have to add a
>switch to let user specify the new behavior (where we don't create
>temp jars). IMHO, old behavior should be the default for Axis2 1.2.
>
>
>Modified:
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
> webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentClassLoader.java Wed Mar 21 20:08:39 2007
>@@ -14,16 +14,30 @@
> * limitations under the License.
> */
>
>-
> package org.apache.axis2.deployment;
>
>-import org.apache.axis2.classloader.JarStreamHandlerFactory;
>+import org.apache.axiom.attachments.utils.IOUtils;
>+import org.apache.axis2.classloader.JarFileUrlStreamHandler;
> import org.apache.axis2.deployment.util.Utils;
>
>+import java.io.ByteArrayInputStream;
>+import java.io.IOException;
>+import java.io.InputStream;
> import java.net.URL;
> import java.net.URLClassLoader;
>+import java.util.ArrayList;
>+import java.util.Collections;
>+import java.util.Enumeration;
>+import java.util.zip.ZipEntry;
>+import java.util.zip.ZipInputStream;
>
> public class DeploymentClassLoader extends URLClassLoader {
>+ // List of URL's
>+ private URL[] urls = null;
>+
>+ // List of jar files inside the jars in the original url
>+ private ArrayList embedded_jars;
>+
> /**
> * DeploymentClassLoader is extended from URLClassLoader. The constructor
> * does not override the super constructor, but does additional steps like find out
>@@ -33,10 +47,191 @@
> * @param parent parent classloader <code>ClassLoader</code>
> */
> public DeploymentClassLoader(URL[] urls, ClassLoader parent, boolean antiJARLocking) {
>- super(Utils.getURLsForAllJars(urls[0], antiJARLocking), parent);
>+ super(Utils.getURLsForAllJars(urls[0]), parent);
> }
>
>+ /**
>+ * Experimental!! Is not hooked up yet.
>+ *
>+ * @param urls
>+ * @param parent
>+ */
> public DeploymentClassLoader(URL[] urls, ClassLoader parent) {
>- super(Utils.getURLsForAllJars(urls[0]), parent, new JarStreamHandlerFactory());
>+ super(urls, parent);
>+ this.urls = urls;
>+ /**
>+ * though the URL array can contain one or more urls , we only consider the
>+ * first one, since this classLoader is only for Axis2 and the classloader
>+ * is created by Deployment, we definitely know that there will be only one url in
>+ * the URL array list
>+ */
>+ embedded_jars = Utils.findLibJars(urls[0]);
>+ }
>+
>+ /**
>+ * Finds and loads the class with the specified name from the URL search
>+ * path. Any URLs referring to JAR files are loaded and opened as needed
>+ * until the class is found.
>+ *
>+ * @param name the name of the class
>+ * @return the resulting class
>+ * @exception ClassNotFoundException if the class could not be found
>+ */
>+ protected Class findClass(String name) throws ClassNotFoundException {
>+ Class clazz;
>+ boolean foundClass;
>+ try {
>+ clazz = super.findClass(name);
>+ foundClass = true;
>+ return clazz;
>+ } catch (ClassNotFoundException e) {
>+ foundClass = false;
>+ }
>+ if (!foundClass) {
>+ byte raw[];
>+ try {
>+ String completeFileName = name;
>+ /**
>+ * Replacing org.apache. -> org/apache/...
>+ */
>+ completeFileName = completeFileName.replace('.', '/').concat(".class");
>+ raw = getBytes(completeFileName);
>+ if (raw == null) {
>+ throw new ClassNotFoundException("Class Not found : " + name);
>+ }
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ clazz = defineClass(name, raw, 0, raw.length);
>+ foundClass = true;
>+ return clazz;
>+ }
>+ if (!foundClass) {
>+ throw new ClassNotFoundException("Class Not found : " + name);
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Finds the resource with the specified name on the URL search path.
>+ *
>+ * @param resource the name of the resource
>+ * @return a <code>URL</code> for the resource, or <code>null</code>
>+ * if the resource could not be found.
>+ */
>+ public URL findResource(String resource) {
>+ URL url = super.findResource(resource);
>+ if (url != null) {
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ try {
>+ InputStream in = getJarAsStream(libjar_name);
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ return new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler());
>+ }
>+ }
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ }
>+ }
>+ return url;
>+ }
>+
>+ /**
>+ * Returns an Enumeration of URLs representing all of the resources
>+ * on the URL search path having the specified name.
>+ *
>+ * @param resource the resource name
>+ * @exception IOException if an I/O exception occurs
>+ * @return an <code>Enumeration</code> of <code>URL</code>s
>+ */
>+ public Enumeration findResources(String resource) throws IOException {
>+ ArrayList resources = new ArrayList();
>+ Enumeration e = super.findResources(resource);
>+ while (e.hasMoreElements()) {
>+ resources.add(e.nextElement());
>+ }
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ try {
>+ InputStream in = getJarAsStream(libjar_name);
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ resources.add(new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new JarFileUrlStreamHandler()));
>+ }
>+ }
>+ } catch (Exception ex) {
>+ throw new RuntimeException(ex);
>+ }
>+ }
>+ return Collections.enumeration(resources);
>+ }
>+
>+ /**
>+ * Access the jars file (/lib) one by one , then for each one create a <code>ZipInputStream</code>
>+ * and check to see whether there is any entry eith given name. if it is found then
>+ * return the byte array for that
>+ *
>+ * @param resource <code>String</code> Name of the file to be found
>+ * @return byte[]
>+ * @throws java.io.IOException <code>Exception</code>
>+ */
>+ private byte[] getBytes(String resource) throws Exception {
>+ for (int i = 0; i < embedded_jars.size(); i++) {
>+ String libjar_name = (String) embedded_jars.get(i);
>+ InputStream in = getJarAsStream(libjar_name);
>+ byte[] bytes = getBytes(in, resource);
>+ if(bytes != null) {
>+ return bytes;
>+ }
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Get a specific entry's content as a byte array
>+ *
>+ * @param in
>+ * @param resource
>+ * @return
>+ * @throws Exception
>+ */
>+ private byte[] getBytes(InputStream in, String resource) throws Exception {
>+ ZipInputStream zin = new ZipInputStream(in);
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ if (entryName != null &&
>+ entryName.endsWith(resource)) {
>+ byte[] raw = IOUtils.getStreamAsByteArray(zin);
>+ zin.close();
>+ return raw;
>+ }
>+ }
>+ return null;
>+ }
>+
>+ /**
>+ * Get the specified embedded jar from the main jar
>+ *
>+ * @param libjar_name
>+ * @return
>+ * @throws Exception
>+ */
>+ private InputStream getJarAsStream(String libjar_name) throws Exception {
>+ return new ByteArrayInputStream(getBytes(urls[0].openStream(), libjar_name));
> }
> }
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java Wed Mar 21 20:08:39 2007
>@@ -198,7 +198,8 @@
> DeploymentClassLoader deploymentClassLoader =
> new DeploymentClassLoader(
> new URL[]{moduleurl},
>- axisConfig.getModuleClassLoader());
>+ axisConfig.getModuleClassLoader(),
>+ false);
> AxisModule module = new AxisModule();
> module.setModuleClassLoader(deploymentClassLoader);
> module.setParent(axisConfig);
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java Wed Mar 21 20:08:39 2007
>@@ -70,7 +70,8 @@
> DeploymentClassLoader classLoader =
> new DeploymentClassLoader(new URL[]{parentFile.toURL()},
> configCtx
>- .getAxisConfiguration().getSystemClassLoader());
>+ .getAxisConfiguration().getSystemClassLoader(),
>+ false);
> Thread.currentThread().setContextClassLoader(classLoader);
> String className = file.getName();
> className = className.replaceAll(".class", "");
>
>Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
>URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?view=diff&rev=521096&r1=521095&r2=521096
>==============================================================================
>--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original)
>+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Wed Mar 21 20:08:39 2007
>@@ -117,23 +117,16 @@
> }
> }
>
>- public static URL[] getURLsForAllJars(URL url, boolean antiJARLocking) {
>+ public static URL[] getURLsForAllJars(URL url) {
> try {
> ArrayList array = new ArrayList();
> String urlString = url.toString();
> InputStream in = url.openStream();
> ZipInputStream zin;
> FileInputStream fin = null;
>- if (antiJARLocking) {
>- File inputFile = createTempFile(urlString.substring(urlString.length() - 4), in);
>- in.close();
>- array.add(inputFile.toURL());
>- fin = new FileInputStream(inputFile);
>- zin = new ZipInputStream(fin);
>- } else {
> array.add(url);
> zin = new ZipInputStream(in);
>- }
>+
> ZipEntry entry;
> String entryName;
> while ((entry = zin.getNextEntry()) != null) {
>@@ -150,9 +143,6 @@
> }
> }
> zin.close();
>- if (!antiJARLocking) {
>- in.close();
>- }
> if (fin != null) {
> fin.close();
> }
>@@ -162,35 +152,6 @@
> }
> }
>
>- public static URL[] getURLsForAllJars(URL url) {
>- try {
>- ArrayList array = new ArrayList();
>- String urlString = url.toString();
>- InputStream in = url.openStream();
>- ZipInputStream zin = new ZipInputStream(in);
>-
>- array.add(url);
>-
>- ZipEntry entry;
>- String entryName;
>- while ((entry = zin.getNextEntry()) != null) {
>- entryName = entry.getName();
>- /**
>- * id the entry name start with /lib and end with .jar
>- * then those entry name will be added to the arraylist
>- */
>- if ((entryName != null) && entryName.toLowerCase().startsWith("lib/")
>- && entryName.toLowerCase().endsWith(".jar")) {
>- array.add(new URL("jar", "", -1, url.toString() + "!/" + entry.getName()));
>- }
>- }
>- zin.close();
>- return (URL[]) array.toArray(new URL[array.size()]);
>- } catch (Exception e) {
>- throw new RuntimeException(e);
>- }
>- }
>-
> public static File createTempFile(String suffix, InputStream in) throws IOException {
> byte data[] = new byte[2048];
> int count;
>@@ -624,5 +585,34 @@
> }
> }
> return filepath;
>+ }
>+
>+ /**
>+ * Searches for jar files inside /lib dirctory. If there are any, the
>+ * names of those jar files will be added to the array list
>+ */
>+ public static ArrayList findLibJars(URL url) {
>+ ArrayList embedded_jars = new ArrayList();
>+ try {
>+ ZipInputStream zin = new ZipInputStream(url.openStream());
>+ ZipEntry entry;
>+ String entryName = "";
>+ while ((entry = zin.getNextEntry()) != null) {
>+ entryName = entry.getName();
>+ /**
>+ * if the entry name start with /lib and ends with .jar
>+ * add it to the the arraylist
>+ */
>+ if (entryName != null && (entryName.startsWith("lib/") ||
>+ entryName.startsWith("Lib/")) &&
>+ entryName.endsWith(".jar")) {
>+ embedded_jars.add(entryName);
>+ }
>+ }
>+ zin.close();
>+ } catch (Exception e) {
>+ throw new RuntimeException(e);
>+ }
>+ return embedded_jars;
> }
> }
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
>For additional commands, e-mail: axis-cvs-help@ws.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org