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 di...@apache.org on 2003/06/30 19:42:52 UTC

cvs commit: xml-axis/java/src/org/apache/axis/handlers JWSHandler.java

dims        2003/06/30 10:42:52

  Modified:    java/src/org/apache/axis/handlers JWSHandler.java
  Log:
  Possible fix for Bug 17906 - Sample JWS support not working on JBoss 3.06 w/ Jetty
  Possible fix for Bug 20464 - Possible classloader conflict when Axis compile *.jws files within WAS 5.0
  
  Notes:
  - pick up java.class.path
  - pick up and expand java.ext.dirs
  - pick up ws.ext.dirs (Used by websphere)
  
  Revision  Changes    Path
  1.31      +121 -70   xml-axis/java/src/org/apache/axis/handlers/JWSHandler.java
  
  Index: JWSHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/JWSHandler.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- JWSHandler.java	22 Apr 2003 19:34:39 -0000	1.30
  +++ JWSHandler.java	30 Jun 2003 17:42:50 -0000	1.31
  @@ -82,6 +82,7 @@
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.FileFilter;
   import java.net.URL;
   import java.net.URLClassLoader;
   import java.util.HashMap;
  @@ -342,113 +343,156 @@
       private String getDefaultClasspath(MessageContext msgContext)
       {
           StringBuffer classpath = new StringBuffer();
  +
           ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +        fillClassPath(cl, classpath);
   
  -        while(cl != null)
  -        {
  -            if(cl instanceof URLClassLoader)
  -            {
  -                URL[] urls = ((URLClassLoader) cl).getURLs();
  +        // Just to be safe (the above doesn't seem to return the webapp
  +        // classpath in all cases), manually do this:
  +
  +        String webBase = (String)msgContext.getProperty(
  +                                         HTTPConstants.MC_HTTP_SERVLETLOCATION);
  +        if (webBase != null) {
  +            classpath.append(webBase + File.separatorChar + "classes" +
  +                             File.pathSeparatorChar);
  +            try {
  +                String libBase = webBase + File.separatorChar + "lib";
  +                File libDir = new File(libBase);
  +                String [] jarFiles = libDir.list();
  +                for (int i = 0; i < jarFiles.length; i++) {
  +                    String jarFile = jarFiles[i];
  +                    if (jarFile.endsWith(".jar")) {
  +                        classpath.append(libBase +
  +                                         File.separatorChar +
  +                                         jarFile +
  +                                         File.pathSeparatorChar);
  +                    }
  +                }
  +            } catch (Exception e) {
  +                // Oh well.  No big deal.
  +            }
  +        }
  +
  +        String wsClasspath = AxisProperties.getProperty("ws.ext.dirs");
  +        if( wsClasspath  != null) {
  +            classpath.append(wsClasspath);
  +            classpath.append(File.pathSeparatorChar);
  +        }
  +        
  +        String systemClasspath = AxisProperties.getProperty("java.class.path");
  +        if( systemClasspath != null) {
  +            classpath.append(systemClasspath);
  +            classpath.append(File.pathSeparatorChar);
  +        }
  +
  +        String systemExtDirs = AxisProperties.getProperty("java.ext.dirs");
  +        String systemExtClasspath = null;
  +        try {
  +            systemExtClasspath = expandDirs(systemExtDirs);
  +        } catch (Exception e) {
  +            // Oh well.  No big deal.
  +        }
  +        if( systemExtClasspath!= null) {
  +            classpath.append(systemExtClasspath);
  +            classpath.append(File.pathSeparatorChar);
  +        }
  +
  +        // boot classpath isn't found in above search
  +        String bootClassPath = AxisProperties.getProperty("sun.boot.class.path");
  +        if( bootClassPath != null) {
  +            classpath.append(bootClassPath);
  +            classpath.append(File.pathSeparatorChar);
  +        }
  +
  +        return classpath.toString();
  +    }
   
  -                for(int i=0; (urls != null) && i < urls.length; i++)
  -                {
  +    /**
  +     * Walk the classloader hierarchy and add to the classpath
  +     * 
  +     * @param cl
  +     * @param classpath
  +     */
  +    private void fillClassPath(ClassLoader cl, StringBuffer classpath) {
  +        while (cl != null) {
  +            if (cl instanceof URLClassLoader) {
  +                URL[] urls = ((URLClassLoader) cl).getURLs();
  +                for (int i = 0; (urls != null) && i < urls.length; i++) {
                       String path = urls[i].getPath();
                       //If it is a drive letter, adjust accordingly.
  -                    if(path.length() >= 3 && path.charAt(0)=='/' && path.charAt(2)==':')
  +                    if (path.length() >= 3 && path.charAt(0) == '/' && path.charAt(2) == ':')
                           path = path.substring(1);
                       classpath.append(path);
                       classpath.append(File.pathSeparatorChar);
   
                       // if its a jar extract Class-Path entries from manifest
                       File file = new File(urls[i].getFile());
  -                    if(file.isFile())
  -                    {
  +                    if (file.isFile()) {
                           FileInputStream fis = null;
  -
  -                        try
  -                        {
  +                        try {
                               fis = new FileInputStream(file);
   
  -                            if(isJar(fis))
  -                            {
  +                            if (isJar(fis)) {
                                   JarFile jar = new JarFile(file);
                                   Manifest manifest = jar.getManifest();
  -                                if (manifest != null)
  -                                {
  -                                    Attributes attributes = manifest.
  -                                            getMainAttributes();
  -                                    if (attributes != null)
  -                                    {
  -                                        String s = attributes.
  -                           getValue(java.util.jar.Attributes.Name.CLASS_PATH);
  +                                if (manifest != null) {
  +                                    Attributes attributes = manifest.getMainAttributes();
  +                                    if (attributes != null) {
  +                                        String s = attributes.getValue(Attributes.Name.CLASS_PATH);
                                           String base = file.getParent();
   
  -                                        if (s != null)
  -                                        {
  -                                            StringTokenizer st =
  -                                                  new StringTokenizer(s, " ");
  -                                            while(st.hasMoreTokens())
  -                                            {
  +                                        if (s != null) {
  +                                            StringTokenizer st = new StringTokenizer(s, " ");
  +                                            while (st.hasMoreTokens()) {
                                                   String t = st.nextToken();
  -                                                classpath.append(base +
  -                                                      File.separatorChar + t);
  -                                                classpath.append(
  -                                                      File.pathSeparatorChar);
  +                                                classpath.append(base + File.separatorChar + t);
  +                                                classpath.append(File.pathSeparatorChar);
                                               }
                                           }
                                       }
                                   }
                               }
  -                        }
  -                        catch(IOException ioe)
  -                        {
  -                            if(fis != null)
  +                        } catch (IOException ioe) {
  +                            if (fis != null)
                                   try {
                                       fis.close();
  -                                } catch (IOException ioe2) {}
  +                                } catch (IOException ioe2) {
  +                                }
                           }
                       }
                   }
               }
  -
               cl = cl.getParent();
           }
  +    }
   
  -        // Just to be safe (the above doesn't seem to return the webapp
  -        // classpath in all cases), manually do this:
  -
  -        String webBase = (String)msgContext.getProperty(
  -                                         HTTPConstants.MC_HTTP_SERVLETLOCATION);
  -        if (webBase != null) {
  -            classpath.append(webBase + File.separatorChar + "classes" +
  -                             File.pathSeparatorChar);
  -            try {
  -                String libBase = webBase + File.separatorChar + "lib";
  -                File libDir = new File(libBase);
  -                String [] jarFiles = libDir.list();
  -                for (int i = 0; i < jarFiles.length; i++) {
  -                    String jarFile = jarFiles[i];
  -                    if (jarFile.endsWith(".jar")) {
  -                        classpath.append(libBase +
  -                                         File.separatorChar +
  -                                         jarFile +
  -                                         File.pathSeparatorChar);
  -                    }
  +    /**
  +     * Expand a directory path or list of directory paths (File.pathSeparator
  +     * delimited) into a list of file paths of all the jar files in those
  +     * directories.
  +     *
  +     * @param dirPaths The string containing the directory path or list of
  +     * 		directory paths.
  +     * @return The file paths of the jar files in the directories. This is an
  +     *		empty string if no files were found, and is terminated by an
  +     *		additional pathSeparator in all other cases.
  +     */
  +    private String expandDirs(String dirPaths) {
  +        StringTokenizer st = new StringTokenizer(dirPaths, File.pathSeparator);
  +        StringBuffer buffer = new StringBuffer();
  +        while (st.hasMoreTokens()) {
  +            String d = st.nextToken();
  +            File dir = new File(d);
  +            if (dir.isDirectory()) {
  +                File[] files = dir.listFiles(new JavaArchiveFilter());
  +                for (int i = 0; i < files.length; i++) {
  +                    buffer.append(files[i]).append(File.pathSeparator);
                   }
  -            } catch (Exception e) {
  -                // Oh well.  No big deal.
               }
           }
  -
  -        // boot classpath isn't found in above search
  -        String bootClassPath = AxisProperties.getProperty("sun.boot.class.path");
  -        if( bootClassPath != null) {
  -            classpath.append(bootClassPath);
  -        }
  -
  -        return classpath.toString();
  +        return buffer.toString();
       }
  -    
  +
       // an exception or emptiness signifies not a jar
       public static boolean isJar(InputStream is) {
           try {
  @@ -468,6 +512,13 @@
           } catch (Exception e) {
               log.error( Messages.getMessage("exception00"), e );
               throw AxisFault.makeFault(e);
  +        }
  +    }
  +
  +    class JavaArchiveFilter implements FileFilter {
  +        public boolean accept(File file) {
  +            String name = file.getName().toLowerCase();
  +            return (name.endsWith(".jar") || name.endsWith(".zip"));
           }
       }
   }