You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2005/06/26 11:59:33 UTC

svn commit: r201825 - in /webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill: ArchiveFileData.java ArchiveReader.java

Author: deepal
Date: Sat Jun 25 22:03:40 2005
New Revision: 201825

URL: http://svn.apache.org/viewcvs?rev=201825&view=rev
Log:
improved to support jar files inside a service archive file. 

Modified:
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveFileData.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveReader.java

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveFileData.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveFileData.java?rev=201825&r1=201824&r2=201825&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveFileData.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveFileData.java Sat Jun 25 22:03:40 2005
@@ -16,21 +16,18 @@
 
 package org.apache.axis.deployment.repository.utill;
 
+import org.apache.axis.deployment.DeploymentEngine;
+import org.apache.axis.deployment.DeploymentException;
 import org.apache.axis.engine.AxisFault;
-import org.apache.axis.deployment.DeploymentParser;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
+import java.io.*;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
 
 /**
  * ArchiveFileData = Hot Deployment File Item , to store infromation of the module or servise
@@ -45,7 +42,7 @@
     private String moduleClass;
     private String name;
 
-    private ArrayList modules = new ArrayList() ;
+    private ArrayList modules = new ArrayList();
 
 
     public ArchiveFileData(int type, String name) {
@@ -107,49 +104,73 @@
 
     public void setClassLoader() throws AxisFault {
         ClassLoader parent = Thread.currentThread().getContextClassLoader();
+        ArrayList URLs = new ArrayList();
+        boolean tobeRecreated = false;// if there is a jar file inside a jar file then the URLClassLoader
+        // has to be craeted taking that file to the account
         if (file != null) {
             URL[] urlsToLoadFrom = new URL[0];
             try {
                 if (!file.exists()) {
                     throw new RuntimeException("file not found !!!!!!!!!!!!!!!");
                 }
+                URLs.add(file.toURL());
                 urlsToLoadFrom = new URL[]{file.toURL()};
                 classLoader = new URLClassLoader(urlsToLoadFrom, parent);
-                try {
-                    ZipInputStream in = new ZipInputStream(new FileInputStream(file));
-                    ZipEntry entry;
-                    String entryName = "";
-                    while ((entry = in.getNextEntry()) != null) {
-                        entryName = entry.getName();
-                        if(entryName != null && entryName.startsWith("lib/") && entryName.endsWith(".jar")){
-                            ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
-                            URL uuuu = classLoader.getResource(entryName);
-                            parent =
-                                    URLClassLoader.newInstance(new URL[]{uuuu}, prevCl);
-                            try {
-                                //Thread.currentThread().setContextClassLoader(urlCl);
-                            }catch(Exception e){
-                                e.printStackTrace();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            try {
+                ZipInputStream zin = new ZipInputStream(new FileInputStream(file));
+                ZipEntry entry;
+                String entryName = "";
+                int BUFFER = 2048;
+                while ((entry = zin.getNextEntry()) != null) {
+                    entryName = entry.getName();
+                    if (entryName != null && entryName.startsWith("lib/") && entryName.endsWith(".jar")) {
+                        //extarcting jar file form the orignial jar file and copy it to the axis2 lib
+                        File libFile = new File(DeploymentEngine.axis2repository, entryName);
+                        FileOutputStream dest = new FileOutputStream(libFile);
+                        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
+                        byte data[] = new byte[BUFFER];
+                        InputStream in = classLoader.getResourceAsStream(entryName);
+                        ZipInputStream jar_zin = null;
+                        jar_zin = new ZipInputStream(in);
+                        ZipEntry jarentry;
+                        while ((jarentry = jar_zin.getNextEntry()) != null) {
+                            ZipEntry zip = new ZipEntry(jarentry);
+                            out.putNextEntry(zip);
+                            int count;
+                            while ((count = jar_zin.read(data, 0, BUFFER)) != -1) {
+                                out.write(data, 0, count);
                             }
                         }
+                        out.close();
+                        jar_zin.close();
+                        URLs.add(libFile.toURL());
+                        tobeRecreated = true;
                     }
-                    in.close();
-                } catch (IOException e) {
-                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
-            } catch (MalformedURLException e) {
-                throw new AxisFault(e.getMessage(), e);
-            } catch (Exception e) {
-                throw new AxisFault(e.getMessage(), e);
+                zin.close();
+                if (tobeRecreated) {
+                    URL[] urlstobeload = new URL[URLs.size()];
+                    for (int i = 0; i < URLs.size(); i++) {
+                        URL url = (URL) URLs.get(i);
+                        urlstobeload[i] = url;
+                    }
+                    //recreating the classLoader
+                    classLoader = new URLClassLoader(urlstobeload, parent);
+                }
+            } catch (IOException e) {
+                throw new DeploymentException(e);
             }
-        } 
+        }
     }
 
-    public void addModule(QName moduleName){
+    public void addModule(QName moduleName) {
         modules.add(moduleName);
     }
 
-    public ArrayList getModules(){
+    public ArrayList getModules() {
         return modules;
     }
 }

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveReader.java?rev=201825&r1=201824&r2=201825&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveReader.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/deployment/repository/utill/ArchiveReader.java Sat Jun 25 22:03:40 2005
@@ -28,7 +28,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.wsdl.WSDLDescription;
 
-import javax.wsdl.WSDLException;
 import java.io.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -202,7 +201,7 @@
                 in = cl.getResourceAsStream("modules/" + moduleName + ".jar");
             }
             if(in == null){
-                throw new DeploymentException( moduleName + " dose not found");
+                throw new DeploymentException( moduleName + " does not found");
             }
             ZipInputStream zin = null;
             zin = new ZipInputStream(in);