Java Code Examples for org.apache.openejb.loader.SystemInstance#init()

The following examples show how to use org.apache.openejb.loader.SystemInstance#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalInitialContextFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void init(final Properties properties) throws Exception {
    if (openejb != null && openejb.isInitialized()) {
        return;
    }

    openejb = new OpenEJBInstance();

    if (openejb.isInitialized()) {
        return;
    }

    bootedOpenEJB = true;
    SystemInstance.init(properties);
    OptionsLog.install();
    SystemInstance.get().setProperty("openejb.embedded", "true");
    openejb.init(properties);
}
 
Example 2
Source File: InheritedAppExceptionTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollback() throws Exception {
    SystemInstance.init(new Properties());
    final BeanContext cdi = new BeanContext("foo", null, new ModuleContext("foo", null, "bar", new AppContext("foo", SystemInstance.get(), null, null, null, false), null, null), Object.class, null, new HashMap<>());
    cdi.addApplicationException(AE1.class, true, true);
    cdi.addApplicationException(AE3.class, true, false);
    cdi.addApplicationException(AE6.class, false, true);

    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE1()));
    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE2()));
    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE3()));
    assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE4()));
    assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE5()));
    assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE6()));
    assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE7()));
}
 
Example 3
Source File: TomcatLoader.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void initSystemInstance(final Properties properties) throws Exception {
    // Enable System EJBs like the MEJB and DeployerEJB
    initDefaults(properties);

    // Loader maybe the first thing executed in a new classloader
    // so we must attempt to initialize the system instance.
    SystemInstance.init(properties);
}
 
Example 4
Source File: OpenEjbContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the {@link SystemInstance}
 * @param properties properties instance
 * @throws Exception if any problem occurs
 */
private void doInitialize(final Properties properties) throws Exception{
    SystemInstance.reset();
    SystemInstance.init(properties);
    SystemInstance.get().setProperty("openejb.embedded", "true");
    SystemInstance.get().setProperty(EJBContainer.class.getName(), "true");

    if (SystemInstance.get().getComponent(ParentClassLoaderFinder.class) == null) {
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        if (tccl == null) {
            tccl = OpenEjbContainer.class.getClassLoader();
        }
        SystemInstance.get().setComponent(ParentClassLoaderFinder.class, new ProvidedClassLoaderFinder(tccl));
    }

    //Install option log
    OptionsLog.install();

    //Initialize openEjb
    OpenEJB.init(properties);

    //Warmup class
    // don't do it too eagerly to avoid to not have properties
    Core.warmup();

    //Reload ALTDD
    // otherwise hard to use multiple altdd with several start/stop in the same JVM
    DeploymentLoader.reloadAltDD();

}
 
Example 5
Source File: DeploymentsElementTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public OpenEjbConfiguration init() throws Exception {
    try {
        IO.writeString(configFile, JaxbOpenejb.marshal(Openejb.class, openejb));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }

    SystemInstance.init(properties);

    final ConfigurationFactory configurationFactory = new ConfigurationFactory();
    configurationFactory.init(properties);

    return configurationFactory.getOpenEjbConfiguration();
}
 
Example 6
Source File: URLClassLoaderFirstTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void loadFromAppIfNotInContainer() throws Exception {
    assertTrue(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));

    final URLClassLoader parent = new URLClassLoader(new URL[0]) {
        @Override
        public URL getResource(final String name) {
            if ("javax/wsdl/WSDLException.class".equals(name)) {
                return null;
            }
            return super.getResource(name);
        }
    };
    final URLClassLoader tmpLoader = new URLClassLoaderFirst(new URL[]{JarLocation.jarLocation(WSDLException.class).toURI().toURL()}, parent);

    SystemInstance.init(new Properties());
    SystemInstance.get().setComponent(ParentClassLoaderFinder.class, new ParentClassLoaderFinder() {
        @Override
        public ClassLoader getParentClassLoader(final ClassLoader fallback) {
            return parent;
        }
    });

    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(tmpLoader);
    try {
        assertFalse(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));
    } finally {
        Thread.currentThread().setContextClassLoader(old);
        SystemInstance.reset();
    }

    assertTrue(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));
    SystemInstance.reset();
}
 
Example 7
Source File: ServiceClasspathTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelativePath() throws Exception {

    final String className = "org.superbiz.foo.Orange";
    final File jar = subclass(Color.class, className);

    final File xml = File.createTempFile("config-", ".xml");
    xml.deleteOnExit();

    final PrintStream out = new PrintStream(IO.write(xml));
    out.println("<openejb>\n" +
        "  <Resource id=\"Orange\" type=\"org.superbiz.foo.Orange\"" +
        "           class-name=\"org.superbiz.foo.Orange\"" +
        "           classpath=\"${openejb.home}/" + jar.getName() + "\">\n" +
        "    red = FF\n" +
        "    green = 99\n" +
        "    blue = 00\n" +
        "  </Resource>\n" +
        "</openejb>");
    out.close();
    new File(jar.getParentFile(), "temp").mkdirs();


    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

    final Properties properties = new Properties();
    properties.setProperty("openejb.home", jar.getParentFile().getAbsolutePath());
    SystemInstance.init(properties);
    PropertyPlaceHolderHelper.reset();
    createEnvrt();
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();

    assembler.buildContainerSystem(config.getOpenEjbConfiguration(xml));

    final InitialContext initialContext = new InitialContext();
    final Color color = (Color) initialContext.lookup("openejb:Resource/Orange");

    assertNotNull(color);
    assertEquals("Orange.FF", color.getRed());
    assertEquals("Orange.99", color.getGreen());
    assertEquals("Orange.00", color.getBlue());
}
 
Example 8
Source File: AutoDeployerTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void testOriginalAppScanning() throws Exception {
    final File tmpdir = Files.tmpdir();
    final File apps = Files.mkdir(tmpdir, "myapps");
    final File conf = Files.mkdir(tmpdir, "conf");

    files.add(apps);

    final Properties properties = new Properties();
    properties.setProperty("openejb.deployments.classpath", "false");
    properties.setProperty("openejb.deployment.unpack.location", "false");
    properties.setProperty("openejb.home", tmpdir.getAbsolutePath());
    properties.setProperty("openejb.base", tmpdir.getAbsolutePath());
    properties.setProperty("openejb.autodeploy.interval", "2 seconds");

    SystemInstance.init(properties);

    { // Setup the configuration location
        final File config = new File(conf, "openejb.xml");
        IO.writeString(config, "<openejb><Deployments autoDeploy=\"true\" dir=\"myapps\"/> </openejb>");
        SystemInstance.get().setProperty("openejb.configuration", config.getAbsolutePath());
    }

    final File deployed = Files.path(apps, "colors.ear");
    final File ear = createEar(tmpdir, Orange.class, State.class);
    IO.copy(ear, deployed);

    final ConfigurationFactory configurationFactory = new ConfigurationFactory();
    configurationFactory.init(properties);
    final OpenEjbConfiguration configuration = configurationFactory.getOpenEjbConfiguration();

    { // Check the ContainerSystemInfo

        final List<String> autoDeploy = configuration.containerSystem.autoDeploy;
        assertEquals(1, autoDeploy.size());
        assertEquals("myapps", autoDeploy.get(0));
    }

    final Assembler assembler = new Assembler();
    assembler.buildContainerSystem(configuration);

    assertTrue(Orange.deployed);
    final long start = Orange.start;

    assertFalse(Yellow.deployed);
    assertTrue(Orange.deployed);

    // wait another to ensure it doesnt redeploy again
    Thread.sleep(4000);
    assertEquals(start, Orange.start);

    Files.delete(deployed);

    Orange.state.waitForChange(1, TimeUnit.MINUTES);

    assertFalse(Yellow.deployed);
    assertFalse(Orange.deployed);
}