Package org.apache.catalina

Examples of org.apache.catalina.Context


        if (rootContext.exists()) {
            docBase = "ROOT";
        }

        Container[] hosts = engine.findChildren();
        Context defaultContext;
        ObjectName objName = objectName == null ? null : ObjectName.getInstance(objectName);
        for (int i = 0; i < hosts.length; i++) {
            defaultContext = embedded.createContext("", docBase, classLoader);
            if(objName != null) {
                defaultContext.setName(objName.getKeyProperty(NameFactory.J2EE_NAME));
            }
            if (defaultContext instanceof GeronimoStandardContext) {
                GeronimoStandardContext ctx = (GeronimoStandardContext) defaultContext;
                // Without this the Tomcat FallBack Application is left behind,
                // MBean - ...J2EEApplication=none,J2EEServer=none,..........
View Full Code Here


     * @param ctx the context to be added
     * @see org.apache.catalina.startup.Embedded
     * @see org.apache.catalina.Host
     */
    public void addContext(TomcatContext ctx) throws Exception {
        Context anotherCtxObj = embedded.createContext(ctx.getContextPath(), ctx.getDocBase(), ctx.getClassLoader());

        // Set the context for the Tomcat implementation
        ctx.setContext(anotherCtxObj);

        // Have the context to set its properties if its a GeronimoStandardContext
        if (anotherCtxObj instanceof GeronimoStandardContext) {
            ((GeronimoStandardContext) anotherCtxObj).setContextProperties(ctx);
        }
        //Was a virtual server defined?
        String virtualServer = ctx.getVirtualServer();
        if (virtualServer == null) {
            virtualServer = engine.getDefaultHost();
        }
        Container host = engine.findChild(virtualServer);
        if (host == null) {
            throw new IllegalArgumentException("Invalid virtual host '" + virtualServer + "'.  Do you have a matching Host entry in the plan?");
        }

        //Get the security-realm-name if there is one
        String securityRealmName = null;
        SecurityHolder secHolder = ctx.getSecurityHolder();
        if (secHolder != null)
            securityRealmName = secHolder.getSecurityRealm();

        //Did we declare a GBean at the context level?
        if (ctx.getRealm() != null) {
            Realm realm = ctx.getRealm();

            //Allow for the <security-realm-name> override from the
            //geronimo-web.xml file to be used if our Realm is a JAAS type
            if (securityRealmName != null) {
                if (realm instanceof JAASRealm) {
                    ((JAASRealm) realm).setAppName(securityRealmName);
                }
            }
            anotherCtxObj.setRealm(realm);
        } else {
            Realm realm = host.getRealm();
            //Check and see if we have a declared realm name and no match to a parent name
            if (securityRealmName != null) {
                String parentRealmName = null;
                if (realm instanceof JAASRealm) {
                    parentRealmName = ((JAASRealm) realm).getAppName();
                }

                //Do we have a match to a parent?
                if (!securityRealmName.equals(parentRealmName)) {
                    //No...we need to create a default adapter

                    //Is the context requiring JACC?
                    if (secHolder.isSecurity()) {
                        //JACC
                        realm = new TomcatGeronimoRealm();
                    } else {
                        //JAAS
                        realm = new TomcatJAASRealm();
                    }

                    log.debug("The security-realm-name '" + securityRealmName +
                            "' was specified and a parent (Engine/Host) is not named the same or no RealmGBean was configured for this context. " +
                            "Creating a default " + realm.getClass().getName() +
                            " adapter for this context.");

                    ((JAASRealm) realm).setUserClassNames("org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
                    ((JAASRealm) realm).setRoleClassNames("org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
                    ((JAASRealm) realm).setAppName(securityRealmName);

                    anotherCtxObj.setRealm(realm);
                } else {
                    //Use the parent since a name matches
                    anotherCtxObj.setRealm(realm);
                }
            } else {
                anotherCtxObj.setRealm(realm);
            }
        }
       
        // add application listeners to the new context
        if (applicationListeners != null) {
            for (String listener : applicationListeners) {
                anotherCtxObj.addApplicationListener(listener);
            }
        }

        host.addChild(anotherCtxObj);
    }
View Full Code Here

        host.addChild(anotherCtxObj);
    }

    public void removeContext(TomcatContext ctx) {
        Context context = ctx.getContext();

        if (context != null) {
            if (context instanceof GeronimoStandardContext) {
                GeronimoStandardContext stdctx = (GeronimoStandardContext) context;
               
                try {
                    stdctx.kill();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

            }
            context.getParent().removeChild(context);
        }

    }
View Full Code Here

    public void removeConnector(Connector connector) {
        embedded.removeConnector(connector);
    }

    public void addWebService(String contextPath, String[] virtualHosts, WebServiceContainer webServiceContainer, String securityRealmName, String realmName, String transportGuarantee, String authMethod, ClassLoader classLoader) throws Exception {
        Context webServiceContext = embedded.createEJBWebServiceContext(contextPath, webServiceContainer, securityRealmName, realmName, transportGuarantee, authMethod, classLoader);

        String virtualServer;
        if (virtualHosts != null && virtualHosts.length > 0) {
            virtualServer = virtualHosts[0];
        } else {
View Full Code Here

import org.apache.catalina.Request;
import org.apache.catalina.core.StandardHost;

public class WarpHost extends StandardHost {
    public Container map(Request request, boolean update) {
        Context context=null;
        if (Constants.DEBUG) this.log("Mapping request for Host");
        if (request instanceof WarpRequest)
            context=((WarpRequest)request).getContext();
        else
            context=(Context)super.map(request,update);
View Full Code Here

                    this.processUri(logger,request,ruri);
                    if (args.length()>0) request.setQueryString(args);
                    else request.setQueryString(null);
                    request.setProtocol(prot);
                    request.setConnection(connection);
                    Context ctx=connector.applicationContext(id);
                    if (ctx!=null) {
                        request.setContext(ctx);
                        request.setContextPath(ctx.getPath());
                        request.setHost((Host)ctx.getParent());
                    }
                    break;
                }

                case Constants.TYPE_REQ_CONTENT: {
View Full Code Here

                case Constants.TYPE_CONF_DEPLOY: {
                    String appl=packet.readString();
                    String host=packet.readString();
                    int port=packet.readUnsignedShort();
                    String path=packet.readString();
                    Context context=null;
                    packet.reset();

                    if (Constants.DEBUG)
                        logger.log("Deploying web application \""+appl+"\" "+
                                   "under <http://"+host+":"+port+path+">");
                    try {
                        context=deploy(connection,logger,appl,host,path);
                    } catch (Exception e) {
                        logger.log(e);
                    }
                    if (context==null) {
                        String msg="Error deploying web application \""+appl+
                                   "\" under <http://"+host+":"+port+path+">";
                        logger.log(msg);
                        packet.setType(Constants.TYPE_ERROR);
                        packet.writeString(msg);
                        connection.send(packet);
                        break;
                    }
                    int k=connection.getConnector().applicationId(context);
                    packet.setType(Constants.TYPE_CONF_APPLIC);
                    packet.writeInteger(k);
                    packet.writeString(context.getDocBase());
                    connection.send(packet);
                    if (Constants.DEBUG)
                        logger.debug("Application \""+appl+"\" deployed "+
                                     "under <http://"+host+":"+port+path+
                                     "> with root="+context.getDocBase()+
                                     " ID="+k);
                    break;
                }

                case Constants.TYPE_CONF_MAP: {
                    int id=packet.readInteger();
                    Context context=connection.getConnector()
                                    .applicationContext(id);

                    if (context==null) {
                        String msg="Invalid application ID for mappings "+id;
                        logger.log(msg);
                        packet.reset();
                        packet.setType(Constants.TYPE_ERROR);
                        packet.writeString(msg);
                        connection.send(packet);
                        break;
                    }

                    String smap[]=context.findServletMappings();
                    if (smap!=null) {
                        for (int x=0; x<smap.length; x++) {
                            Container c=context.findChild(
                                context.findServletMapping(smap[x]));
                            packet.reset();
                            packet.setType(Constants.TYPE_CONF_MAP_DENY);
                            packet.writeString(smap[x]);

                            if (c instanceof Wrapper) {
                                String servlet=((Wrapper)c).getServletClass();
                                if (DEFAULT_SERVLET.equals(servlet)) {
                                    packet.setType(
                                        Constants.TYPE_CONF_MAP_ALLOW);
                                    if (Constants.DEBUG)
                                        logger.debug("Servlet mapping \""+
                                                     smap[x]+"\" allowed");
                                } else if (Constants.DEBUG) {
                                    logger.debug("Servlet mapping \""+smap[x]+
                                                 "\" denied");
                                }
                            }
                            connection.send(packet);
                        }
                    }

                    FilterMap fmap[]=context.findFilterMaps();
                    if (fmap!=null) {
                        logger.log("Filter mappings ("+fmap.length+")");
                        for (int x=0; x<fmap.length; x++) {
                            String map=fmap[x].getURLPattern();
                            if (map!=null) {
                                if (Constants.DEBUG)
                                    logger.debug("Filter mapping \""+map+
                                                 "\" denied");
                                packet.reset();
                                packet.setType(Constants.TYPE_CONF_MAP_DENY);
                                packet.writeString(map);
                                connection.send(packet);
                            }
                        }
                    }

                    SecurityConstraint scon[]=context.findConstraints();
                    if (scon!=null) {
                        for (int x=0; x<scon.length; x++) {
                            SecurityCollection col[]=scon[x].findCollections();
                            if (col!=null) {
                                for (int y=0; y<col.length; y++) {
View Full Code Here

        // TODO: Set up mapping mechanism for performance

        if (applPath.endsWith("/"))
            applPath=applPath.substring(0,applPath.length()-1);

        Context appl=(Context)host.findChild(applPath);

        if (appl==null) {

            if (Constants.DEBUG)
                logger.debug("No application for \""+applPath+"\"");

            Deployer deployer=(Deployer)host;
            File file=new File(applName);
            if (!file.isAbsolute()) {
                file=new File(host.getAppBase()+File.separator+applName);
                if (!file.isAbsolute()) {
                     file=new File(System.getProperty("catalina.base"),
                                  host.getAppBase()+File.separator+applName);
                }
            }

            if (!file.exists()) {
                logger.log("Cannot find \""+file.getPath()+"\" for appl. \""+
                           applName+"\" host \""+host.getName()+"\"");
                return(null);
            }

            String path=file.getCanonicalPath();
            URL url=new URL("file",null,path);
            if (path.toLowerCase().endsWith(".war"))
                url=new URL("jar:"+url.toString()+"!/");

            if (Constants.DEBUG)
                logger.debug("Application URL \""+url.toString()+"\"");

            deployer.install(applPath, url);
            StandardContext context=null;
            context=(StandardContext)deployer.findDeployedApp(applPath);
            context.setDebug(connection.getConnector().getDebug());
            return(context);
        } else {
            if (Constants.DEBUG)
                logger.debug("Found application for \""+appl.getName()+"\"");
            return(appl);
        }
        }
    }
View Full Code Here

        // Validate the format of the specified argument
        if ((uri == null) || (!uri.startsWith("/")))
            return (null);

        Context child = null;
        try {
            Host host = (Host) context.getParent();
            String mapuri = uri;
            while (true) {
                child = (Context) host.findChild(mapuri);
                if (child != null)
                    break;
                int slash = mapuri.lastIndexOf('/');
                if (slash < 0)
                    break;
                mapuri = mapuri.substring(0, slash);
            }
        } catch (Throwable t) {
            return (null);
        }

        if (child == null)
            return (null);

        if (context.getCrossContext()) {
            // If crossContext is enabled, can always return the context
            return child.getServletContext();
        } else if (child == context) {
            // Can still return the current context
            return context.getServletContext();
        } else {
            // Nothing to return
View Full Code Here

        // Assume this is a configuration descriptor and deploy it
        if(log.isDebugEnabled()) {
            log.debug(sm.getString("hostConfig.deployDescriptor", file));
        }

        Context context = null;
        try {
            synchronized (digester) {
                try {
                    context = (Context) digester.parse(contextXml);
                    if (context == null) {
                        log.error(sm.getString("hostConfig.deployDescriptor.error",
                                file));
                        return;
                    }
                } finally {
                    digester.reset();
                }
            }
            if (context instanceof Lifecycle) {
                Class clazz = Class.forName(host.getConfigClass());
                LifecycleListener listener =
                    (LifecycleListener) clazz.newInstance();
                ((Lifecycle) context).addLifecycleListener(listener);
            }
            context.setConfigFile(contextXml.getAbsolutePath());
            context.setPath(contextPath);
            // Add the associated docBase to the redeployed list if it's a WAR
            boolean isWar = false;
            boolean isExternal = false;
            if (context.getDocBase() != null) {
                File docBase = new File(context.getDocBase());
                if (!docBase.isAbsolute()) {
                    docBase = new File(appBase(), context.getDocBase());
                }
                // If external docBase, register .xml as redeploy first
                if (!docBase.getCanonicalPath().startsWith(appBase().getAbsolutePath())) {
                    isExternal = true;
                    deployedApp.redeployResources.put
                        (contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
                    deployedApp.redeployResources.put(docBase.getAbsolutePath(),
                        new Long(docBase.lastModified()));
                    if (docBase.getAbsolutePath().toLowerCase().endsWith(".war")) {
                        isWar = true;
                    }
                } else {
                    log.warn(sm.getString("hostConfig.deployDescriptor.localDocBaseSpecified",
                             docBase));
                    // Ignore specified docBase
                    context.setDocBase(null);
                }
            }
            host.addChild(context);
            // Get paths for WAR and expanded WAR in appBase
            String name = null;
            String path = context.getPath();
            if (path.equals("")) {
                name = "ROOT";
            } else {
                if (path.startsWith("/")) {
                    name = path.substring(1);
                } else {
                    name = path;
                }
            }
            File expandedDocBase = new File(name);
            File warDocBase = new File(name + ".war");
            if (!expandedDocBase.isAbsolute()) {
                expandedDocBase = new File(appBase(), name);
                warDocBase = new File(appBase(), name + ".war");
            }
            // Add the eventual unpacked WAR and all the resources which will be
            // watched inside it
            if (isWar && unpackWARs) {
                deployedApp.redeployResources.put(expandedDocBase.getAbsolutePath(),
                        new Long(expandedDocBase.lastModified()));
                deployedApp.redeployResources.put
                    (contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
                addWatchedResources(deployedApp, expandedDocBase.getAbsolutePath(), context);
            } else {
                // Find an existing matching war and expanded folder
                if (warDocBase.exists()) {
                    deployedApp.redeployResources.put(warDocBase.getAbsolutePath(),
                            new Long(warDocBase.lastModified()));
                }
                if (expandedDocBase.exists()) {
                    deployedApp.redeployResources.put(expandedDocBase.getAbsolutePath(),
                            new Long(expandedDocBase.lastModified()));
                    addWatchedResources(deployedApp,
                            expandedDocBase.getAbsolutePath(), context);
                } else {
                    addWatchedResources(deployedApp, null, context);
                }
                // Add the context XML to the list of files which should trigger a redeployment
                if (!isExternal) {
                    deployedApp.redeployResources.put
                        (contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
                }
            }
        } catch (Throwable t) {
            log.error(sm.getString("hostConfig.deployDescriptor.error",
                                   file), t);
        }

        if (context != null && host.findChild(context.getName()) != null) {
            deployed.put(contextPath, deployedApp);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.catalina.Context

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.