use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class WeldSniffer method scanLibDir.
private boolean scanLibDir(DeploymentContext context, ReadableArchive archive, String libLocation) {
boolean entryPresent = false;
if (libLocation != null) {
Enumeration<String> entries = archive.entries(libLocation);
while (entries.hasMoreElements() && !entryPresent) {
String entryName = entries.nextElement();
// if a jar in lib dir and not WEB-INF/lib/foo/bar.jar
if (entryName.endsWith(WeldUtils.JAR_SUFFIX) && entryName.indexOf(WeldUtils.SEPARATOR_CHAR, libLocation.length() + 1) == -1) {
try {
ReadableArchive jarInLib = archive.getSubArchive(entryName);
if (jarInLib != null) {
entryPresent = isArchiveCDIEnabled(context, jarInLib, WeldUtils.META_INF_BEANS_XML);
jarInLib.close();
}
} catch (IOException e) {
}
}
}
}
return entryPresent;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class VirtualServer method removeContext.
/**
* Stops the given <tt>context</tt> and removes it from this <tt>VirtualServer</tt>.
*
* @throws org.glassfish.embeddable.GlassFishException
*/
@Override
public void removeContext(Context context) throws GlassFishException {
ActionReport report = services.getService(ActionReport.class, "plain");
Deployment deployment = services.getService(Deployment.class);
String name;
if (context instanceof ContextFacade) {
name = ((ContextFacade) context).getAppName();
} else {
name = context.getPath();
}
ApplicationInfo appInfo = deployment.get(name);
if (appInfo == null) {
report.setMessage("Cannot find deployed application of name " + name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot find deployed application of name " + name);
}
ReadableArchive source = appInfo.getSource();
if (source == null) {
report.setMessage("Cannot get source archive for undeployment");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot get source archive for undeployment");
}
UndeployCommandParameters params = new UndeployCommandParameters(name);
params.origin = UndeployCommandParameters.Origin.undeploy;
params.target = "server";
ExtendedDeploymentContext deploymentContext = null;
try {
deploymentContext = deployment.getBuilder(_logger, params, report).source(source).build();
deployment.undeploy(name, deploymentContext);
deployment.unregisterAppFromDomainXML(name, "server");
} catch (IOException e) {
_logger.log(Level.SEVERE, LogFacade.REMOVE_CONTEXT_ERROR, e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot create context for undeployment ", e);
} catch (TransactionFailure e) {
throw new GlassFishException(e);
} finally {
if (deploymentContext != null) {
deploymentContext.clean();
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.REMOVED_CONTEXT, name);
}
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class WeldDeployer method load.
/**
* Processing in this method is performed for each module that is in the process of being loaded by
* the container.
*
* <p>
* This method will collect information from each archive (module) and produce
* <code>BeanDeploymentArchive</code> information for each module.
* </p>
*
* <p>
* The
* <code>BeanDeploymentArchive</code>s are stored in the <code>Deployment</code> (that will
* eventually be handed off to <code>Weld</code>. Once this method is called for all modules (and
* <code>BeanDeploymentArchive</code> information has been collected for all <code>Weld</code>
* modules), a relationship structure is produced defining the accessiblity rules for the
* <code>BeanDeploymentArchive</code>s.
* </p>
*
* @param container
* @param context
* @return
*/
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
ApplicationInfo applicationInfo = applicationRegistry.get(deployParams.name);
ReadableArchive archive = context.getSource();
boolean[] setTransientAppMetaData = { false };
// See if a WeldBootsrap has already been created - only want one per app.
WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData);
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
EjbServices ejbServices = null;
Set<EjbDescriptor> ejbs = new HashSet<>();
if (ejbBundle != null) {
ejbs.addAll(ejbBundle.getEjbs());
ejbServices = new EjbServicesImpl(services);
}
// Create a deployment collecting information from the ReadableArchive (archive)
// If the archive is a composite, or has version numbers per maven conventions, strip them out
String archiveName = getArchiveName(context, applicationInfo, archive);
DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
if (deploymentImpl == null) {
deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class));
// Add services
TransactionServices transactionServices = new TransactionServicesImpl(services);
deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
SecurityServices securityServices = new SecurityServicesImpl();
deploymentImpl.getServices().add(SecurityServices.class, securityServices);
ProxyServices proxyServices = new ProxyServicesImpl(services);
deploymentImpl.getServices().add(ProxyServices.class, proxyServices);
try {
ExecutorServices executorServices = new ExecutorServicesImpl();
deploymentImpl.getServices().add(ExecutorServices.class, executorServices);
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
addWeldListenerToAllWars(context);
} else {
deploymentImpl.scanArchive(archive, ejbs, context, archiveName);
}
deploymentImpl.addDeployedEjbs(ejbs);
if (ejbBundle != null && (!deploymentImpl.getServices().contains(EjbServices.class))) {
// EJB Services is registered as a top-level service
deploymentImpl.getServices().add(EjbServices.class, ejbServices);
}
ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
externalConfiguration.setBeanIndexOptimization(!deployParams.isAvailabilityEnabled());
externalConfiguration.setNonPortableMode(false);
configureConcurrentDeployment(context, externalConfiguration);
deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);
BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
if (setTransientAppMetaData[0]) {
// Do this only if we have a root BDA
appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap);
applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
}
WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class);
boolean developmentMode = isDevelopmentMode(context);
if (webBundleDescriptor != null) {
webBundleDescriptor.setExtensionProperty(WELD_EXTENSION, "true");
// Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
// able to do it.
webBundleDescriptor.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
// Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
// for JSP's..
webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_CONTEXT_LISTENER));
// Weld 2.2.1.Final. There is a tck test for this:
// org.jboss.cdi.tck.tests.context.session.listener.SessionContextHttpSessionListenerTest
// This WeldTerminationListener must come after all application-defined listeners
webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WeldTerminationListenerProxy.class.getName()));
// Adding Weld ConverstationFilter if there is a filterMapping for it and it doesn't exist already.
// However, it will be applied only if web.xml has a mapping for it.
// Doing this here to make sure that its done only for CDI enabled web applications
registerWeldConversationFilter(webBundleDescriptor);
// every deployment
if (developmentMode) {
registerProbeFilter(webBundleDescriptor);
}
}
if (developmentMode) {
registerProbeExtension(externalConfiguration, deploymentImpl);
}
BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle;
if (bundle != null) {
if (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
// Register EE injection manager at the bean deployment archive level.
// We use the generic InjectionService service to handle all EE-style
// injection instead of the per-dependency-type InjectionPoint approach.
// Each InjectionServicesImpl instance knows its associated GlassFish bundle.
InjectionServices injectionServices = new InjectionServicesImpl(deploymentImpl.injectionManager, bundle, deploymentImpl);
ResourceInjectionServicesImpl resourceInjectionServices = new ResourceInjectionServicesImpl();
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, beanDeploymentArchive.getId() });
}
beanDeploymentArchive.getServices().add(InjectionServices.class, injectionServices);
beanDeploymentArchive.getServices().add(ResourceInjectionServices.class, resourceInjectionServices);
EEModuleDescriptor eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
// Relevant in WAR BDA - WEB-INF/lib BDA scenarios
for (BeanDeploymentArchive subBda : beanDeploymentArchive.getBeanDeploymentArchives()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, subBda.getId() });
}
subBda.getServices().add(InjectionServices.class, injectionServices);
// Should not be subBda?
eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
}
}
bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
}
}
context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
return new WeldApplicationContainer();
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class BeanDeploymentArchiveImpl method populate.
private void populate(Collection<com.sun.enterprise.deployment.EjbDescriptor> ejbs, Application app) {
try {
boolean webinfbda = false;
boolean hasBeansXml = false;
String beansXMLURL = null;
if (archive.exists(WEB_INF_BEANS_XML)) {
beansXMLURL = WEB_INF_BEANS_XML;
}
if (beansXMLURL == null && archive.exists(WEB_INF_CLASSES_META_INF_BEANS_XML)) {
beansXMLURL = WEB_INF_CLASSES_META_INF_BEANS_XML;
}
if (beansXMLURL != null) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(archive, beansXMLURL);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
webinfbda = true;
// If the mode is explicitly set to "annotated", then pretend there is no beans.xml
// to force the implicit behavior
hasBeansXml = !bdMode.equals(BeanDiscoveryMode.ANNOTATED);
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_BEANS_XML, new Object[] { archive.getURI(), WEB_INF_BEANS_XML, WEB_INF_CLASSES_META_INF_BEANS_XML });
}
} else {
addBeansXMLURL(archive, beansXMLURL);
}
} else if (archive.exists(WEB_INF_CLASSES)) {
// If WEB-INF/classes exists, check for CDI beans there
// Check WEB-INF/classes for CDI-enabling annotations
URI webinfclasses = new File(context.getSourceDir().getAbsolutePath(), WEB_INF_CLASSES).toURI();
if (WeldUtils.isImplicitBeanArchive(context, webinfclasses)) {
webinfbda = true;
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_CDI_ENABLED_ARCHIVE, new Object[] { archive.getURI() });
}
}
}
if (webinfbda) {
bdaType = BDAType.WAR;
Enumeration<String> entries = archive.entries();
while (entries.hasMoreElements()) {
String entry = entries.nextElement();
if (legalClassName(entry)) {
if (entry.contains(WEB_INF_CLASSES)) {
// Workaround for incorrect WARs that bundle classes above WEB-INF/classes
// [See. GLASSFISH-16706]
entry = entry.substring(WEB_INF_CLASSES.length() + 1);
}
String className = filenameToClassname(entry);
try {
if (hasBeansXml || isCDIAnnotatedClass(className)) {
beanClassNames.add(className);
beanClasses.add(getClassLoader().loadClass(className));
}
moduleClassNames.add(className);
} catch (Throwable t) {
if (logger.isLoggable(Level.WARNING)) {
logger.log(Level.WARNING, CDILoggerInfo.ERROR_LOADING_BEAN_CLASS, new Object[] { className, t.toString() });
}
}
} else if (entry.endsWith(BEANS_XML_FILENAME)) {
addBeansXMLURL(archive, entry);
}
}
archive.close();
}
if (archive.exists(WEB_INF_LIB)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_WEB_INF_LIB, new Object[] { archive.getURI() });
}
bdaType = BDAType.WAR;
Enumeration<String> entries = archive.entries(WEB_INF_LIB);
List<ReadableArchive> weblibJarsThatAreBeanArchives = new ArrayList<ReadableArchive>();
while (entries.hasMoreElements()) {
String entry = (String) entries.nextElement();
// if directly under WEB-INF/lib
if (entry.endsWith(JAR_SUFFIX) && entry.indexOf(SEPARATOR_CHAR, WEB_INF_LIB.length() + 1) == -1 && (app == null || DOLUtils.isScanningAllowed(app, entry))) {
ReadableArchive weblibJarArchive = archive.getSubArchive(entry);
if (weblibJarArchive != null && weblibJarArchive.exists(META_INF_BEANS_XML)) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(weblibJarArchive, META_INF_BEANS_XML);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE, new Object[] { entry });
}
weblibJarsThatAreBeanArchives.add(weblibJarArchive);
}
} else {
// Check for classes annotated with qualified annotations
if (WeldUtils.isImplicitBeanArchive(context, weblibJarArchive)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE, new Object[] { entry });
}
weblibJarsThatAreBeanArchives.add(weblibJarArchive);
} else {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_SKIPPING_BEAN_ARCHIVE, new Object[] { archive.getName() });
}
}
}
}
}
// process all web-inf lib JARs and create BDAs for them
List<BeanDeploymentArchiveImpl> webLibBDAs = new ArrayList<BeanDeploymentArchiveImpl>();
if (weblibJarsThatAreBeanArchives.size() > 0) {
ListIterator<ReadableArchive> libJarIterator = weblibJarsThatAreBeanArchives.listIterator();
while (libJarIterator.hasNext()) {
ReadableArchive libJarArchive = (ReadableArchive) libJarIterator.next();
BeanDeploymentArchiveImpl wlbda = new BeanDeploymentArchiveImpl(libJarArchive, ejbs, context, makeBdaId(friendlyId, bdaType, libJarArchive.getName()));
// add to list of BDAs for this WAR
this.beanDeploymentArchives.add(wlbda);
webLibBDAs.add(wlbda);
}
}
ensureWebLibJarVisibility(webLibBDAs);
} else if (archive.getName().endsWith(RAR_SUFFIX) || archive.getName().endsWith(EXPANDED_RAR_SUFFIX)) {
// Handle RARs. RARs are packaged differently from EJB-JARs or WARs.
// see 20.2 of Connectors 1.6 specification
// The resource adapter classes are in a jar file within the
// RAR archive
bdaType = BDAType.RAR;
collectRarInfo(archive);
} else if (archive.exists(META_INF_BEANS_XML)) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(archive, META_INF_BEANS_XML);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_BDA_JAR, new Object[] { archive.getURI() });
}
bdaType = BDAType.JAR;
collectJarInfo(archive, true, !bdMode.equals(BeanDiscoveryMode.ANNOTATED));
} else {
addBeansXMLURL(archive, META_INF_BEANS_XML);
}
} else if (WeldUtils.isImplicitBeanArchive(context, archive)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_BECAUSE_SCOPE_ANNOTATION, new Object[] { archive.getURI() });
}
bdaType = BDAType.JAR;
collectJarInfo(archive, true, false);
}
// This is causing tck failures, specifically
// MultiModuleProcessingTest.testProcessedModulesCount
// creating a bda for an extionsion that does not include a beans.xml is handled later
// when annotated types are created by that extension. This is done in
// DeploymentImpl.loadBeanDeploymentArchive(Class<?> beanClass)
// if (archive.exists(META_INF_SERVICES_EXTENSION)){
// if ( logger.isLoggable( FINE ) ) {
// logger.log(FINE, "-JAR processing: " + archive.getURI()
// + " as an extensions jar since it has META-INF/services extension");
// }
// bdaType = BDAType.UNKNOWN;
// collectJarInfo(archive, false);
// }
} catch (IOException e) {
logger.log(SEVERE, e.getLocalizedMessage(), e);
} catch (ClassNotFoundException cne) {
logger.log(SEVERE, cne.getLocalizedMessage(), cne);
}
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class DeploymentImpl method processBdasForAppLibs.
// These are application libraries that reside outside of the ear. They are usually specified by entries
// in the manifest.
// to test this put a jar in domains/domain1/lib/applibs and in its manifest make sure it has something like:
// Extension-Name: com.acme.extlib
// In a war's manifest put in something like:
// Extension-List: MyExtLib
// MyExtLib-Extension-Name: com.acme.extlib
private void processBdasForAppLibs(ReadableArchive archive, DeploymentContext context) {
List<RootBeanDeploymentArchive> libBdas = new ArrayList<>();
try {
// each appLib in context.getAppLibs is a URI of the form "file:/glassfish/runtime/trunk/glassfish4/glassfish/domains/domain1/lib/applibs/mylib.jar"
List<URI> appLibs = context.getAppLibs();
Set<String> installedLibraries = InstalledLibrariesResolver.getInstalledLibraries(archive);
if (appLibs != null && !appLibs.isEmpty() && installedLibraries != null && !installedLibraries.isEmpty()) {
for (URI oneAppLib : appLibs) {
for (String oneInstalledLibrary : installedLibraries) {
if (oneAppLib.getPath().endsWith(oneInstalledLibrary)) {
ReadableArchive libArchive = null;
try {
libArchive = archiveFactory.openArchive(oneAppLib);
if (libArchive.exists(WeldUtils.META_INF_BEANS_XML)) {
String bdaId = archive.getName() + "_" + libArchive.getName();
RootBeanDeploymentArchive rootBda = new RootBeanDeploymentArchive(libArchive, Collections.<EjbDescriptor>emptyList(), context, bdaId);
libBdas.add(rootBda);
}
} finally {
if (libArchive != null) {
try {
libArchive.close();
} catch (Exception ignore) {
}
}
}
break;
}
}
}
}
} catch (URISyntaxException | IOException e) {
// todo: log error
}
for (RootBeanDeploymentArchive oneBda : libBdas) {
createLibJarBda(oneBda);
}
}
Aggregations