use of org.glassfish.internal.api.ClassLoaderHierarchy in project Payara by payara.
the class Realm method doInstantiate.
/**
* Instantiates a Realm class of the given type and invokes its init()
*/
private static synchronized Realm doInstantiate(String name, String className, Properties props) throws BadRealmException {
ServiceLocator habitat = Globals.getDefaultHabitat();
RealmsManager mgr = null;
try {
mgr = getRealmsManager();
Class realmClass = null;
// try a HK2 route first
Realm r = habitat.getService(Realm.class, name);
if (r == null) {
try {
// TODO: workaround here. Once fixed in V3 we should be able to use
// Context ClassLoader instead.
ClassLoaderHierarchy hierarchy = habitat.getService(ClassLoaderHierarchy.class);
realmClass = hierarchy.getCommonClassLoader().loadClass(className);
Object obj = realmClass.newInstance();
r = (Realm) obj;
} catch (ClassNotFoundException ex) {
realmClass = Class.forName(className);
Object obj = realmClass.newInstance();
r = (Realm) obj;
}
}
r.setName(name);
r.init(props);
if (mgr == null) {
throw new BadRealmException("Unable to locate RealmsManager Service");
}
_logger.log(Level.FINER, SecurityLoggerInfo.realmCreated, new Object[] { name, className });
return r;
} catch (NoSuchRealmException | InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
throw new BadRealmException(ex);
}
}
use of org.glassfish.internal.api.ClassLoaderHierarchy in project Payara by payara.
the class AppLibClassLoaderServiceImpl method getAppLibClassLoader.
/**
* @see org.glassfish.internal.api.ClassLoaderHierarchy#getAppLibClassLoader(String, List<URI>)
*/
public ClassLoader getAppLibClassLoader(String application, List<URI> libURIs) throws MalformedURLException {
ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class);
DelegatingClassLoader connectorCL = clh.getConnectorClassLoader(application);
if (libURIs == null || libURIs.isEmpty()) {
// class loader in the hierarchy? Instead return the parent.
return connectorCL;
}
final ClassLoader commonCL = commonCLS.getCommonClassLoader();
DelegatingClassLoader applibCL = AccessController.doPrivileged(new PrivilegedAction<DelegatingClassLoader>() {
public DelegatingClassLoader run() {
return new DelegatingClassLoader(commonCL);
}
});
// search path
for (DelegatingClassLoader.ClassFinder cf : connectorCL.getDelegates()) {
applibCL.addDelegate(cf);
}
addDelegates(libURIs, applibCL);
return applibCL;
}
use of org.glassfish.internal.api.ClassLoaderHierarchy in project Payara by payara.
the class ASClassLoaderUtil method getModuleClassPath.
/**
* Gets the classpath associated with a module, suffixing libraries
* defined [if any] for the application
*
* @param habitat the habitat the application resides in.
* @param moduleId Module id of the module
* @param deploymentLibs libraries option passed through deployment
* @return A <code>File.pathSeparator</code> separated list of classpaths
* for the passed in module, including the module specified
* "libraries" defined for the module.
*/
public static String getModuleClassPath(ServiceLocator habitat, String moduleId, String deploymentLibs) {
if (deplLogger.isLoggable(Level.FINE)) {
deplLogger.log(Level.FINE, "ASClassLoaderUtil.getModuleClassPath " + "for module Id : " + moduleId);
}
StringBuilder classpath = new StringBuilder(getModulesClasspath(habitat));
ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class);
final String commonClassPath = clh.getCommonClassPath();
if (commonClassPath != null && commonClassPath.length() > 0) {
classpath.append(commonClassPath).append(File.pathSeparator);
}
addDeployParamLibrariesForModule(classpath, moduleId, deploymentLibs, habitat);
if (deplLogger.isLoggable(Level.FINE)) {
deplLogger.log(Level.FINE, "Final classpath: " + classpath.toString());
}
return classpath.toString();
}
use of org.glassfish.internal.api.ClassLoaderHierarchy in project Payara by payara.
the class DolProvider method processDeploymentMetaData.
/**
* This method populates the Application object from a ReadableArchive
* @param archive the archive for the application
*/
public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
FileArchive expandedArchive = null;
File tmpFile = null;
ExtendedDeploymentContext context = null;
Logger logger = Logger.getAnonymousLogger();
ClassLoader cl = null;
try {
String archiveName = Util.getURIName(archive.getURI());
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
if (archiveHandler == null) {
throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", archiveName));
}
DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
ActionReport report = new HTMLActionReporter();
context = new DeploymentContextImpl(report, archive, parameters, env);
context.setArchiveHandler(archiveHandler);
String appName = archiveHandler.getDefaultApplicationName(archive, context);
parameters.name = appName;
if (archive instanceof InputJarArchive) {
// we need to expand the archive first in this case
tmpFile = File.createTempFile(archiveName, "");
String path = tmpFile.getAbsolutePath();
if (!tmpFile.delete()) {
logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] { path });
}
File tmpDir = new File(path);
tmpDir.deleteOnExit();
if (!tmpDir.exists() && !tmpDir.mkdirs()) {
throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
}
expandedArchive = (FileArchive) archiveFactory.createArchive(tmpDir);
archiveHandler.expand(archive, expandedArchive, context);
context.setSource(expandedArchive);
}
context.setPhase(DeploymentContextImpl.Phase.PREPARE);
ClassLoaderHierarchy clh = clhProvider.get();
context.createDeploymentClassLoader(clh, archiveHandler);
cl = context.getClassLoader();
deployment.getDeployableTypes(context);
deployment.getSniffers(archiveHandler, null, context);
return processDOL(context);
} finally {
if (cl != null && cl instanceof PreDestroy) {
try {
PreDestroy.class.cast(cl).preDestroy();
} catch (Exception e) {
// ignore
}
}
if (context != null) {
context.postDeployClean(true);
}
if (expandedArchive != null) {
try {
expandedArchive.close();
} catch (Exception e) {
// ignore
}
}
if (tmpFile != null && tmpFile.exists()) {
try {
FileUtils.whack(tmpFile);
} catch (Exception e) {
// ignore
}
}
}
}
Aggregations