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

The following examples show how to use org.apache.openejb.loader.SystemInstance#reset() . 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: Resolver.java    From tomee with Apache License 2.0 6 votes vote down vote up
public InputStream resolve(final String rawLocation) {
       final boolean initialized = SystemInstance.isInitialized();
final String MVN_JNDI_PREFIX = "mvn:";

       if (!initialized) {
           SystemInstance.get().setComponent(ProvisioningResolver.class, new ProvisioningResolver());
       }

       try {
           if (rawLocation.startsWith(MVN_JNDI_PREFIX) && rawLocation.length() > MVN_JNDI_PREFIX.length()) {
               try {
                   return new FileInputStream(ShrinkwrapBridge.resolve(rawLocation));
               } catch (final Throwable th) {
                   // try aether if not in a mvn build
                   th.printStackTrace();
               }
           }
           return super.resolve(rawLocation);
       } finally {
           if (!initialized) {
               SystemInstance.reset();
           }
       }
   }
 
Example 2
Source File: IvmContextTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void testReadOnlyNoException() throws NamingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
   final IvmContext context = new IvmContext();
   context.setReadOnly(true);

   String originalValue = System.getProperty(IvmContext.JNDI_EXCEPTION_ON_FAILED_WRITE);
   System.setProperty(IvmContext.JNDI_EXCEPTION_ON_FAILED_WRITE, Boolean.FALSE.toString());
   try {
       Context subContext = context.createSubcontext("global/foo/Bar");
       assertNull(subContext);
   } finally {
       if(originalValue == null) {
           System.clearProperty(IvmContext.JNDI_EXCEPTION_ON_FAILED_WRITE);
       } else {
           System.setProperty(IvmContext.JNDI_EXCEPTION_ON_FAILED_WRITE, originalValue);
       }
       SystemInstance.reset();
   }
}
 
Example 3
Source File: EarModuleNamesTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void preventDefaults() {
    System.setProperty("openejb.environment.default", "false");
    SystemInstance.reset();
    // we use it in a bunch of other tests but not here
    NewLoaderLogic.setExclusions(
            Stream.concat(Stream.of(ORIGINAL_EXCLUSIONS),
                    Stream.of("openejb-itest", "failover-ejb"))
                  .toArray(String[]::new));
}
 
Example 4
Source File: ContextualJndiReferenceTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void propagateUnwrapping() throws NamingException {
    SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem(new IvmJndiFactory()));
    final ContextualJndiReference ref = new ContextualJndiReference("foo");
    ref.setDefaultValue(new Reference() {
        @Override
        public Object getObject() throws NamingException {
            return "yeah";
        }
    });
    assertEquals("yeah", ref.getObject());
    SystemInstance.reset();
}
 
Example 5
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 6
Source File: OpenEJB.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static void destroy() {
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    if (assembler != null) {
        assembler.destroy();
    } else {
        SystemInstance.reset();
    }
    instance = null;
}
 
Example 7
Source File: ActivationConfigPropertyOverrideTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverrideFromContainerDefinedInAppModule() throws Exception {
    SystemInstance.reset();

    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));

    final AppModule appModule = new AppModule(new EjbModule(ejbJar));
    appModule.setModuleId("mymodule");

    final Container container = new Container();
    container.setId("mycontainer");
    container.setCtype("MESSAGE");
    container.getProperties().setProperty("activation.DeliveryActive", "false");
    appModule.getContainers().add(container);


    final AppInfo appInfo = config.configureApplication(appModule);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);

    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);

    assertEquals("false", orange.activationProperties.get("DeliveryActive"));
    assertEquals("false", yellow.activationProperties.get("DeliveryActive"));
}
 
Example 8
Source File: ActivationConfigPropertyOverrideTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void testEjbNameOverrideSystem() throws Exception {
    SystemInstance.reset();
    final Properties properties = SystemInstance.get().getProperties();
    properties.setProperty("Orange.activation.maxSessions", "20");
    properties.setProperty("Orange.activation.maxMessagesPerSessions", "100");
    properties.setProperty("Orange.activation.destinationType", "javax.jms.Queue");
    properties.setProperty("Orange.activation.destination", "OVERRIDDEN.QUEUE");

    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class)); // just to make sure class name is not used
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class)); // just to make sure class name is not used
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);

    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);

    assertEquals("7", orange.activationProperties.get("maxSessions"));
    assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));

    assertEquals("20", yellow.activationProperties.get("maxSessions"));
    assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
}
 
Example 9
Source File: ActivationConfigPropertyOverrideTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void testMdbOverrideSystem() throws Exception {
    SystemInstance.reset();
    final Properties systProps = SystemInstance.get().getProperties();
    final Properties properties = new Properties();
    properties.setProperty("mdb.activation.maxSessions", "20");
    properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
    properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
    properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
    systProps.putAll(properties);

    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);

    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);

    assertEquals("20", orange.activationProperties.get("maxSessions"));
    assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));

    assertEquals("20", yellow.activationProperties.get("maxSessions"));
    assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));

    for (final String n : properties.stringPropertyNames()) {
        systProps.remove(n);
    }
}
 
Example 10
Source File: ActivationConfigPropertyOverrideTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotOverridden() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);

    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);

    assertEquals("7", orange.activationProperties.get("maxSessions"));
    assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));

    assertEquals("5", yellow.activationProperties.get("maxSessions"));
    assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
    assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
}
 
Example 11
Source File: InvokeMethod.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void setUp() throws Exception {
    SystemInstance.reset();
    // we use it in a bunch of other tests but not here
    NewLoaderLogic.setExclusions(
            Stream.concat(Stream.of(ORIGINAL_EXCLUSIONS),
                    Stream.of("openejb-itest", "failover-ejb"))
                  .toArray(String[]::new));
    config = new ConfigurationFactory();
    assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
 
Example 12
Source File: MBeanDeployerTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@After
public void resetList() {
    System.clearProperty(LocalMBeanServer.OPENEJB_JMX_ACTIVE);
    assembler.destroy();
    SystemInstance.reset();
}
 
Example 13
Source File: CheckInvalidAsynchronousAnnotationsTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void cleanupTestCase() {
    SystemInstance.reset();
}
 
Example 14
Source File: ManagedScheduledExecutorServiceTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void reset() {
    SystemInstance.reset();
}
 
Example 15
Source File: ReloadingLoaderTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
@AfterClass
public static void resetSystemInstance() {
    SystemInstance.reset();
}
 
Example 16
Source File: HerokuDatabasePropertiesProviderTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Before
@After
public void reset() {
    SystemInstance.reset();
}
 
Example 17
Source File: DataSourceFactoryTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@After
@Before
public void reset() {
    SystemInstance.reset();
}
 
Example 18
Source File: CheckInvalidAsynchronousAnnotationsTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupTestCase() {
    SystemInstance.reset();
    final SystemInstance system = SystemInstance.get();
    system.setProperty(VALIDATION_OUTPUT_LEVEL, "VERBOSE");
}
 
Example 19
Source File: HooksTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void reset() {
    SystemInstance.reset();
}
 
Example 20
Source File: HttpSessionImplTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@After
public void reset() {
    SystemInstance.reset();
}