Search in sources :

Example 26 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class StatefulTransactionLockingTest method setUp.

@Override
protected void setUp() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
    statefulContainerInfo.properties.setProperty("AccessTimeout", "0 milliseconds");
    // containers
    assembler.createContainer(statefulContainerInfo);
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(BlueStatelessBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean(RedStatefulBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean(LegacyStatefulBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
}
Also used : StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 27 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class StatelessConstructorInjectionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    bean.getEnvEntry().add(new EnvEntry("count", Integer.class.getName(), "10"));
    assembler.createApplication(config.configureApplication(new EjbModule(ejbJar).withCdi()));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry)

Example 28 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class StatefulContainerTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
    statefulContainerInfo.properties.setProperty("PoolSize", "0");
    statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
    statefulContainerInfo.properties.setProperty("Frequency", "0");
    assembler.createContainer(statefulContainerInfo);
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    WidgetBean.lifecycle.clear();
    expectedLifecycle = Arrays.asList(Lifecycle.values());
    inTxExpectedLifecycle = new ArrayList<Lifecycle>();
    for (final Lifecycle lifecycle : Lifecycle.values()) {
        if (!lifecycle.name().startsWith("PRE_PASSIVATE") && !lifecycle.name().startsWith("POST_ACTIVATE")) {
            inTxExpectedLifecycle.add(lifecycle);
        }
    }
}
Also used : StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 29 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class AutoDeployer method fileAdded.

private boolean fileAdded(final File file) {
    final String appPath = file.getAbsolutePath();
    logger.info("Starting Auto-Deployment of: " + appPath);
    try {
        final AppInfo appInfo = factory.configureApplication(file);
        appInfo.paths.add(appPath);
        appInfo.paths.add(appInfo.path);
        if (logger.isDebugEnabled()) {
            for (final String path : appInfo.paths) {
                logger.debug("Auto-Deployment path: " + path);
            }
        }
        final Assembler assembler = getAssembler();
        if (null == assembler) {
            throw new Exception("Assembler is not available for Auto-Deployment of: " + appPath);
        }
        assembler.createApplication(appInfo);
        // war can be unpacked so it changes the last modified time
        files.get(appPath).setModified(getLastModifiedInDir(new File(appPath)));
    } catch (final Exception e) {
        logger.error("Failed Auto-Deployment of: " + appPath, e);
    }
    return true;
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 30 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class ApplicationComposers method startContainer.

public void startContainer(final Object instance) throws Exception {
    originalProperties = (Properties) JavaSecurityManagers.getSystemProperties().clone();
    originalLoader = Thread.currentThread().getContextClassLoader();
    fixFakeClassFinder(instance);
    // For the moment we just take the first @Configuration method
    // maybe later we can add something fancy to allow multiple configurations using a qualifier
    // as a sort of altDD/altConfig concept.  Say for example the altDD prefix might be "foo",
    // we can then imagine something like this:
    // @Foo @Configuration public Properties alternateConfig(){...}
    // @Foo @Module  public Properties alternateModule(){...}
    // anyway, one thing at a time ....
    final Properties configuration = new Properties();
    configuration.put(DEPLOYMENTS_CLASSPATH_PROPERTY, "false");
    final EnableServices annotation = testClass.getAnnotation(EnableServices.class);
    if (annotation != null && annotation.httpDebug()) {
        configuration.setProperty("httpejbd.print", "true");
        configuration.setProperty("httpejbd.indent.xml", "true");
        configuration.setProperty("logging.level.OpenEJB.server.http", "FINE");
    }
    final org.apache.openejb.junit.EnableServices annotationOld = testClass.getAnnotation(org.apache.openejb.junit.EnableServices.class);
    if (annotationOld != null && annotationOld.httpDebug()) {
        configuration.setProperty("httpejbd.print", "true");
        configuration.setProperty("httpejbd.indent.xml", "true");
        configuration.setProperty("logging.level.OpenEJB.server.http", "FINE");
    }
    final WebResource webResource = testClass.getAnnotation(WebResource.class);
    if (webResource != null && webResource.value().length > 0) {
        configuration.setProperty("openejb.embedded.http.resources", Join.join(",", webResource.value()));
    }
    Openejb openejb = null;
    final Map<Object, List<Method>> configs = new HashMap<>();
    findAnnotatedMethods(configs, Configuration.class);
    findAnnotatedMethods(configs, org.apache.openejb.junit.Configuration.class);
    for (final Map.Entry<Object, List<Method>> method : configs.entrySet()) {
        for (final Method m : method.getValue()) {
            final Object o = m.invoke(method.getKey());
            if (o instanceof Properties) {
                final Properties properties = (Properties) o;
                configuration.putAll(properties);
            } else if (Openejb.class.isInstance(o)) {
                openejb = Openejb.class.cast(o);
            } else if (String.class.isInstance(o)) {
                final String path = String.class.cast(o);
                final URL url = Thread.currentThread().getContextClassLoader().getResource(path);
                if (url == null) {
                    throw new IllegalArgumentException(o.toString() + " not found");
                }
                final InputStream in = url.openStream();
                try {
                    if (path.endsWith(".json")) {
                        openejb = JSonConfigReader.read(Openejb.class, in);
                    } else {
                        openejb = JaxbOpenejb.readConfig(new InputSource(in));
                    }
                } finally {
                    IO.close(in);
                }
            }
        }
    }
    if (SystemInstance.isInitialized()) {
        SystemInstance.reset();
    }
    Collection<String> propertiesToSetAgain = null;
    final ContainerProperties configAnnot = testClass.getAnnotation(ContainerProperties.class);
    if (configAnnot != null) {
        for (final ContainerProperties.Property p : configAnnot.value()) {
            final String value = p.value();
            if (ContainerProperties.Property.IGNORED.equals(value)) {
                // enforces some clean up since we can't set null in a hash table
                System.clearProperty(p.name());
                continue;
            }
            final String name = p.name();
            configuration.put(name, value);
            if (value.contains("${")) {
                if (propertiesToSetAgain == null) {
                    propertiesToSetAgain = new LinkedList<>();
                }
                propertiesToSetAgain.add(name);
            }
        }
    }
    SystemInstance.init(configuration);
    if (SystemInstance.get().getComponent(ThreadSingletonService.class) == null) {
        CdiBuilder.initializeOWB();
    }
    for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet()) {
        for (final Field field : finder.getValue().findAnnotatedFields(RandomPort.class)) {
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
            final String service = field.getAnnotation(RandomPort.class).value();
            final String key = ("http".equals(service) ? "httpejbd" : service) + ".port";
            final String existing = SystemInstance.get().getProperty(key);
            final int random;
            if (existing == null) {
                random = NetworkUtil.getNextAvailablePort();
                SystemInstance.get().setProperty(key, Integer.toString(random));
            } else {
                random = Integer.parseInt(existing);
            }
            if (int.class == field.getType()) {
                field.set(finder.getKey(), random);
            } else if (URL.class == field.getType()) {
                field.set(finder.getKey(), new URL("http://localhost:" + random + "/"));
            }
        }
    }
    for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet()) {
        if (!finder.getValue().findAnnotatedClasses(SimpleLog.class).isEmpty()) {
            SystemInstance.get().setProperty("openejb.jul.forceReload", "true");
            break;
        }
    }
    final CdiExtensions cdiExtensions = testClass.getAnnotation(CdiExtensions.class);
    if (cdiExtensions != null) {
        SystemInstance.get().setComponent(LoaderService.class, new ExtensionAwareOptimizedLoaderService(cdiExtensions.value()));
    }
    // save the test under test to be able to retrieve it from extensions
    // /!\ has to be done before all other init
    SystemInstance.get().setComponent(TestInstance.class, new TestInstance(testClass, instance));
    // call the mock injector before module method to be able to use mocked classes
    // it will often use the TestInstance so
    final Map<Object, List<Method>> mockInjectors = new HashMap<>();
    findAnnotatedMethods(mockInjectors, MockInjector.class);
    findAnnotatedMethods(mockInjectors, org.apache.openejb.junit.MockInjector.class);
    if (!mockInjectors.isEmpty() && !mockInjectors.values().iterator().next().isEmpty()) {
        final Map.Entry<Object, List<Method>> methods = mockInjectors.entrySet().iterator().next();
        Object o = methods.getValue().iterator().next().invoke(methods.getKey());
        if (o instanceof Class<?>) {
            o = ((Class<?>) o).newInstance();
        }
        if (o instanceof FallbackPropertyInjector) {
            SystemInstance.get().setComponent(FallbackPropertyInjector.class, (FallbackPropertyInjector) o);
        }
    }
    for (final Map.Entry<Object, List<Method>> method : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Component.class).entrySet()) {
        for (final Method m : method.getValue()) {
            setComponent(method.getKey(), m);
        }
    }
    for (final Map.Entry<Object, List<Method>> method : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.Component.class).entrySet()) {
        for (final Method m : method.getValue()) {
            setComponent(method.getKey(), m);
        }
    }
    final ConfigurationFactory config = new ConfigurationFactory();
    config.init(SystemInstance.get().getProperties());
    SystemInstance.get().setComponent(ConfigurationFactory.class, config);
    assembler = new Assembler();
    SystemInstance.get().setComponent(Assembler.class, assembler);
    final OpenEjbConfiguration openEjbConfiguration;
    if (openejb != null) {
        openEjbConfiguration = config.getOpenEjbConfiguration(openejb);
    } else {
        openEjbConfiguration = config.getOpenEjbConfiguration();
    }
    assembler.buildContainerSystem(openEjbConfiguration);
    if ("true".equals(configuration.getProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "false")) || annotation != null || annotationOld != null) {
        try {
            if (annotation != null) {
                final List<String> value = new ArrayList<>(asList(annotation.value()));
                if (annotation.jaxrs()) {
                    value.add("jaxrs");
                }
                if (annotation.jaxws()) {
                    value.add("jaxws");
                }
                initFilteredServiceManager(value.toArray(new String[value.size()]));
            }
            if (annotationOld != null) {
                initFilteredServiceManager(annotationOld.value());
            }
            serviceManager = new ServiceManagerProxy(false);
            serviceManager.start();
        } catch (final ServiceManagerProxy.AlreadyStartedException e) {
            throw new OpenEJBRuntimeException(e);
        }
    }
    if (propertiesToSetAgain != null) {
        for (final String name : propertiesToSetAgain) {
            final String value = PropertyPlaceHolderHelper.simpleValue(SystemInstance.get().getProperty(name));
            configuration.put(name, value);
            // done lazily to support placeholders so container will not do it here
            JavaSecurityManagers.setSystemProperty(name, value);
        }
        propertiesToSetAgain.clear();
    }
}
Also used : InputSource(org.xml.sax.InputSource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URL(java.net.URL) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) Field(java.lang.reflect.Field) ClassFinder(org.apache.xbean.finder.ClassFinder) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Openejb(org.apache.openejb.config.sys.Openejb) JaxbOpenejb(org.apache.openejb.config.sys.JaxbOpenejb) InputStream(java.io.InputStream) Method(java.lang.reflect.Method) ThreadSingletonService(org.apache.openejb.cdi.ThreadSingletonService) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) FallbackPropertyInjector(org.apache.openejb.injection.FallbackPropertyInjector) Assembler(org.apache.openejb.assembler.classic.Assembler) Map(java.util.Map) HashMap(java.util.HashMap) ServiceManagerProxy(org.apache.openejb.util.ServiceManagerProxy)

Aggregations

Assembler (org.apache.openejb.assembler.classic.Assembler)173 EjbJar (org.apache.openejb.jee.EjbJar)90 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)83 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)80 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)80 StatelessBean (org.apache.openejb.jee.StatelessBean)54 File (java.io.File)49 InitialContext (javax.naming.InitialContext)49 Properties (java.util.Properties)45 AppInfo (org.apache.openejb.assembler.classic.AppInfo)44 HashMap (java.util.HashMap)39 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)39 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)34 ContainerSystem (org.apache.openejb.spi.ContainerSystem)33 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)29 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)28 Test (org.junit.Test)27 EjbModule (org.apache.openejb.config.EjbModule)26 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)22 Map (java.util.Map)21