Search in sources :

Example 71 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class JDBCStore method getName.

/**
 * Return the name for this instance (built from container name)
 */
public String getName() {
    if (name == null) {
        Container container = manager.getContainer();
        String contextName = container.getName();
        String hostName = "";
        String engineName = "";
        if (container.getParent() != null) {
            Container host = container.getParent();
            hostName = host.getName();
            if (host.getParent() != null) {
                engineName = host.getParent().getName();
            }
        }
        name = "/" + engineName + "/" + hostName + contextName;
    }
    return name;
}
Also used : Container(org.apache.catalina.Container)

Example 72 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class JDBCStore method load.

/**
 * Load the Session associated with the id <code>id</code>.
 * If no such session is found <code>null</code> is returned.
 *
 * @param id a value of type <code>String</code>
 * @return the stored <code>Session</code>
 * @exception ClassNotFoundException if an error occurs
 * @exception IOException if an input/output error occurred
 */
public Session load(String id) throws ClassNotFoundException, IOException {
    ResultSet rst = null;
    StandardSession _session = null;
    Loader loader = null;
    ClassLoader classLoader = null;
    ObjectInputStream ois = null;
    BufferedInputStream bis = null;
    Container container = manager.getContainer();
    String loadSql = "SELECT " + sessionIdCol + ", " + sessionDataCol + " FROM " + sessionTable + " WHERE " + sessionIdCol + " = ? AND " + sessionAppCol + " = ?";
    synchronized (this) {
        Connection _conn = getConnection();
        if (_conn == null) {
            return (null);
        }
        try {
            if (preparedLoadSql == null) {
                preparedLoadSql = _conn.prepareStatement(loadSql);
            }
            preparedLoadSql.setString(1, id);
            preparedLoadSql.setString(2, getName());
            rst = preparedLoadSql.executeQuery();
            if (rst.next()) {
                bis = new BufferedInputStream(rst.getBinaryStream(2));
                if (container != null) {
                    loader = container.getLoader();
                }
                if (loader != null) {
                    classLoader = loader.getClassLoader();
                }
                if (classLoader != null) {
                    ois = new CustomObjectInputStream(bis, classLoader);
                } else {
                    ois = new ObjectInputStream(bis);
                }
                if (debug > 0) {
                    String msg = MessageFormat.format(rb.getString(LogFacade.LOADING_SESSION_FROM_DATABASE), new Object[] { id, sessionTable });
                    log(msg);
                }
                _session = StandardSession.deserialize(ois, manager);
                _session.setManager(manager);
            } else if (debug > 0) {
                log(getStoreName() + ": No persisted data object found");
            }
        } catch (SQLException e) {
            String msg = MessageFormat.format(rb.getString(LogFacade.SQL_ERROR), e);
            log(msg);
        } finally {
            try {
                if (rst != null) {
                    rst.close();
                }
            } catch (SQLException e) {
            // Ignore
            }
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                // Ignore
                }
            }
            release(_conn);
        }
    }
    return (_session);
}
Also used : Container(org.apache.catalina.Container) Loader(org.apache.catalina.Loader) CustomObjectInputStream(org.apache.catalina.util.CustomObjectInputStream) CustomObjectInputStream(org.apache.catalina.util.CustomObjectInputStream)

Example 73 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class ContainerBase method setParent.

/**
 * Set the parent Container to which this Container is being added as a
 * child.  This Container may refuse to become attached to the specified
 * Container by throwing an exception.
 *
 * @param container Container to which this Container is being added
 *  as a child
 *
 * @exception IllegalArgumentException if this Container refuses to become
 *  attached to the specified Container
 */
public void setParent(Container container) {
    Container oldParent = this.parent;
    this.parent = container;
    support.firePropertyChange("parent", oldParent, this.parent);
}
Also used : Container(org.apache.catalina.Container)

Example 74 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class StandardContext method postWorkDirectory.

/**
 * Set the appropriate context attribute for our work directory.
 */
private void postWorkDirectory() {
    // Acquire (or calculate) the work directory path
    String workDir = getWorkDir();
    if (workDir == null || workDir.length() == 0) {
        // Retrieve our parent (normally a host) name
        String hostName = null;
        String engineName = null;
        String hostWorkDir = null;
        Container parentHost = getParent();
        if (parentHost != null) {
            hostName = parentHost.getName();
            if (parentHost instanceof StandardHost) {
                hostWorkDir = ((StandardHost) parentHost).getWorkDir();
            }
            Container parentEngine = parentHost.getParent();
            if (parentEngine != null) {
                engineName = parentEngine.getName();
            }
        }
        if ((hostName == null) || (hostName.length() < 1))
            hostName = "_";
        if ((engineName == null) || (engineName.length() < 1))
            engineName = "_";
        String temp = getPath();
        if (temp.startsWith("/"))
            temp = temp.substring(1);
        temp = temp.replace('/', '_');
        temp = temp.replace('\\', '_');
        if (temp.length() < 1)
            temp = "_";
        if (hostWorkDir != null) {
            workDir = hostWorkDir + File.separator + temp;
        } else {
            workDir = "work" + File.separator + engineName + File.separator + hostName + File.separator + temp;
        }
        setWorkDir(workDir);
    }
    // Create this directory if necessary
    File dir = new File(workDir);
    if (!dir.isAbsolute()) {
        File catalinaHome = engineBase();
        String catalinaHomePath = null;
        try {
            catalinaHomePath = catalinaHome.getCanonicalPath();
            dir = new File(catalinaHomePath, workDir);
        } catch (IOException e) {
        }
    }
    if (!dir.mkdirs() && !dir.isDirectory()) {
        log.log(Level.SEVERE, LogFacade.CREATE_WORK_DIR_EXCEPTION, dir.getAbsolutePath());
    }
    // Set the appropriate servlet context attribute
    getServletContext().setAttribute(ServletContext.TEMPDIR, dir);
    context.setAttributeReadOnly(ServletContext.TEMPDIR);
}
Also used : Container(org.apache.catalina.Container) IOException(java.io.IOException) File(java.io.File)

Example 75 with Container

use of org.apache.catalina.Container in project Payara by payara.

the class StandardContext method getVirtualServerName.

@Override
public String getVirtualServerName() {
    String virtualServerName = null;
    Container parent = getParent();
    if (parent != null) {
        virtualServerName = parent.getName();
    }
    return virtualServerName;
}
Also used : Container(org.apache.catalina.Container)

Aggregations

Container (org.apache.catalina.Container)163 Context (org.apache.catalina.Context)28 IOException (java.io.IOException)24 Host (org.apache.catalina.Host)22 StandardContext (org.apache.catalina.core.StandardContext)21 Engine (org.apache.catalina.Engine)18 LifecycleException (org.apache.catalina.LifecycleException)17 File (java.io.File)15 ObjectName (javax.management.ObjectName)15 Wrapper (org.apache.catalina.Wrapper)13 StandardHost (org.apache.catalina.core.StandardHost)13 ArrayList (java.util.ArrayList)12 ServletException (javax.servlet.ServletException)11 MalformedURLException (java.net.MalformedURLException)10 Valve (org.apache.catalina.Valve)10 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 NamingException (javax.naming.NamingException)9 Lifecycle (org.apache.catalina.Lifecycle)9 Realm (org.apache.catalina.Realm)9