Search in sources :

Example 1 with ASURLClassLoader

use of com.sun.enterprise.loader.ASURLClassLoader in project Payara by payara.

the class EjbJarHandler method getClassLoader.

public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    ASURLClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<ASURLClassLoader>() {

        @Override
        public ASURLClassLoader run() {
            return new ASURLClassLoader(parent);
        }
    });
    try {
        String compatProp = context.getAppProps().getProperty(DeploymentProperties.COMPATIBILITY);
        // let's see if it's defined in glassfish-ejb-jar.xml
        if (compatProp == null) {
            GFEjbJarXMLParser gfEjbJarXMLParser = new GFEjbJarXMLParser(context.getSource());
            compatProp = gfEjbJarXMLParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        // let's see if it's defined in sun-ejb-jar.xml
        if (compatProp == null) {
            SunEjbJarXMLParser sunEjbJarXMLParser = new SunEjbJarXMLParser(context.getSourceDir());
            compatProp = sunEjbJarXMLParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        // compatibility of v2 jar visibility
        if (compatProp != null && compatProp.equals("v2")) {
            List<URL> moduleRootLibraries = ASClassLoaderUtil.getURLsAsList(null, new File[] { context.getSourceDir() }, true);
            for (URL url : moduleRootLibraries) {
                cloader.addURL(url);
            }
        }
        cloader.addURL(context.getSource().getURI().toURL());
        cloader.addURL(context.getScratchDir("ejb").toURI().toURL());
        // add libraries referenced from manifest
        for (URL url : getManifestLibraries(context)) {
            cloader.addURL(url);
        }
        try {
            final DeploymentContext dc = context;
            final ClassLoader cl = cloader;
            AccessController.doPrivileged(new PermsArchiveDelegate.SetPermissionsAction(SMGlobalPolicyUtil.CommponentType.ejb, dc, cl));
        } catch (PrivilegedActionException e) {
            throw new SecurityException(e.getException());
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, e.getMessage());
        throw new RuntimeException(e);
    }
    return cloader;
}
Also used : PermsArchiveDelegate(com.sun.enterprise.security.perms.PermsArchiveDelegate) PrivilegedActionException(java.security.PrivilegedActionException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader)

Example 2 with ASURLClassLoader

use of com.sun.enterprise.loader.ASURLClassLoader in project Payara by payara.

the class CarHandler method getClassLoader.

@Override
public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    ASURLClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<ASURLClassLoader>() {

        @Override
        public ASURLClassLoader run() {
            return new ASURLClassLoader(parent);
        }
    });
    try {
        cloader.addURL(context.getSource().getURI().toURL());
        // add libraries referenced from manifest
        for (URL url : getManifestLibraries(context)) {
            cloader.addURL(url);
        }
        try {
            final DeploymentContext dc = context;
            final ClassLoader cl = cloader;
            AccessController.doPrivileged(new PermsArchiveDelegate.SetPermissionsAction(SMGlobalPolicyUtil.CommponentType.car, dc, cl));
        } catch (PrivilegedActionException e) {
            throw new SecurityException(e.getException());
        }
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return cloader;
}
Also used : PermsArchiveDelegate(com.sun.enterprise.security.perms.PermsArchiveDelegate) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) MalformedURLException(java.net.MalformedURLException) PrivilegedActionException(java.security.PrivilegedActionException) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) URL(java.net.URL)

Example 3 with ASURLClassLoader

use of com.sun.enterprise.loader.ASURLClassLoader in project Payara by payara.

the class ConnectorClassLoader method getClasspath.

/**
 * Returns all the resources of the connector classloaders in the chain,
 * concatenated to a classpath string.
 * <p/>
 * Notice that this method is called by the setClassPath() method of
 * org.apache.catalina.loader.WebappLoader, since the ConnectorClassLoader does
 * not extend off of URLClassLoader.
 *
 * @return Classpath string containing all the resources of the connectors
 *         in the chain. An empty string if there exists no connectors in the chain.
 */
public String getClasspath() {
    StringBuffer strBuf = new StringBuffer();
    for (int i = 0; i < classLoaderChain.size(); i++) {
        ASURLClassLoader ecl = (ASURLClassLoader) classLoaderChain.get(i);
        String eclClasspath = ecl.getClasspath();
        if (eclClasspath != null) {
            if (i > 0)
                strBuf.append(File.pathSeparator);
            strBuf.append(eclClasspath);
        }
    }
    return strBuf.toString();
}
Also used : ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader)

Example 4 with ASURLClassLoader

use of com.sun.enterprise.loader.ASURLClassLoader in project Payara by payara.

the class ConnectorClassLoader method addResourceAdapter.

/**
 * Adds the requested resource adapter to the ConnectorClassLoader. A
 * ConnectorClassLoader is created with the moduleDir as its search path
 * and this classloader is added to the classloader chain.
 *
 * @param rarName   the resourceAdapter module name to add
 * @param moduleDir the directory location where the RAR contents are exploded
 */
public void addResourceAdapter(String rarName, String moduleDir) {
    try {
        File file = new File(moduleDir);
        ASURLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ASURLClassLoader>() {

            public ASURLClassLoader run() {
                return new ASURLClassLoader(parent);
            }
        });
        cl.appendURL(file.toURI().toURL());
        appendJars(file, cl);
        classLoaderChain.add(cl);
        rarModuleClassLoaders.put(rarName, cl);
    } catch (MalformedURLException ex) {
        _logger.log(Level.SEVERE, "enterprise_util.connector_malformed_url", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) File(java.io.File)

Example 5 with ASURLClassLoader

use of com.sun.enterprise.loader.ASURLClassLoader in project Payara by payara.

the class ConnectorClassLoader method removeResourceAdapter.

/**
 * Removes the resource adapter's class loader from the classloader linked
 * list
 *
 * @param moduleName the connector module that needs to be removed.
 */
public void removeResourceAdapter(String moduleName) {
    ASURLClassLoader classLoaderToRemove = (ASURLClassLoader) rarModuleClassLoaders.get(moduleName);
    if (classLoaderToRemove != null) {
        classLoaderChain.remove(classLoaderToRemove);
        rarModuleClassLoaders.remove(moduleName);
        _logger.log(Level.WARNING, "enterprise_util.remove_connector", moduleName);
    }
}
Also used : ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader)

Aggregations

ASURLClassLoader (com.sun.enterprise.loader.ASURLClassLoader)7 URL (java.net.URL)3 PermsArchiveDelegate (com.sun.enterprise.security.perms.PermsArchiveDelegate)2 MalformedURLException (java.net.MalformedURLException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 NoMetadataModelInfo (com.sun.xml.rpc.spi.tools.NoMetadataModelInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 WsUtil (org.glassfish.webservices.WsUtil)1