Search in sources :

Example 36 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class HTTPEJBClientXidTransactionTestCase method beforeTestClass.

/**
     * Create and setup the remoting connection
     *
     * @throws Exception
     */
@BeforeClass
public static void beforeTestClass() throws Exception {
    // These system properties are required or else we end up picking up JTS transaction manager,
    // which is not what we want
    final JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
    jtaEnvironmentBean.setTransactionManagerClassName(TransactionManagerImple.class.getName());
    jtaEnvironmentBean.setTransactionSynchronizationRegistryClassName(TransactionSynchronizationRegistryImple.class.getName());
    final TransactionManager narayanaTm = jtaEnvironmentBean.getTransactionManager();
    final TransactionSynchronizationRegistry narayanaTsr = jtaEnvironmentBean.getTransactionSynchronizationRegistry();
    final XATerminator xat = new XATerminator();
    final JBossLocalTransactionProvider.Builder builder = JBossLocalTransactionProvider.builder();
    builder.setXATerminator(xat).setExtendedJBossXATerminator(xat);
    builder.setTransactionManager(narayanaTm);
    builder.setTransactionSynchronizationRegistry(narayanaTsr);
    LocalTransactionContext.getContextManager().setGlobalDefault(new LocalTransactionContext(builder.build()));
    txManager = ContextTransactionManager.getInstance();
    txSyncRegistry = ContextTransactionSynchronizationRegistry.getInstance();
    // setup the tx manager and tx sync registry
    AuthenticationConfiguration config = AuthenticationConfiguration.EMPTY.useName("user1").usePassword("password1");
    AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
    old = AuthenticationContext.captureCurrent();
    AuthenticationContext.getContextManager().setGlobalDefault(context);
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) XATerminator(com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator) TransactionManagerImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple) TransactionSynchronizationRegistryImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple) JBossLocalTransactionProvider(org.wildfly.transaction.client.provider.jboss.JBossLocalTransactionProvider) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ContextTransactionSynchronizationRegistry(org.wildfly.transaction.client.ContextTransactionSynchronizationRegistry) JTAEnvironmentBean(com.arjuna.ats.jta.common.JTAEnvironmentBean) LocalTransactionContext(org.wildfly.transaction.client.LocalTransactionContext) BeforeClass(org.junit.BeforeClass)

Example 37 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class TransactionManagerTest method testTransactionManagerBoundToJndi.

@Test
public void testTransactionManagerBoundToJndi() throws NamingException {
    TransactionManager tm = (TransactionManager) new InitialContext().lookup("java:jboss/TransactionManager");
    Assert.assertNotNull(tm);
}
Also used : TransactionManager(javax.transaction.TransactionManager) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 38 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class TransactionRollbackSetupAction method checkTransactionStatus.

private void checkTransactionStatus() {
    try {
        final TransactionManager tm = transactionManager.getOptionalValue();
        if (tm == null) {
            return;
        }
        final int status = tm.getStatus();
        final boolean active = isTransactionActive(tm, status);
        if (active) {
            try {
                TransactionLogger.ROOT_LOGGER.transactionStillOpen(status);
                tm.rollback();
            } catch (Exception ex) {
                TransactionLogger.ROOT_LOGGER.unableToRollBack(ex);
            }
        }
    } catch (Exception e) {
        TransactionLogger.ROOT_LOGGER.unableToGetTransactionStatus(e);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) SystemException(javax.transaction.SystemException) StartException(org.jboss.msc.service.StartException)

Example 39 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class TestWildFlyTSR method test.

@Test
public void test() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
    jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple");
    final TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryWrapper(new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple());
    TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    transactionManager.begin();
    tsr.registerInterposedSynchronization(new Synchronization() {

        @Override
        public void beforeCompletion() {
            tsr.registerInterposedSynchronization(new Synchronization() {

                @Override
                public void beforeCompletion() {
                    innerSyncCalled = true;
                }

                @Override
                public void afterCompletion(int status) {
                }
            });
        }

        @Override
        public void afterCompletion(int status) {
        }
    });
    transactionManager.commit();
    assertTrue(innerSyncCalled);
}
Also used : TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) TransactionManager(javax.transaction.TransactionManager) Synchronization(javax.transaction.Synchronization) TransactionSynchronizationRegistryWrapper(org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper) Test(org.junit.Test)

Example 40 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class EjbIIOPService method start.

public synchronized void start(final StartContext startContext) throws StartException {
    try {
        final RiverMarshallerFactory factory = new RiverMarshallerFactory();
        final MarshallingConfiguration configuration = new MarshallingConfiguration();
        configuration.setClassResolver(ModularClassResolver.getInstance(serviceModuleLoaderInjectedValue.getValue()));
        this.configuration = configuration;
        this.factory = factory;
        final TransactionManager jtsTransactionManager = transactionManagerInjectedValue.getValue().getTransactionManager();
        assert !(jtsTransactionManager instanceof ContextTransactionManager);
        // Should create a CORBA interface repository?
        final boolean interfaceRepositorySupported = false;
        // Build binding name of the bean.
        final EJBComponent component = ejbComponentInjectedValue.getValue();
        final String earApplicationName = component.getEarApplicationName();
        if (iiopMetaData != null && iiopMetaData.getBindingName() != null) {
            name = iiopMetaData.getBindingName();
        } else if (useQualifiedName) {
            if (component.getDistinctName() == null || component.getDistinctName().isEmpty()) {
                name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
                name = name + component.getModuleName() + "/" + component.getComponentName();
            } else {
                name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
                name = name + component.getModuleName() + "/" + component.getDistinctName() + "/" + component.getComponentName();
            }
        } else {
            name = component.getComponentName();
        }
        name = name.replace(".", "_");
        final ORB orb = this.orb.getValue();
        if (interfaceRepositorySupported) {
            // Create a CORBA interface repository for the enterprise bean
            iri = new InterfaceRepository(orb, irPoa.getValue(), name);
            // Add bean interface info to the interface repository
            iri.mapClass(remoteView.getValue().getViewClass());
            iri.mapClass(homeView.getValue().getViewClass());
            iri.finishBuild();
            EjbLogger.ROOT_LOGGER.cobraInterfaceRepository(name, orb.object_to_string(iri.getReference()));
        }
        IORSecurityConfigMetaData iorSecurityConfigMetaData = this.iorSecConfigMetaData.getOptionalValue();
        if (this.iiopMetaData != null && this.iiopMetaData.getIorSecurityConfigMetaData() != null)
            iorSecurityConfigMetaData = this.iiopMetaData.getIorSecurityConfigMetaData();
        // Create security policies if security metadata has been provided.
        List<Policy> policyList = new ArrayList<Policy>();
        if (iorSecurityConfigMetaData != null) {
            // Create csiv2Policy for both home and remote containing IorSecurityConfigMetadata.
            final Any secPolicy = orb.create_any();
            secPolicy.insert_Value(iorSecurityConfigMetaData);
            Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
            policyList.add(csiv2Policy);
            //  Add ZeroPortPolicy if ssl is required (it ensures home and remote IORs will have port 0 in the primary address).
            boolean sslRequired = false;
            if (iorSecurityConfigMetaData != null && iorSecurityConfigMetaData.getTransportConfig() != null) {
                IORTransportConfigMetaData tc = iorSecurityConfigMetaData.getTransportConfig();
                sslRequired = IORTransportConfigMetaData.INTEGRITY_REQUIRED.equals(tc.getIntegrity()) || IORTransportConfigMetaData.CONFIDENTIALITY_REQUIRED.equals(tc.getConfidentiality()) || IORTransportConfigMetaData.ESTABLISH_TRUST_IN_CLIENT_REQUIRED.equals(tc.getEstablishTrustInClient());
            }
            if (sslRequired) {
                policyList.add(ZeroPortPolicy.getPolicy());
            }
        }
        //TODO: what should this default to
        String securityDomain = "CORBA_REMOTE";
        if (component.getSecurityMetaData() != null) {
            securityDomain = component.getSecurityMetaData().getSecurityDomain();
        }
        Policy[] policies = policyList.toArray(new Policy[policyList.size()]);
        // If there is an interface repository, then get the homeInterfaceDef from the IR
        InterfaceDef homeInterfaceDef = null;
        if (iri != null) {
            Repository ir = iri.getReference();
            homeInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(homeRepositoryIds[0]));
        }
        // Get the POACurrent object
        Current poaCurrent = CurrentHelper.narrow(orb.resolve_initial_references("POACurrent"));
        // Instantiate home servant, bind it to the servant registry, and create CORBA reference to the EJBHome.
        final EjbCorbaServant homeServant = new EjbCorbaServant(poaCurrent, homeMethodMap, homeRepositoryIds, homeInterfaceDef, orb, homeView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), true, securityDomain, component.getSecurityDomain());
        homeServantRegistry = poaRegistry.getValue().getRegistryWithPersistentPOAPerServant();
        ReferenceFactory homeReferenceFactory = homeServantRegistry.bind(homeServantName(name), homeServant, policies);
        final org.omg.CORBA.Object corbaRef = homeReferenceFactory.createReference(homeRepositoryIds[0]);
        //we do this twice to force eager dynamic stub creation
        ejbHome = (EJBHome) PortableRemoteObject.narrow(corbaRef, EJBHome.class);
        final HomeHandleImplIIOP homeHandle = new HomeHandleImplIIOP(orb.object_to_string(corbaRef));
        homeServant.setHomeHandle(homeHandle);
        // Initialize beanPOA and create metadata
        // This is a session bean (lifespan: transient)
        beanServantRegistry = poaRegistry.getValue().getRegistryWithTransientPOAPerServant();
        if (component instanceof StatelessSessionComponent) {
            // Stateless session bean
            ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, true, homeHandle);
        } else {
            // Stateful session bean
            ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, false, homeHandle);
        }
        homeServant.setEjbMetaData(ejbMetaData);
        // If there is an interface repository, then get the beanInterfaceDef from the IR
        InterfaceDef beanInterfaceDef = null;
        if (iri != null) {
            final Repository ir = iri.getReference();
            beanInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(beanRepositoryIds[0]));
        }
        // Instantiate the ejb object servant and bind it to the servant registry.
        final EjbCorbaServant beanServant = new EjbCorbaServant(poaCurrent, beanMethodMap, beanRepositoryIds, beanInterfaceDef, orb, remoteView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), false, securityDomain, component.getSecurityDomain());
        beanReferenceFactory = beanServantRegistry.bind(beanServantName(name), beanServant, policies);
        // Register bean home in local CORBA naming context
        rebind(corbaNamingContext.getValue(), name, corbaRef);
        EjbLogger.ROOT_LOGGER.debugf("Home IOR for %s bound to %s in CORBA naming service", component.getComponentName(), this.name);
        //now eagerly force stub creation, so de-serialization of stubs will work correctly
        final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
            try {
                DynamicStubFactoryFactory.makeStubClass(homeView.getValue().getViewClass());
            } catch (Exception e) {
                EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(homeView.getValue().getViewClass().getName(), e);
            }
            try {
                DynamicStubFactoryFactory.makeStubClass(remoteView.getValue().getViewClass());
            } catch (Exception e) {
                EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(remoteView.getValue().getViewClass().getName(), e);
            }
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
        }
    } catch (Exception e) {
        throw new StartException(e);
    }
}
Also used : ZeroPortPolicy(com.sun.corba.se.spi.extension.ZeroPortPolicy) CSIv2Policy(org.wildfly.iiop.openjdk.csiv2.CSIv2Policy) Policy(org.omg.CORBA.Policy) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) ArrayList(java.util.ArrayList) InterfaceRepository(org.wildfly.iiop.openjdk.rmi.ir.InterfaceRepository) Any(org.omg.CORBA.Any) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EJBMetaDataImplIIOP(org.jboss.ejb.iiop.EJBMetaDataImplIIOP) StartException(org.jboss.msc.service.StartException) IORTransportConfigMetaData(org.jboss.metadata.ejb.jboss.IORTransportConfigMetaData) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) StartException(org.jboss.msc.service.StartException) InterfaceDef(org.omg.CORBA.InterfaceDef) InterfaceRepository(org.wildfly.iiop.openjdk.rmi.ir.InterfaceRepository) Repository(org.omg.CORBA.Repository) IORSecurityConfigMetaData(org.jboss.metadata.ejb.jboss.IORSecurityConfigMetaData) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) RiverMarshallerFactory(org.jboss.marshalling.river.RiverMarshallerFactory) Current(org.omg.PortableServer.Current) ORB(org.omg.CORBA.ORB) HomeHandleImplIIOP(org.jboss.ejb.iiop.HomeHandleImplIIOP)

Aggregations

TransactionManager (javax.transaction.TransactionManager)110 Test (org.junit.Test)40 Transaction (javax.transaction.Transaction)24 SystemException (javax.transaction.SystemException)22 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)15 UserTransaction (javax.transaction.UserTransaction)14 JtaTransactionCoordinatorImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)12 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)11 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)9 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)9 Method (java.lang.reflect.Method)7 EntityManager (javax.persistence.EntityManager)7 NotSupportedException (javax.transaction.NotSupportedException)7 RollbackException (javax.transaction.RollbackException)7 SynchronizationCollectorImpl (org.hibernate.test.resource.common.SynchronizationCollectorImpl)6 TestForIssue (org.hibernate.testing.TestForIssue)6 IOException (java.io.IOException)5 InitialContext (javax.naming.InitialContext)5 DataSource (javax.sql.DataSource)5 JtaPlatform (org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform)5