Examples of FileDirContext


Examples of org.apache.naming.resources.FileDirContext

       
        DirContext dirContext;
        URI uri = URI.create(documentRoot);
        if (!"file".equals(uri.getScheme())) {
           
            dirContext = new FileDirContext() {
                @Override
                public Attributes getAttributes(String name) throws NamingException {
                    return new BasicAttributes();
                }
               
                @Override
                public Object lookup(String name) throws NamingException {
                   
                    try {
                        final URL url = new URL(TomcatDefaultServlet.this.documentRoot + name);
                        return new Resource() {
                            @Override
                            public InputStream streamContent() throws IOException {
                                URLConnection connection = url.openConnection();
                                connection.setUseCaches(false);
                                return connection.getInputStream();
                            }
                        };
                    } catch (MalformedURLException e) {
                        throw new NamingException(e.toString());
                    }
                }
            };
           
        } else {
            dirContext = new FileDirContext();
            ((FileDirContext)dirContext).setDocBase(uri.getPath());
        }
        proxyDirContext = new ProxyDirContext(new Hashtable(), dirContext);
        resources = proxyDirContext;           
    }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

            try {
                if ((getDocBase() != null) && (getDocBase().endsWith(".war")) &&
                        (!(new File(getBasePath())).isDirectory()))
                    setResources(new WARDirContext());
                else
                    setResources(new FileDirContext());
            } catch (IllegalArgumentException e) {
                log.error("Error initializing resources: " + e.getMessage());
                ok = false;
            }
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

            {
                if ( !new File( buildOutputDirectory ).exists() )
                {
                    return Collections.emptyList();
                }
                FileDirContext fileDirContext = new FileDirContext();
                fileDirContext.setDocBase( buildOutputDirectory );
                NamingEntry namingEntry = new NamingEntry( "/WEB-INF/classes", fileDirContext, -1 );
                return Collections.singletonList( namingEntry );
            }

            return super.doListBindings( name );
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

                log("Configuring default Resources");
            try {
                if ((docBase != null) && (docBase.endsWith(".war")))
                    setResources(new WARDirContext());
                else
                    setResources(new FileDirContext());
            } catch (IllegalArgumentException e) {
                log("Error initializing resources: " + e.getMessage());
                ok = false;
            }
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

            }
        }

        for (File resourceDirectory : jarResourceRootDirectory.listFiles()) {
            if (resourceDirectory.isDirectory() && resourceDirectory.getName().endsWith(".jar") && resourceDirectory.listFiles().length > 0) {
                FileDirContext fileDirContext = new FileDirContext();
                fileDirContext.setAllowLinking(allowLinking);
                fileDirContext.setDocBase(resourceDirectory.getAbsolutePath());
                altDirContexts.add(fileDirContext);
            }
        }

        //If it is system artifact, or no getRealPath and development stage support is required, just use BundleDirContext
        if (systemArtifact || !(getRealPathSupportRequired || developmentStage)) {
            return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, null);
        }

        File realPathTempDirecotory = new File(tempRootDirectory, "real_path");
        if (refreshmentRequired || ! realPathTempDirecotory.exists()) {
            FileUtils.recursiveDelete(realPathTempDirecotory);
            realPathTempDirecotory.mkdirs();
            ZipInputStream zipIn = null;
            try {
                zipIn = new ZipInputStream(new URL(bundle.getLocation()).openStream());
                ZipEntry entry = null;
                String modulePath = tomcatContext.getModulePath() == null ? "" : tomcatContext.getModulePath();
                while ((entry = zipIn.getNextEntry()) != null) {
                    if(!entry.getName().startsWith(modulePath)){
                        continue;
                    }
                    String subPath = entry.getName().equals(modulePath) ? "" : entry.getName().substring(modulePath.length());
                    if (entry.isDirectory()) {
                        File dir = new File(realPathTempDirecotory, subPath);
                        dir.mkdirs();
                    } else {
                        File file = new File(realPathTempDirecotory, subPath);
                        file.getParentFile().mkdirs();
                        OutputStream out = null;
                        try {
                            out = new BufferedOutputStream(new FileOutputStream(file));
                            IOUtils.copy(zipIn, out);
                            out.flush();
                        } finally {
                            IOUtils.close(out);
                        }
                    }
                }
            } catch (IOException e) {
                checksumFile.delete();
                getLogger().warn("fail to extract the bundle, getRealPath might not work", e);
            } finally {
                IOUtils.close(zipIn);
            }
        }

        if (developmentStage) {
            GeronimoFileDirContext fileDirContext = new GeronimoFileDirContext(altDirContexts);
            fileDirContext.setAllowLinking(allowLinking);
            setDocBase(realPathTempDirecotory.getAbsolutePath());
            return fileDirContext;
        } else {
            return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, realPathTempDirecotory);
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

                log.debug("Configuring default Resources");
            try {
                if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(getBasePath())).isDirectory()))
                    setResources(new WARDirContext());
                else
                    setResources(new FileDirContext());
            } catch (IllegalArgumentException e) {
                log.error("Error initializing resources: " + e.getMessage());
                ok = false;
            }
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

                log.debug("Configuring default Resources");
            try {
                if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(getBasePath())).isDirectory()))
                    setResources(new WARDirContext());
                else
                    setResources(new FileDirContext());
            } catch (IllegalArgumentException e) {
                log.error("Error initializing resources: " + e.getMessage());
                ok = false;
            }
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

                        }
                        jar.nextEntry();
                        entryName = jar.getEntryName();
                    }
                } else if ("file".equals(url.getProtocol())) {
                    FileDirContext fileDirContext = new FileDirContext();
                    fileDirContext.setDocBase(new File(url.toURI()).getAbsolutePath());
                    try {
                        fileDirContext.lookup("META-INF/resources/");
                        //lookup succeeded
                        if(context instanceof StandardContext){
                            ((StandardContext)context).addResourcesDirContext(fileDirContext);
                        }
                    } catch (NamingException e) {
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

                log.debug("Configuring default Resources");
            try {
                if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(getBasePath())).isDirectory()))
                    setResources(new WARDirContext());
                else
                    setResources(new FileDirContext());
            } catch (IllegalArgumentException e) {
                log.error("Error initializing resources: " + e.getMessage());
                ok = false;
            }
        }
View Full Code Here

Examples of org.apache.naming.resources.FileDirContext

        // Add other overlays, if any
        if (ok) {
            for (String overlay : overlays) {
                if (context.getResources() instanceof ProxyDirContext) {
                    ProxyDirContext resources = (ProxyDirContext) context.getResources();
                    FileDirContext dirContext = new FileDirContext();
                    dirContext.setDocBase(overlay);
                    resources.addOverlay(dirContext);
                }
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.