Announcement Announcement Module
Collapse
No announcement yet.
Spring, Glassfish, Remote EJB and JTA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, Glassfish, Remote EJB and JTA

    Hi,

    I have simple main-method where I try to call a method on a remote EJB bean which requires an EJB transaction. I've set up an JtaTransactionManager where I change the jndi-environment to the IP-address of the machine that runs Glassfish (SGCS). After that I fetch the remote EJB bean from the same Glassfish machine with an helper class (BeanUtil). I then call JtaTransactionManger.getTransaction(def) and then I call the method on the remote bean which requires an transaction. However when I call the method on the remote bean I can see in the log that an transaction is created but after that it just hangs. See the code below.

    Code:
    public class TransactionManager extends JtaTransactionManager {
        
        private static Logger logger = Logger.getLogger(TransactionManager.class);
        private String deployType;
        
        public void setDeployType(String deploymentType) {
            this.deployType = deploymentType;
        }
        
        public void afterPropertiesSet() throws TransactionSystemException {
            if("dev".equals(deployType)) {
                Properties ENV = new Properties();
                ENV.put("org.omg.CORBA.ORBInitialHost", "30.0.0.181");
                ENV.put("org.omg.CORBA.ORBInitialPort", "33700");
                setJndiEnvironment(ENV);
            }
            super.afterPropertiesSet();
        }
        
        public static void main(String[] args) {
            LogConfig.configure();
            ChangeRetrieverRemote crr = BeanUtil.jndiLookup(ChangeRetrieverRemote.class, ChangeRetrieverRemote.JNDI_NAME);
            TransactionManager tx = new TransactionManager();
            tx.setDeployType("dev");
            tx.afterPropertiesSet();
            
            TransactionDefinition def = new TransactionDefinition() {
                public boolean isReadOnly() {
                    return true;
                }
                
                public int getTimeout() {
                    return 0;
                }
                
                @Override
                public int getPropagationBehavior() {
                    return PROPAGATION_REQUIRED;
                }
                
                public String getName() {
                    return "apa";
                }
                
                public int getIsolationLevel() {
                    return ISOLATION_DEFAULT;
                }
            };
                    
            logger.debug("getting transaction");
            TransactionStatus status = tx.getTransaction(def);
            logger.debug("LATEST VERSION: " + crr.getLatestChange(new DataRef("tracked", "epgcs", "programUpdate")));
            logger.debug("great");
        }
    }
    Console log:
    Code:
    17:57:31,830 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/UserTransaction]
    17:57:32,038 DEBUG TransactionManager:676 - JTA UserTransaction found at default JNDI location [java:comp/UserTransaction]
    17:57:32,038 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/TransactionManager]
    17:57:32,041 DEBUG TransactionManager:717 - No JTA TransactionManager found at fallback JNDI location [java:comp/TransactionManager]
    javax.naming.NameNotFoundException: No object bound for java:comp/TransactionManager [Root exception is java.lang.NullPointerException]
    	at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:224)
    	at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:407)
    	at javax.naming.InitialContext.lookup(InitialContext.java:392)
    	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    	at org.springframework.transaction.jta.JtaTransactionManager.findTransactionManager(JtaTransactionManager.java:709)
    	at org.springframework.transaction.jta.JtaTransactionManager.initUserTransactionAndTransactionManager(JtaTransactionManager.java:470)
    	at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:431)
    	at se.dreampark.transactionmanager.TransactionManager.afterPropertiesSet(TransactionManager.java:35)
    	at se.dreampark.transactionmanager.TransactionManager.main(TransactionManager.java:43)
    Caused by: java.lang.NullPointerException
    	at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:218)
    	... 11 more
    17:57:32,042 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:appserver/TransactionManager]
    17:57:32,043 DEBUG TransactionManager:711 - JTA TransactionManager found at fallback JNDI location [java:appserver/TransactionManager]
    17:57:32,044  INFO TransactionManager:488 - Using JTA UserTransaction: com.sun.enterprise.distributedtx.UserTransactionImpl@7578a7d9
    17:57:32,044  INFO TransactionManager:499 - Using JTA TransactionManager: com.sun.enterprise.transaction.TransactionManagerHelper@4453d3cf
    17:57:32,046 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/TransactionSynchronizationRegistry]
    17:57:32,047 DEBUG TransactionManager:752 - JTA TransactionSynchronizationRegistry found at default JNDI location [java:comp/TransactionSynchronizationRegistry]
    17:57:32,048  INFO TransactionManager:529 - Using JTA TransactionSynchronizationRegistry: com.sun.enterprise.distributedtx.TransactionSynchronizationRegistryImpl@6f3b625b
    17:57:32,048 DEBUG TransactionManager:69 - getting transaction
    17:57:32,051 DEBUG TransactionManager:371 - Creating new transaction with name [apa]: se.dreampark.transactionmanager.TransactionManager$1@4c4ab84c
    As you can see the two last log statements are missing. Any ideas?

    Just as a side-note, the real problem is that I'm trying to get this to work together with Spring. I get the exact same problem when I'm running spring, using annotations to activate the transaction handling. Right now however, I'm concentrating on getting it to work in my main-method before I try to solve the problem in spring.

    Thanks in advance
    Christian
Working...
X