use of org.glassfish.web.loader.WebappClassLoader in project Payara by payara.
the class WebappLoader method start.
/**
* Start this component, initializing our associated class loader.
*
* @exception LifecycleException if a lifecycle error occurs
*/
@Override
public void start() throws LifecycleException {
// Validate and update our current component state
if (!initialized)
init();
if (started)
throw new LifecycleException(rb.getString(LogFacade.LOADER_ALREADY_STARTED_EXCEPTION));
if (log.isLoggable(Level.FINEST))
log.log(Level.FINEST, "Starting this Loader");
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
if (container.getResources() == null) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, LogFacade.NO_RESOURCE_INFO, container);
}
return;
}
// Register a stream handler factory for the JNDI protocol
initStreamHandlerFactory();
// Construct a class loader based on our current repositories list
try {
final ClassLoader cl = createClassLoader();
if (cl instanceof WebappClassLoader) {
classLoader = (WebappClassLoader) cl;
} else {
classLoader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {
@Override
public WebappClassLoader run() {
return new WebappClassLoader(cl, Application.createApplication());
}
});
}
classLoader.setResources(container.getResources());
classLoader.setDebug(this.debug);
classLoader.setDelegate(this.delegate);
for (int i = 0; i < repositories.length; i++) {
classLoader.addRepository(repositories[i]);
}
// START OF PE 4985680
if (overridablePackages != null) {
for (int i = 0; i < overridablePackages.size(); i++) {
classLoader.addOverridablePackage(overridablePackages.get(i));
}
overridablePackages = null;
}
// END OF PE 4985680
// Configure our repositories
setRepositories();
setClassPath();
setPermissions();
// Binding the Webapp class loader to the directory context
DirContextURLStreamHandler.bind(classLoader, this.container.getResources());
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.LIFECYCLE_EXCEPTION, t);
throw new LifecycleException("start: ", t);
}
}
use of org.glassfish.web.loader.WebappClassLoader in project Payara by payara.
the class WebappLoader method createClassLoader.
// ------------------------------------------------------- Private Methods
/**
* Create associated classLoader.
*/
protected ClassLoader createClassLoader() throws Exception {
Class<?> clazz = Class.forName(loaderClass);
WebappClassLoader classLoader = null;
if (parentClassLoader == null) {
parentClassLoader = Thread.currentThread().getContextClassLoader();
}
Class<?>[] argTypes = { ClassLoader.class };
Object[] args = { parentClassLoader };
Constructor<?> constr = clazz.getConstructor(argTypes);
classLoader = (WebappClassLoader) constr.newInstance(args);
classLoader.setUseMyFaces(useMyFaces);
/*
* Start the WebappClassLoader here as opposed to in the course of
* WebappLoader#start, in order to prevent it from being started
* twice (during normal deployment, the WebappClassLoader is created
* by the deployment backend without calling
* WebappLoader#createClassLoader, and will have been started
* by the time WebappLoader#start is called)
*/
try {
classLoader.start();
} catch (Exception e) {
throw new LifecycleException(e);
}
return classLoader;
}
use of org.glassfish.web.loader.WebappClassLoader in project Payara by payara.
the class WebContainer method loadWebModule.
/**
* Creates and configures a web module for each virtual server that the web module is hosted under.
* <p/>
* If no virtual servers have been specified, then the web module will not be loaded.
*
* @param webModuleConfig
* @param j2eeApplication
* @param deploymentProperties
* @return
*/
public List<Result<WebModule>> loadWebModule(WebModuleConfig webModuleConfig, String j2eeApplication, Properties deploymentProperties) {
List<Result<WebModule>> results = new ArrayList<>();
String virtualServerIds = webModuleConfig.getVirtualServers();
List<String> virtualServers = parseStringList(virtualServerIds, " ,");
if (virtualServers == null || virtualServers.isEmpty()) {
if (logger.isLoggable(INFO)) {
logger.log(INFO, WEB_MODULE_NOT_LOADED_NO_VIRTUAL_SERVERS, webModuleConfig.getName());
}
return results;
}
logger.log(FINE, LOADING_WEB_MODULE, virtualServerIds);
List<String> nonProcessedVirtualServers = new ArrayList<>(virtualServers);
Container[] containers = getEngine().findChildren();
List<VirtualServer> virtualServersToDeploy = new ArrayList<>(containers.length);
for (Container container : containers) {
if (container instanceof VirtualServer) {
VirtualServer virtualServer = (VirtualServer) container;
boolean eqVS = virtualServers.contains(virtualServer.getID());
if (eqVS) {
nonProcessedVirtualServers.remove(virtualServer.getID());
}
Set<String> matchedAliases = matchAlias(virtualServers, virtualServer);
boolean hasMatchedAlias = matchedAliases.size() > 0;
if (hasMatchedAlias) {
nonProcessedVirtualServers.removeAll(matchedAliases);
}
if (eqVS || hasMatchedAlias) {
virtualServersToDeploy.add(virtualServer);
}
}
}
boolean moreThanOneVirtualServer = virtualServersToDeploy.size() > 1;
for (VirtualServer virtualServerToDeploy : virtualServersToDeploy) {
WebModule webModule = null;
ClassLoader appClassLoader = webModuleConfig.getAppClassLoader();
try {
if (moreThanOneVirtualServer) {
WebappClassLoader virtualServerClassLoader = new WebappClassLoader(appClassLoader, webModuleConfig.getDeploymentContext().getModuleMetaData(Application.class));
virtualServerClassLoader.start();
// For every virtual server, JSF and other extensions expect a separate class loader
webModuleConfig.setAppClassLoader(virtualServerClassLoader);
}
webModule = loadWebModule(virtualServerToDeploy, webModuleConfig, j2eeApplication, deploymentProperties);
results.add(new Result<>(webModule));
} catch (Throwable t) {
if (webModule != null) {
webModule.setAvailable(false);
}
results.add(new Result<>(t));
} finally {
if (moreThanOneVirtualServer) {
webModuleConfig.setAppClassLoader(appClassLoader);
}
}
}
if (nonProcessedVirtualServers.size() > 0) {
StringBuilder sb = new StringBuilder();
boolean follow = false;
for (String alias : nonProcessedVirtualServers) {
if (follow) {
sb.append(",");
}
sb.append(alias);
follow = true;
}
logger.log(SEVERE, WEB_MODULE_NOT_LOADED_TO_VS, new Object[] { webModuleConfig.getName(), sb.toString() });
}
return results;
}
use of org.glassfish.web.loader.WebappClassLoader in project Payara by payara.
the class WarHandler method getClassLoader.
@Override
public ClassLoader getClassLoader(final ClassLoader parent, final DeploymentContext context) {
Application applicationTemp = context.getModuleMetaData(Application.class);
boolean hotDeploy = context.getCommandParameters(DeployCommandParameters.class).hotDeploy;
final Application application = applicationTemp == null ? Application.createApplication() : applicationTemp;
WebappClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {
@Override
public WebappClassLoader run() {
return new WebappClassLoader(parent, application, hotDeploy);
}
});
try {
WebDirContext r = new WebDirContext();
File base = new File(context.getSource().getURI());
r.setDocBase(base.getAbsolutePath());
cloader.setResources(r);
cloader.addRepository("WEB-INF/classes/", new File(base, "WEB-INF/classes/"));
if (context.getScratchDir("ejb") != null) {
cloader.addRepository(context.getScratchDir("ejb").toURI().toURL().toString().concat("/"));
}
if (context.getScratchDir("jsp") != null) {
cloader.setWorkDir(context.getScratchDir("jsp"));
}
// add libraries referenced from manifest
for (URL url : getManifestLibraries(context)) {
cloader.addRepository(url.toString());
}
WebXmlParser webXmlParser = getWebXmlParser(context.getSource(), application);
configureLoaderAttributes(cloader, webXmlParser, base);
configureLoaderProperties(cloader, webXmlParser, base);
configureContextXmlAttribute(cloader, base, context);
try {
doPrivileged(new SetPermissionsAction(CommponentType.war, context, cloader));
} catch (PrivilegedActionException e) {
throw new SecurityException(e.getException());
}
} catch (XMLStreamException xse) {
logger.log(SEVERE, xse.getMessage());
if (logger.isLoggable(FINE)) {
logger.log(FINE, xse.getMessage(), xse);
}
xse.printStackTrace();
} catch (IOException ioe) {
logger.log(SEVERE, ioe.getMessage());
if (logger.isLoggable(FINE)) {
logger.log(FINE, ioe.getMessage(), ioe);
}
ioe.printStackTrace();
}
cloader.start();
return cloader;
}
use of org.glassfish.web.loader.WebappClassLoader in project Payara by payara.
the class StandardContext method getExtractedMetaInfResourcePath.
/**
* Get resource from META-INF/resources/ in jars.
*/
private File getExtractedMetaInfResourcePath(String path) {
path = Globals.META_INF_RESOURCES + path;
ClassLoader cl = getLoader().getClassLoader();
if (cl instanceof WebappClassLoader) {
return ((WebappClassLoader) cl).getExtractedResourcePath(path);
}
return null;
}
Aggregations