public AppInfo configureApplication(AppModule appModule) throws OpenEJBException { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); try { return configurationFactory.configureApplication(appModule); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
private void configureDescriptor(final AppModule appModule, final Descriptor descriptor) { URL resource = appModule.getClassLoader().getResource(descriptor.path()); try { appModule.getAltDDs().put(descriptor.name(), resource == null ? new File(descriptor.path()).toURI().toURL() : resource); } catch (final MalformedURLException e) { throw new IllegalArgumentException(e); } } }
final ClassLoader cl = module.getClassLoader(); if (cl != null) { final InputStream is = cl.getResourceAsStream(path);
private void importFile(final String path) throws SAXException { final File file = new File(path); if (file.exists()) { try (final InputStream inputStream = new FileInputStream(file)) { parse(module, new InputSource(inputStream), envEntriesDeployer, beanPropertiesDeployer); } catch (final ParserConfigurationException | IOException e) { throw new SAXException(e); } } else { // try in the classpath final ClassLoader cl = module.getClassLoader(); if (cl != null) { try (final InputStream is = cl.getResourceAsStream(path)) { if (is != null) { try { parse(module, new InputSource(is), envEntriesDeployer, beanPropertiesDeployer); } catch (final ParserConfigurationException | IOException e) { throw new SAXException(e); } } else { LOGGER.warning("Can't find " + path); } } catch (final IOException e) { LOGGER.warning("Can't find " + path, e); } } else { LOGGER.warning("Can't find " + path + ", no classloader for the module " + module); } } } }
public AppModule validate(final AppModule appModule) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); // be sure to not mix classloaders try { final ValidationRule[] rules = getValidationRules(); for (int i = 0; i < rules.length; i++) { rules[i].validate(appModule); } } catch (final DefinitionException de) { throw de; } catch (final Throwable e) { e.printStackTrace(System.out); final ValidationError err = new ValidationError("cannot.validate"); err.setCause(e); err.setDetails(e.getMessage()); appModule.getValidation().addError(err); } finally { Thread.currentThread().setContextClassLoader(loader); } return appModule; }
@SuppressWarnings({"unchecked"}) protected static void addPersistenceUnits(AppModule appModule, URL... urls) throws OpenEJBException { // OPENEJB-1059: Anything in the appModule.getAltDDs() map has already been // processed by the altdd code, so anything in here should not cause OPENEJB-1059 List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml"); if (persistenceUrls == null) { persistenceUrls = new ArrayList<URL>(); appModule.getAltDDs().put("persistence.xml", persistenceUrls); } for (URL url : urls) { // OPENEJB-1059: looking for an altdd persistence.xml file in all urls // delegates to xbean finder for going throughout the list ResourceFinder finder = new ResourceFinder("", appModule.getClassLoader(), url); Map<String, URL> descriptors = getDescriptors(finder, false); // if a persistence.xml has been found, just pull it to the list if (descriptors.containsKey("persistence.xml")) { URL descriptor = descriptors.get("persistence.xml"); // don't add it if already present if (persistenceUrls.contains(descriptor)) continue; // log if it is an altdd String urlString = descriptor.toExternalForm(); if (!urlString.contains("META-INF/persistence.xml")) { logger.info("AltDD persistence.xml -> " + urlString); } persistenceUrls.add(descriptor); } } }
public AppModule validate(final AppModule appModule) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); // be sure to not mix classloaders try { final ValidationRule[] rules = getValidationRules(); for (int i = 0; i < rules.length; i++) { rules[i].validate(appModule); } } catch (final Throwable e) { e.printStackTrace(System.out); final ValidationError err = new ValidationError("cannot.validate"); err.setCause(e); err.setDetails(e.getMessage()); appModule.getValidation().addError(err); } finally { Thread.currentThread().setContextClassLoader(loader); } return appModule; }
public AppModule deploy(AppModule appModule) throws OpenEJBException { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); setModule(appModule); try { appModule = discoverAnnotatedBeans.deploy(appModule); appModule = envEntriesPropertiesDeployer.deploy(appModule); appModule = mergeWebappJndiContext.deploy(appModule); appModule = builtInEnvironmentEntries.deploy(appModule); appModule = processAnnotatedBeans.deploy(appModule); appModule = mergeWebappJndiContext.deploy(appModule); appModule = mBeanDeployer.deploy(appModule); return appModule; } finally { envEntriesPropertiesDeployer.resetAdditionalEnvEntries(); Thread.currentThread().setContextClassLoader(classLoader); removeModule(); } }
@Override public void validate(final AppModule appModule) { this.appModule = appModule; module = appModule; check(appModule.getClassLoader()); for (final WebModule webModule : appModule.getWebModules()) { module = webModule; validate(webModule); } super.validate(appModule); }
@Override public void validate(final AppModule appModule) { this.appModule = appModule; module = appModule; check(appModule.getClassLoader()); for (final WebModule webModule : appModule.getWebModules()) { module = webModule; validate(webModule); } super.validate(appModule); }
public AppModule deploy(AppModule appModule) throws OpenEJBException { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); setModule(appModule); try { appModule = discoverAnnotatedBeans.deploy(appModule); appModule = envEntriesPropertiesDeployer.deploy(appModule); appModule = mergeWebappJndiContext.deploy(appModule); appModule = builtInEnvironmentEntries.deploy(appModule); appModule = processAnnotatedBeans.deploy(appModule); appModule = mergeWebappJndiContext.deploy(appModule); appModule = mBeanDeployer.deploy(appModule); return appModule; } finally { envEntriesPropertiesDeployer.resetAdditionalEnvEntries(); Thread.currentThread().setContextClassLoader(classLoader); removeModule(); } }
final List<String> done = new ArrayList<String>(); ClassLoader cl = appModule.getClassLoader(); if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); final IAnnotationFinder finder = new AnnotationFinder(new ConfigurableClasspathArchive(appModule.getClassLoader(), true, libs)); for (final Class<? extends Annotation> mclazz : mbeanClasses) { for (final Annotated<Class<?>> clazz : finder.findMetaAnnotatedClasses(mclazz)) {
private AppInfo configureApplication(AppModule appModule, EjbModule ejbModule, Configuration configuration) throws OpenEJBException { OpenEjbConfiguration openEjbConfiguration = new OpenEjbConfiguration(); openEjbConfiguration.containerSystem = new ContainerSystemInfo(); openEjbConfiguration.facilities = new FacilitiesInfo(); boolean offline = true; ConfigurationFactory.Chain chain = new ConfigurationFactory.Chain(); ConfigurationFactory configurationFactory = new ConfigurationFactory(offline, chain, openEjbConfiguration); buildChain(offline, ejbModule.getPreAutoConfigDeployer(), SystemInstance.get().getOptions(), configurationFactory, chain); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); try { addContainerInfos(configuration, openEjbConfiguration.containerSystem, configurationFactory); addResourceAdapterMDBInfos(configuration, openEjbConfiguration.containerSystem, configurationFactory); //process resource adapters return configurationFactory.configureApplication(appModule); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
resourceInfo.originAppName = module.getModuleId(); final ResourceRef resourceRef = new ResourceRef(); resourceRef.setResType(chooseType(module.getClassLoader(), resourceInfo, resource.getType()));
final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false); newModule.getClientModules().addAll(appModule.getClientModules()); newModule.addPersistenceModules(appModule.getPersistenceModules());
final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false); newModule.getClientModules().addAll(appModule.getClientModules()); newModule.addPersistenceModules(appModule.getPersistenceModules());
finder = FinderFactory.createFinder(appModule); } catch (final Exception e) { finder = new FinderFactory.ModuleLimitedFinder(new FinderFactory.OpenEJBAnnotationFinder(new WebappAggregatedArchive(appModule.getClassLoader(), appModule.getAltDDs(), xmls))); final EjbModule ejbModule = new EjbModule(appModule.getClassLoader(), EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar()); ejbModule.setBeans(complete); ejbModule.setFinder(finder);
private DeploymentInfo quickDeploy(final Archive<?> archive, final TestClass testClass) throws DeploymentException { final String name = archive.getName(); DeploymentInfo info = DEPLOYMENT_INFO.get(name); if (info == null) { try { final AppModule module = OpenEJBArchiveProcessor.createModule(archive, testClass); final AppInfo appInfo = configurationFactory.configureApplication(module); final AppContext appCtx = assembler.createApplication(appInfo, module.getClassLoader()); final ServletContext appServletContext = new MockServletContext(); final HttpSession appSession = new MockHttpSession(); startContexts(appCtx.getWebBeansContext().getContextsService(), appServletContext, appSession); info = new DeploymentInfo(appServletContext, appSession, appInfo, appCtx); if (configuration.isSingleDeploymentByArchiveName(name)) { DEPLOYMENT_INFO.putIfAbsent(name, info); } } catch (final Exception e) { throw new DeploymentException("can't deploy " + name, e); } } return info; }
finder = FinderFactory.createFinder(appModule); } catch (final Exception e) { finder = new FinderFactory.ModuleLimitedFinder(new FinderFactory.OpenEJBAnnotationFinder(new WebappAggregatedArchive(appModule.getClassLoader(), appModule.getAltDDs(), xmls))); final EjbModule ejbModule = new EjbModule(appModule.getClassLoader(), EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar()); ejbModule.setBeans(complete); ejbModule.setFinder(finder);
final AppContext appCtx = assembler.createApplication(appInfo, module.getClassLoader()); if (isEmbeddedWebAppBuilder && PROPERTIES.containsKey(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE) && !appCtx.getWebContexts().isEmpty()) { cls.add(new Closeable() {