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 "Deepal Jayasinghe (JIRA)" <ji...@apache.org> on 2005/08/11 09:04:37 UTC

[jira] Resolved: (AXIS2-137) ArchiveReader.creatModuleArchivefromResource(): handling of module archive has problems.

     [ http://issues.apache.org/jira/browse/AXIS2-137?page=all ]
     
Deepal Jayasinghe resolved AXIS2-137:
-------------------------------------

    Fix Version: 0.91
     Resolution: Fixed
      Assign To: Deepal Jayasinghe

Thanks Gopalakrishnan , it was my fault. and I fixed it in the following way

if (axis2repository == null) {
                String userHome = System.getProperty("user.home");
                File userHomedir = new File(userHome);
                File repository = new File(userHomedir, ".axis2home");
                if (!repository.exists()) {
                    repository.mkdirs();
                    modules = new File(repository, "modules");
                    modules.mkdirs();
                } else {
                    modules = new File(repository, "modules");
                    if(!modules.exists()){
                        modules.mkdirs();
                    }
                }
            } else {
                modules = new File(axis2repository, "modules");
                if (!modules.exists()) {
                    modules = new File(axis2repository, "modules");
                    modules.mkdirs();
                }
            }
            String modulearchiveName = moduleName + ".mar";
            modulearchiveFile = new File(modules, modulearchiveName);
            if (modulearchiveFile.exists()) {
                return modulearchiveFile;
            }
//
//            else {
//                modulearchiveFile.createNewFile();
//            }
//
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            InputStream in = cl.getResourceAsStream("modules/" + moduleName + ".mar");
            if (in == null) {
                in = cl.getResourceAsStream("modules/" + moduleName + ".jar");
            }
            if (in == null) {
                throw new DeploymentException(moduleName + " module is not found");
            } else {
                modulearchiveFile.createNewFile();
                FileOutputStream dest = new
                        FileOutputStream(modulearchiveFile);
                ZipOutputStream out = new ZipOutputStream(new
                        BufferedOutputStream(dest));
                byte data[] = new byte[BUFFER];
                ZipInputStream zin = null;
                zin = new ZipInputStream(in);
                ZipEntry entry;
                while ((entry = zin.getNextEntry()) != null) {
                    ZipEntry zip = new ZipEntry(entry);
                    out.putNextEntry(zip);
                    int count;
                    while ((count = zin.read(data, 0, BUFFER)) != -1) {
                        out.write(data, 0, count);
                    }
                }
                out.close();
                zin.close();
            }

        } catch (Exception e) {
            throw new DeploymentException(e);
        }
        return modulearchiveFile;
    }


> ArchiveReader.creatModuleArchivefromResource(): handling of module archive has problems.
> ----------------------------------------------------------------------------------------
>
>          Key: AXIS2-137
>          URL: http://issues.apache.org/jira/browse/AXIS2-137
>      Project: Apache Axis 2.0 (Axis2)
>         Type: Bug
>   Components: deployment
>     Versions: 0.9
>     Reporter: Gopalakrishnan
>     Assignee: Deepal Jayasinghe
>      Fix For: 0.91

>
> There 3 problems in this:
> 1. 
> org.apache.axis2.deployment.repository.util.ArchiveReader.creatModuleArchivefromResource() has this piece of code:
> if(DeploymentEngine.axis2repository == null ){
>                 String userHome = System.getProperty("user.home");
>                 File userHomedir = new File(userHome);
>                 File repository = new File(userHomedir, ".axis2home");
> 184:       if (!repository.exists()) {  ***** 
>                     repository.mkdirs();                
>                     modules = new File(repository, "modules");
>                     modules.mkdirs();
>                 }
> } else {
>         modules = new File(DeploymentEngine.axis2repository, "modules");
>         if (!modules.exists()) {
>           modules = new File(DeploymentEngine.axis2repository, "modules");
>           modules.mkdirs();
>         }
>       }
>       String modulearchiveName = moduleName + ".mar";
> 197:   modulearchiveFile = new File(modules, modulearchiveName);
> So when the repository directory exsists(line 184), the module variable will not be initialized and at Line 197, modules will still be null. So the moduleArchiveFile will point to a file in the users  'current directory' and the .mar file will get extracted in the user's current dir, instead of the userhome/.axis2home/modules dir.
> the code should have been:
>       if (DeploymentEngine.axis2repository == null) {
>         modules = new File(System.getProperty("user.home"), ".axis2home/modules");
>       } else {
>         modules = new File(DeploymentEngine.axis2repository, "modules");
>       }
>       if (!modules.exists())
>         modules.mkdirs();
>       
>       String modulearchiveName = moduleName + ".mar";
>       modulearchiveFile = new File(modules, modulearchiveName);
>  
> 2. 
> Another problem is from 198 - 202
>             if (modulearchiveFile.exists()) {
>                 return modulearchiveFile;
>             } else {
>                 modulearchiveFile.createNewFile();
>             }
> If the module file exsists it returns it otherwise creates a new one. But we are creating the new file too early, what if we are not able to load the module file as resource. This will endup in creating a 0 byte file file in the repository and from next time onwards axis will try to load this 0 byte file and will give a module.xml not found error. We should do  modulearchiveFile.createNewFile(); only after 
>            if(in == null){
>                 throw new DeploymentException( moduleName + " module is not found");
>             }
> succeeds.
> 3. Why are we caching the module archive in the repository dir? This will create problems if I update the .mar file in my distribution(.jar file or .war file). Axis engine will find the old .mar file in the repository and use it, instead of loading the new .mar from the distribution .jar or .war. 
>  

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira