Package org.openqa.jetty.util

Examples of org.openqa.jetty.util.Resource


import org.openqa.jetty.util.Resource;

public class ClasspathResourceLocator implements ResourceLocator {

    public Resource getResource(HttpContext context, String pathInContext) throws IOException {
        Resource resource = new ClassPathResource(pathInContext);
        context.getResourceMetaData(resource);
        return resource;
    }
View Full Code Here


    {
        String sessionId = getSessionId(pathInContext);
        if (sessionId != null) {
            String extensionJs = FrameGroupCommandQueueSet
                .getQueueSet(sessionId).getExtensionJs();
            Resource resource = new SessionExtensionJsResource(extensionJs);
            getHttpContext().getResourceMetaData(resource);
            return resource;
        }
        return null;
    }
View Full Code Here

        if (!resource.isDirectory())
            return null;

        for (int i=0;i<_welcomes.length;i++)
        {
            Resource welcome=resource.addPath(_welcomes[i]);
            if (welcome.exists())
                return _welcomes[i];
        }

        return null;
    }
View Full Code Here

                URL[] urls = ((URLClassLoader)loader).getURLs();
                for (int j=0;urls!=null && j<urls.length;j++)
                {
                    try
                    {
                        Resource path = Resource.newResource(urls[j]);
                        if (log.isTraceEnabled()) log.trace("path "+path);
                        File file = path.getFile();
                        if (file!=null)
                            paths.add(file.getAbsolutePath());
                    }
                    catch(Exception e)
                    {
View Full Code Here

        {
            String[] files=lib.list();
            for (int f=0;files!=null && f<files.length;f++)
            {
                try {
                    Resource fn=lib.addPath(files[f]);
                    String fnlc=fn.getName().toLowerCase();
                    if (fnlc.endsWith(".jar") || fnlc.endsWith(".zip"))
                    {
                        addClassPath(fn.toString());
                    }
                }
                catch (Exception ex)
                {
                    log.warn(LogSupport.EXCEPTION,ex);
View Full Code Here

        throws IOException
    {
        _config=config;
        if(log.isDebugEnabled())log.debug("Load "+this+" from "+config);
        Properties properties = new Properties();
        Resource resource=Resource.newResource(config);
        properties.load(resource.getInputStream());

        Iterator iter = properties.entrySet().iterator();
        while(iter.hasNext())
        {
            Map.Entry entry = (Map.Entry)iter.next();
View Full Code Here

            // Is the WAR usable directly?
            if (_webApp.exists() && !_webApp.isDirectory() && !_webApp.toString().startsWith("jar:"))
            {
                // No - then lets see if it can be turned into a jar URL.
                Resource jarWebApp= Resource.newResource("jar:" + _webApp + "!/");
                if (jarWebApp.exists() && jarWebApp.isDirectory())
                {
                    _webApp= jarWebApp;
                    _war= _webApp.toString();
                    if (log.isDebugEnabled())
                        log.debug(
                            "Try webapp="
                                + _webApp
                                + ", exists="
                                + _webApp.exists()
                                + ", directory="
                                + _webApp.isDirectory());
                }
            }

            // If we should extract or the URL is still not usable
            if (_webApp.exists()
                && (!_webApp.isDirectory()
                    || (_extract && _webApp.getFile() == null)
                    || (_extract && _webApp.getFile() != null && !_webApp.getFile().isDirectory())))
            {
                // Then extract it.
                File tempDir= new File(getTempDirectory(), "webapp");
                if (tempDir.exists())
                    tempDir.delete();
                tempDir.mkdir();
                tempDir.deleteOnExit();
                log.info("Extract " + _war + " to " + tempDir);
                JarResource.extract(_webApp, tempDir, true);
                _webApp= Resource.newResource(tempDir.getCanonicalPath());

                if (log.isDebugEnabled())
                    log.debug(
                        "Try webapp="
                            + _webApp
                            + ", exists="
                            + _webApp.exists()
                            + ", directory="
                            + _webApp.isDirectory());
            }

            // Now do we have something usable?
            if (!_webApp.exists() || !_webApp.isDirectory())
            {
                log.warn("Web application not found " + _war);
                throw new java.io.FileNotFoundException(_war);
            }

            if (log.isDebugEnabled())
                log.debug("webapp=" + _webApp);

            // Iw there a WEB-INF directory?
            _webInf= _webApp.addPath("WEB-INF/");
            if (!_webInf.exists() || !_webInf.isDirectory())
                _webInf= null;
            else
            {
                // Is there a WEB-INF work directory
                Resource work= _webInf.addPath("work");
                if (work.exists()
                    && work.isDirectory()
                    && work.getFile() != null
                    && work.getFile().canWrite()
                    && getAttribute("javax.servlet.context.tempdir") == null)
                    setAttribute("javax.servlet.context.tempdir", work.getFile());
            }

            // ResourcePath
            super.setBaseResource(_webApp);
        }
View Full Code Here

    /* ------------------------------------------------------------ */
    public Resource getResource(String uriInContext) throws IOException
    {
        IOException ioe= null;
        Resource resource= null;
        try
        {
            resource= super.getResource(uriInContext);
            if (resource != null && resource.exists())
                return resource;
        }
        catch (IOException e)
        {
            ioe= e;
View Full Code Here

     */
    public void loadConfig(String config)
        throws IOException
    {
        Properties properties = new Properties();
        Resource resource=Resource.newResource(config);
        properties.load(resource.getInputStream());
       
        _jdbcDriver = properties.getProperty("jdbcdriver");
        _url = properties.getProperty("url");
        _userName = properties.getProperty("username");
        _password = properties.getProperty("password");
View Full Code Here

                       String pathParams,
                       HttpRequest request,
                       HttpResponse response)
        throws HttpException, IOException
    {
        Resource resource = getResource(pathInContext);
        if (resource==null)
            return;

        // Is the method allowed?
        if (!isMethodAllowed(request.getMethod()))
        {
            if(log.isDebugEnabled())log.debug("Method not allowed: "+request.getMethod());
            if (resource.exists())
            {
                setAllowHeader(response);
                response.sendError(HttpResponse.__405_Method_Not_Allowed);
            }
            return;
        }

        // Handle the request
        try
        {
            if(log.isDebugEnabled())log.debug("PATH="+pathInContext+" RESOURCE="+resource);
           
            // check filename
            String method=request.getMethod();
            if (method.equals(HttpRequest.__GET) ||
                method.equals(HttpRequest.__POST) ||
                method.equals(HttpRequest.__HEAD))
                handleGet(request, response, pathInContext, pathParams, resource)
            else if (method.equals(HttpRequest.__PUT))
                handlePut(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__DELETE))
                handleDelete(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__OPTIONS))
                handleOptions(response, pathInContext);
            else if (method.equals(HttpRequest.__MOVE))
                handleMove(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__TRACE))
                handleTrace(request, response);
            else
            {
                if(log.isDebugEnabled())log.debug("Unknown action:"+method);
                // anything else...
                try{
                    if (resource.exists())
                        response.sendError(HttpResponse.__501_Not_Implemented);
                }
                catch(Exception e) {LogSupport.ignore(log,e);}
            }
        }
        catch(IllegalArgumentException e)
        {
            LogSupport.ignore(log,e);
        }
        finally
        {
            if (resource!=null && !(resource instanceof CachedResource))
                resource.release();
        }
    }
View Full Code Here

TOP

Related Classes of org.openqa.jetty.util.Resource

Copyright © 2018 www.massapicom. 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.