public WebSphereUserGroupAdapter() { try { this.registry = InitialContext.doLookup("UserRegistry"); } catch (NamingException e) { logger.info("Unable to look up UserRegistry in JNDI under key 'UserRegistry', disabling websphere adapter"); } }
private UserTransaction getUserTransaction() { if (userTransaction == null) { try { userTransaction = InitialContext.doLookup("java:comp/UserTransaction"); } catch (NamingException e) { throw new TransactionException(e); } } return userTransaction; }
private TransactionSynchronizationRegistry getSynchronizationRegistry() { if (registry == null) { try { registry = InitialContext.doLookup("java:comp/TransactionSynchronizationRegistry"); } catch (NamingException e) { throw new TransactionException(e); } } return registry; }
@Override protected TransactionManager acquireTransactionManager() throws Exception { try { return InitialContext.doLookup(JBOSS_TRANSACTION_MANAGER); } catch (NamingException ex) { return super.acquireTransactionManager(); } } }
public static Session produceSession() { if (mailSession == null) { try { mailSession = InitialContext.doLookup(MAIL_JNDI_KEY); } catch (NamingException e1) { logger.debug("Mail session was not found in JNDI under {} trying to look up email.properties on classspath", MAIL_JNDI_KEY); Properties conf = new Properties(); try { conf.load(EmailSessionProducer.class.getResourceAsStream("/email.properties")); mailSession = Session.getInstance(conf); } catch (Exception e) { logger.debug("email.properties was not found on classpath, nor mail session available in JNDI, unable to configure deadlines"); return null; } } } return mailSession; } }
protected Object findTransactionSynchronizationRegistry() { String jndiName = JtaTransactionManager.DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME; try { InitialContext context = new InitialContext(); Object tsrObject = context.lookup(jndiName); return tsrObject; } catch (NamingException ex) { logger.warn("Error when getting TransactionSynchronizationRegistry from JNDI ", ex); String customJndiLocation = System.getProperty("jbpm.tsr.jndi.lookup", "java:jboss/TransactionSynchronizationRegistry"); try { Object tsrObject = InitialContext.doLookup(customJndiLocation); logger.debug( "JTA TransactionSynchronizationRegistry found at default JNDI location [{}]", customJndiLocation ); return tsrObject; } catch (Exception e1) { logger.debug( "No JTA TransactionSynchronizationRegistry found at default JNDI location [{}]", customJndiLocation, ex ); } } return null; }
protected static GlobalSchedulerService discoverSchedulerService() { if (System.getProperty("org.quartz.properties") != null) { return new QuartzSchedulerService(); } else { // if there is ejb scheduler service available make use of it unless it's disabled if (!"true".equalsIgnoreCase(System.getProperty("org.kie.timer.ejb.disabled"))) { try { Class<?> clazz = Class.forName("org.jbpm.services.ejb.timer.EjbSchedulerService"); // to ensure ejb timer service is actually available let's jndi look up InitialContext.doLookup("java:module/EJBTimerScheduler"); return (GlobalSchedulerService) clazz.newInstance(); } catch (Exception e) { logger.debug("Unable to find on initialize ejb schduler service due to {}", e.getMessage()); } } } return new ThreadPoolSchedulerService(3); }
@Before public void setUp() throws Exception { context = PersistenceUtil.setupWithPoolingDataSource("org.optaplanner.persistence.jpa.test"); entityManagerFactory = (EntityManagerFactory) context.get(PersistenceUtil.ENTITY_MANAGER_FACTORY); transactionManager = (TransactionManager) InitialContext.doLookup("java:comp/TransactionManager"); }
@Override public void onMessage(Message message) { try { // need to use transaction so entity manager will persist logs UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); super.onMessage(message); ut.commit(); latch.countDown(); } catch (Exception e) { e.printStackTrace(); } }
@After public void after() throws Exception { EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); try { EntityManager em = emf.createEntityManager(); em.createQuery("delete from CorrelationPropertyInfo").executeUpdate(); em.createQuery("delete from CorrelationKeyInfo").executeUpdate(); ut.commit(); } catch (Exception ex) { ut.rollback(); Assert.fail("Exception thrown while trying to cleanup correlation data."); } cleanUp(context); }
@Test public void testAsyncAuditProducerTransactional() throws Exception { UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); Environment env = createEnvironment(context); // load the process KieBase kbase = createKnowledgeBase(); // create a new session KieSession session = createSession(kbase, env); Map<String, Object> jmsProps = new HashMap<String, Object>(); jmsProps.put("jbpm.audit.jms.transacted", true); jmsProps.put("jbpm.audit.jms.connection.factory", factory); jmsProps.put("jbpm.audit.jms.queue", queue); AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps); Assertions.assertThat(logger).isNotNull(); Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue(); // start process instance long processInstanceId = session.startProcess("com.sample.ruleflow").getId(); ut.commit(); MessageReceiver receiver = new MessageReceiver(); List<Message> messages = receiver.receive(queue); Assertions.assertThat(messages).isNotNull(); Assertions.assertThat(messages.size()).isEqualTo(11); }
@Test public void testAsyncAuditProducerTransactionalWithRollback() throws Exception { UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); Environment env = createEnvironment(context); // load the process KieBase kbase = createKnowledgeBase(); // create a new session KieSession session = createSession(kbase, env); Map<String, Object> jmsProps = new HashMap<String, Object>(); jmsProps.put("jbpm.audit.jms.transacted", true); jmsProps.put("jbpm.audit.jms.connection.factory", factory); jmsProps.put("jbpm.audit.jms.queue", queue); AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps); Assertions.assertThat(logger).isNotNull(); Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue(); // start process instance long processInstanceId = session.startProcess("com.sample.ruleflow").getId(); ut.rollback(); MessageReceiver receiver = new MessageReceiver(); List<Message> messages = receiver.receive(queue); Assertions.assertThat(messages).isNotNull(); Assertions.assertThat(messages.size()).isEqualTo(0); }
@Test public void testAsyncAuditProducerNonTransactionalWithRollback() throws Exception { UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); Environment env = createEnvironment(context); // load the process KieBase kbase = createKnowledgeBase(); // create a new session KieSession session = createSession(kbase, env); Map<String, Object> jmsProps = new HashMap<String, Object>(); jmsProps.put("jbpm.audit.jms.transacted", false); jmsProps.put("jbpm.audit.jms.connection.factory", jmsServer.lookup("ConnectionFactory")); jmsProps.put("jbpm.audit.jms.queue", queue); AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps); Assertions.assertThat(logger).isNotNull(); Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue(); // start process instance long processInstanceId = session.startProcess("com.sample.ruleflow").getId(); ut.rollback(); MessageReceiver receiver = new MessageReceiver(); List<Message> messages = receiver.receive(queue); Assertions.assertThat(messages).isNotNull(); Assertions.assertThat(messages.size()).isEqualTo(11); }
@Before public void before() throws Exception { context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME); CorrelationKeyFactory factory = KieInternalServices.Factory.get().newCorrelationKeyFactory(); // populate table with test data EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); try { EntityManager em = emf.createEntityManager(); em.persist(factory.newCorrelationKey("test123")); List<String> props = new ArrayList<String>(); props.add("test123"); props.add("123test"); em.persist(factory.newCorrelationKey(props)); ut.commit(); } catch (Exception ex) { ut.rollback(); Assert.fail("Exception thrown while trying to prepare correlation data."); } }
@Test @RequirePersistence(true) public void testRuleTaskSetVariable() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTask2.bpmn2", "BPMN2-RuleTaskSetVariable.drl"); ksession = createKnowledgeSession(kbase); List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", "SomeString"); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); ProcessInstance processInstance = ksession.startProcess("RuleTask", params); ut.commit(); assertTrue(list.size() == 1); assertProcessVarValue(processInstance, "x", "AnotherString"); assertProcessInstanceFinished(processInstance, ksession); }
assertEquals(taskName, tasks.get(0).getName()); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); Task newTask = taskService.getTaskById(tasks.get(0).getId());
@Test public void testCreationOfRuntimeManagerWithinTransaction() throws Exception { System.setProperty("jbpm.tm.jndi.lookup", "java:comp/UserTransaction"); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get() .newDefaultBuilder() .userGroupCallback(userGroupCallback) .addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2) .get(); manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment); assertNotNull(manager); RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get()); KieSession ksession = runtime.getKieSession(); assertNotNull(ksession); ksession.startProcess("ScriptTask"); ut.commit(); System.clearProperty("jbpm.tm.jndi.lookup"); }
@Test public void testCreationOfRuntimeManagerWithinTransaction() throws Exception { System.setProperty("jbpm.tm.jndi.lookup", "java:comp/UserTransaction"); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get() .newDefaultBuilder() .userGroupCallback(userGroupCallback) .addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2) .get(); manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment); assertNotNull(manager); RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get()); KieSession ksession = runtime.getKieSession(); assertNotNull(ksession); ksession.startProcess("ScriptTask"); ut.commit(); System.clearProperty("jbpm.tm.jndi.lookup"); }
assertNotNull(manager); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin();
assertEquals(sessionId, ksession.getIdentifier()); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); ProcessInstance processInstance = ksession.startProcess("customtask");