use of org.glassfish.api.deployment.DeploymentContext in project Payara by payara.
the class EjbApplication method loadContainers.
/**
* Initial phase of continer initialization. This creates the concrete container
* instance for each EJB component, registers JNDI entries, etc. However, no
* EJB bean instances or invocations occur during this phase. Those must be
* delayed until start() is called.
* @param startupContext
* @return
*/
boolean loadContainers(ApplicationContext startupContext) {
DeploymentContext dc = (DeploymentContext) startupContext;
String dcMapToken = "org.glassfish.ejb.startup.SingletonLCM";
singletonLCM = dc.getTransientAppMetaData(dcMapToken, SingletonLifeCycleManager.class);
if (singletonLCM == null) {
singletonLCM = new SingletonLifeCycleManager(initializeInOrder);
dc.addTransientAppMetaData(dcMapToken, singletonLCM);
}
if (!initializeInOrder) {
dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.FALSE);
List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class);
if (ejbAppList == null) {
ejbAppList = new ArrayList<EjbApplication>();
dc.addTransientAppMetaData(CONTAINER_LIST_KEY, ejbAppList);
}
ejbAppList.add(this);
}
try {
policyLoader.loadPolicy();
for (EjbDescriptor desc : ejbs) {
// Initialize each ejb container (setup component environment, register JNDI objects, etc.)
// Any instance instantiation , timer creation/restoration, message inflow is delayed until
// start phase.
ContainerFactory ejbContainerFactory = services.getService(ContainerFactory.class, desc.getContainerFactoryQualifier());
if (ejbContainerFactory == null) {
String errMsg = localStrings.getLocalString("invalid.container.module", "Container module is not available", desc.getEjbTypeForDisplay());
throw new RuntimeException(errMsg);
}
Container container = ejbContainerFactory.createContainer(desc, ejbAppClassLoader, dc);
containers.add(container);
if (desc instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) desc).isSingleton()) {
singletonLCM.addSingletonContainer(this, (AbstractSingletonContainer) container);
}
}
} catch (Throwable t) {
abortInitializationAfterException();
throw new RuntimeException("EJB Container initialization error", t);
} finally {
// clean up the thread local current classloader after codegen to ensure it isn't
// referencing the deployed application
CurrentClassLoader.set(this.getClass().getClassLoader());
Wrapper._clear();
}
return true;
}
use of org.glassfish.api.deployment.DeploymentContext in project Payara by payara.
the class EjbApplication method start.
public boolean start(ApplicationContext startupContext) throws Exception {
started = true;
if (!initializeInOrder) {
Boolean alreadyMarked = dc.getTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.class);
if (!alreadyMarked.booleanValue()) {
List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class);
for (EjbApplication app : ejbAppList) {
app.markAllContainersAsStarted();
}
dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.TRUE);
}
}
try {
DeployCommandParameters params = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
for (Container container : containers) {
container.startApplication(params.origin.isDeploy());
}
singletonLCM.doStartup(this);
} catch (Exception e) {
abortInitializationAfterException();
throw e;
}
return true;
}
use of org.glassfish.api.deployment.DeploymentContext in project Payara by payara.
the class WebServicesApplication method start.
public boolean start(ApplicationContext startupContext) throws Exception {
cl = startupContext.getClassLoader();
try {
app = deploymentCtx.getModuleMetaData(Application.class);
DeployCommandParameters commandParams = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
String virtualServers = commandParams.virtualservers;
Iterator<EjbEndpoint> iter = ejbendpoints.iterator();
EjbEndpoint ejbendpoint = null;
while (iter.hasNext()) {
ejbendpoint = iter.next();
String contextRoot = ejbendpoint.contextRoot;
WebServerInfo wsi = new WsUtil().getWebServerInfoForDAS();
URL rootURL = wsi.getWebServerRootURL(ejbendpoint.isSecure);
dispatcher.registerEndpoint(contextRoot, httpHandler, this, virtualServers);
// Fix for issue 13107490 and 17648
if (wsi.getHttpVS() != null && wsi.getHttpVS().getPort() != 0) {
logger.log(Level.INFO, LogUtils.EJB_ENDPOINT_REGISTRATION, new Object[] { app.getAppName(), rootURL + contextRoot });
}
}
} catch (EndpointRegistrationException e) {
logger.log(Level.SEVERE, LogUtils.ENDPOINT_REGISTRATION_ERROR, e.toString());
}
return true;
}
use of org.glassfish.api.deployment.DeploymentContext in project Payara by payara.
the class DeploymentImpl method createModuleBda.
private void createModuleBda(ReadableArchive archive, Collection<EjbDescriptor> ejbs, DeploymentContext context, String moduleName) {
RootBeanDeploymentArchive rootBda = new RootBeanDeploymentArchive(archive, ejbs, context, moduleName);
BeanDeploymentArchive moduleBda = rootBda.getModuleBda();
BeansXml moduleBeansXml = moduleBda.getBeansXml();
if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
addBdaToDeploymentBdas(rootBda);
addBdaToDeploymentBdas(moduleBda);
addBeanDeploymentArchives(rootBda);
}
// first check if the parent is an ear and if so see if there are app libs defined there.
if (!earContextAppLibBdasProcessed && context instanceof DeploymentContextImpl) {
DeploymentContextImpl deploymentContext = (DeploymentContextImpl) context;
DeploymentContext parentContext = deploymentContext.getParentContext();
if (parentContext != null) {
processBdasForAppLibs(parentContext.getSource(), parentContext);
parentContext.getSource();
earContextAppLibBdasProcessed = true;
}
}
// then check the module
processBdasForAppLibs(archive, context);
}
use of org.glassfish.api.deployment.DeploymentContext in project Payara by payara.
the class RootBeanDeploymentArchiveTest method testConstructor.
@Test
public void testConstructor() throws Exception {
String archiveName = "an";
String webInfLib1 = "WEB-INF/lib/lib1.jar";
String webInfLib2 = "WEB-INF/lib/lib2.jar";
String subArchive11Name = "sa1";
String subArchive12Name = "sa2";
URI webInfLib1URI = URI.create(webInfLib1);
URI webInfLib2URI = URI.create(webInfLib2);
ArrayList<String> lib1ClassNames = new ArrayList<>();
lib1ClassNames.add(Lib1Class1.class.getName() + ".class");
lib1ClassNames.add(Lib1Class2.class.getName() + ".class");
ArrayList<String> lib2ClassNames = new ArrayList<>();
lib2ClassNames.add(Lib2Class1.class.getName() + ".class");
lib2ClassNames.add(Lib2Class2.class.getName() + ".class");
WeldUtils.BDAType bdaType = WeldUtils.BDAType.WAR;
ArrayList<String> webInfLibEntries = new ArrayList<>();
webInfLibEntries.add(webInfLib1);
webInfLibEntries.add(webInfLib2);
EasyMockSupport mockSupport = new EasyMockSupport();
BeansXml beansXML = mockSupport.createMock(BeansXml.class);
WeldBootstrap wb = mockSupport.createMock(WeldBootstrap.class);
ReadableArchive readableArchive = mockSupport.createMock(ReadableArchive.class);
ReadableArchive subArchive1 = mockSupport.createMock(ReadableArchive.class);
ReadableArchive subArchive2 = mockSupport.createMock(ReadableArchive.class);
Collection<EjbDescriptor> ejbs = Collections.emptyList();
DeploymentContext deploymentContext = mockSupport.createMock(DeploymentContext.class);
expect(deploymentContext.getClassLoader()).andReturn(null).anyTimes();
expect(readableArchive.getName()).andReturn(archiveName).anyTimes();
expect(readableArchive.exists(WeldUtils.WEB_INF_BEANS_XML)).andReturn(true).anyTimes();
expect(readableArchive.exists(WeldUtils.WEB_INF_CLASSES_META_INF_BEANS_XML)).andReturn(false).anyTimes();
// in BeanDeploymentArchiveImpl.populate
expect(deploymentContext.getTransientAppMetadata()).andReturn(null).anyTimes();
expect(deploymentContext.getModuleMetaData(Application.class)).andReturn(null).anyTimes();
expect(deploymentContext.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class)).andReturn(wb).anyTimes();
expect(wb.parse(anyObject(URL.class))).andReturn(beansXML).anyTimes();
expect(readableArchive.getURI()).andReturn(URI.create("an.war")).anyTimes();
expect(subArchive1.getURI()).andReturn(webInfLib1URI).anyTimes();
expect(subArchive2.getURI()).andReturn(webInfLib2URI).anyTimes();
expect(beansXML.getBeanDiscoveryMode()).andReturn(BeanDiscoveryMode.ALL).anyTimes();
expect(readableArchive.entries()).andReturn(Collections.<String>emptyEnumeration());
readableArchive.close();
expect(readableArchive.exists(WeldUtils.WEB_INF_LIB)).andReturn(true).anyTimes();
expect(readableArchive.entries(WeldUtils.WEB_INF_LIB)).andReturn(Collections.enumeration(webInfLibEntries));
expect(readableArchive.getSubArchive(webInfLib1)).andReturn(subArchive1);
expect(subArchive1.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
expect(readableArchive.getSubArchive(webInfLib2)).andReturn(subArchive2);
expect(subArchive2.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
// build new BeanDeploymentArchiveImpl for lib1 and lib2
setupMocksForWebInfLibBda(subArchive1, subArchive11Name, lib1ClassNames);
setupMocksForWebInfLibBda(subArchive2, subArchive12Name, lib2ClassNames);
readableArchive.close();
mockSupport.replayAll();
RootBeanDeploymentArchive rootBeanDeploymentArchive = new RootBeanDeploymentArchive(readableArchive, ejbs, deploymentContext);
assertEquals("root_" + archiveName, rootBeanDeploymentArchive.getId());
assertEquals(WeldUtils.BDAType.UNKNOWN, rootBeanDeploymentArchive.getBDAType());
assertEquals(0, rootBeanDeploymentArchive.getBeanClasses().size());
assertEquals(0, rootBeanDeploymentArchive.getBeanClassObjects().size());
assertNull(rootBeanDeploymentArchive.getBeansXml());
BeanDeploymentArchiveImpl moduleBda = (BeanDeploymentArchiveImpl) rootBeanDeploymentArchive.getModuleBda();
assertNotNull(moduleBda);
assertEquals(WeldUtils.BDAType.WAR, moduleBda.getBDAType());
assertEquals(3, rootBeanDeploymentArchive.getBeanDeploymentArchives().size());
assertTrue(rootBeanDeploymentArchive.getBeanDeploymentArchives().contains(moduleBda));
assertEquals(3, moduleBda.getBeanDeploymentArchives().size());
assertTrue(moduleBda.getBeanDeploymentArchives().contains(rootBeanDeploymentArchive));
assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClasses().size());
assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClassObjects().size());
assertSame(rootBeanDeploymentArchive.getModuleClassLoaderForBDA(), moduleBda.getModuleClassLoaderForBDA());
mockSupport.verifyAll();
mockSupport.resetAll();
}
Aggregations