Announcement Announcement Module
Collapse
No announcement yet.
LDAP Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I would presume your problem was because you were using BeanFactory instead of ApplicationContext. It's quite a common problem people have with AOP and is discussed at the beginning of the reference manual.
    http://www.springframework.org/docs/...nce/beans.html
    Last edited by karldmoore; Aug 29th, 2007, 10:25 AM.

    Comment


    • #17
      Thanks a lot for all of you, I modify my code, and I had an org.springframework.beans.factory.BeanCreationExce ption:

      Code:
      Resource resource = new ClassPathResource("testContext.xml");
      //BeanFactory factory = new XmlBeanFactory(resource);
      ApplicationContext context = new ClassPathXmlApplicationContext(
                  new String[] {"testContext.xml"});
      BeanFactory factory = (BeanFactory) context;
      PerfilDao ldapContact = (PerfilDaoImpl)factory.getBean("myDataAccessObjectTarget");
      and my configuration:

      Code:
         <bean id="transactionManager" 
                  class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
            <constructor-arg ref="contextSource" />
         </bean>
         
         <bean id="myDataAccessObjectTarget" class="PerfilDaoImpl">
            <property name="ldapTemplate" ref="ldapTemplate" />
         </bean>
         
      
      	<bean id="myDataAccessObject"
      		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      		<property name="transactionManager" ref="transactionManager" />
      		<property name="target" ref="myDataAccessObjectTarget" />
         		<property name="transactionAttributes">
      			<props>
      				<prop key="create">PROPAGATION_SUPPORTS</prop>
      				<prop key="delete">PROPAGATION_SUPPORTS</prop>
      				<prop key="update">PROPAGATION_SUPPORTS</prop>
      				<prop key="getAllPerfilCuentas">PROPAGATION_REQUIRED,readOnly</prop>
      			</props>
      		</property>
      	</bean>

      Comment


      • #18
        How about this?
        Code:
        ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
        PerfilDao ldapContact = (PerfilDao) context.getBean("myDataAccessObject");
        Last edited by karldmoore; Aug 29th, 2007, 10:24 AM.

        Comment


        • #19
          A couple of other things I've noticed. Your transaction propagation setting means if an existing transaction doesn't exist it's going to execute non-transactionally. It would also be really useful to see the code you are running to test this.
          http://www.springframework.org/docs/...ATION_SUPPORTS
          Last edited by karldmoore; Aug 29th, 2007, 10:24 AM.

          Comment


          • #20
            Hi Karldmoore, I'm going to try it.
            But I changed to programatically manner using the ContextSourceTransactionManager class to perform a transaction LDAP, I saw the forum http://forum.springframework.org/arc...3C/t-9730.html and and others forums, tutoriales and I see that almost samples are the same, but I have some problems to do the transaction programmatic, here some code:

            Code:
            LdapContextSource ldapContextSource = new LdapContextSource();
            TransactionAwareContextSourceProxy tacsp = null;
            final Perfil p1 = new Perfil();
            		
            //construct an appropriate transaction manager 
            		
            ContextSourceTransactionManager txManager = new ContextSourceTransactionManager();
            		
            DefaultTransactionDefinition def = new DefaultTransactionDefinition();
            //explicitly setting the transaction name is something that can only be done programmatically
            
            def.setName("SomeTxName");
            def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
            		
            Assert.notNull(txManager, "The 'transactionManager' argument must not be null.");
            		
            ldapContextSource.setUrl("ldap://X.X.X:389");
            ldapContextSource.setBase("o=xxxxxx,c=MX");
            ldapContextSource.setUserName("cn=xxxx");
            ldapContextSource.setPassword("xxxxxx");
            		
            tacsp = new TransactionAwareContextSourceProxy(ldapContextSource);
            		
            final ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
            		
            final PerfilDao ldapContact = (PerfilDao)context.getBean("myDataAccessObject");
            
            txManager.setContextSource(ldapContextSource);
            		
            TransactionTemplate(txManager);
            
            //Asignación de los valores de un perfil
            		
            p1.setCn("Alexis Moreno");
            p1.setCt("1013");
            p1.setMail("[email protected]");
            p1.setSn("Alexis");
            p1.setTelephoneNumber("4422666666");
            				
            // execute your business logic here
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            			protected void doInTransactionWithoutResult(TransactionStatus status) {
            			try{
            			ldapContact.create(p1, "perfilTelmex");
            			}
            			catch(Exception e){
            			e.printStackTrace();
            			status.setRollbackOnly();
            			}
            		}
            	});
            Where is/are my error(s)?

            Thanks

            Comment


            • #21
              I forgot to said that I catch and Exception in the line "transactionTemplate.execute(new TransactionCallbackWithoutResult() {":

              Exception in thread "main" java.lang.NullPointerException
              at org.springframework.ldap.core.support.LdapContextS ource.getAnonymousEnv(LdapContextSource.java:49)
              at org.springframework.ldap.core.support.AbstractCont extSource.getAuthenticatedEnv(AbstractContextSourc e.java:395)
              at org.springframework.ldap.core.support.AbstractCont extSource.getReadOnlyContext(AbstractContextSource .java:102)
              at org.springframework.ldap.transaction.compensating. manager.ContextSourceTransactionManagerDelegate.ge tNewHolder(ContextSourceTransactionManagerDelegate .java:79)
              at org.springframework.transaction.compensating.suppo rt.AbstractCompensatingTransactionManagerDelegate. doBegin(AbstractCompensatingTransactionManagerDele gate.java:89)
              at org.springframework.ldap.transaction.compensating. manager.ContextSourceTransactionManager.doBegin(Co ntextSourceTransactionManager.java:123)
              at org.springframework.transaction.support.AbstractPl atformTransactionManager.getTransaction(AbstractPl atformTransactionManager.java:350)
              at org.springframework.transaction.support.Transactio nTemplate.execute(TransactionTemplate.java:124)
              at SimpleService3.<init>(SimpleService3.java:80)
              at SimpleService3.main(SimpleService3.java:21)

              Comment


              • #22
                Debugging I saw the exception "java.lang.IllegalArgumentException: Key must not be null" for the LdapContextSource object
                Last edited by sacara; Jul 9th, 2007, 04:30 PM.

                Comment


                • #23
                  When creating a ContextSource programmatically you need to call afterPropertiesSet once you're done setting the properties. That might account for the IllegalArgumentException.

                  Comment


                  • #24
                    Ok, I already modified my class, and now I have problems with my xml. I put a piece of code of my xml before. I hope somebody could give me a favor to tell me my mistakes, I'm new with LDAP transactions.

                    Comment


                    • #25
                      It's really difficult to follow what you're doing. First you're using XML configuration, then you switch to code, and then you switch back to XML. Please be consistent, post any stack traces you get, and explain carefully what you did and what went wrong. You can't just say "and now I have problems with my xml" and expect an answer.

                      Are you using LDAP transactions together with JDBC? You haven't said so explicitly, but it seems that's what you want to do. Am I right?

                      Did you change the transaction propagation settings as Karl suggested? What happened?

                      Where is the test code that Karl asked for? How do you know that it doesn't work?

                      Comment


                      • #26
                        Hi Ulsa, I'm going to describe what I'm doing.
                        I need to use transaction for LDAP now (after a time, I'm going to incorporate JDBC transactions, so in the future I'm going to have two transactions: LDAP and JDBC), I chose the programmatic manner to do transactions for LDAP, and I'm trying to use the TransactionTemplate and PlatformTransactionManager classes following the examples in http://static.springframework.org/sp...ansaction.html, but I didn't see how has to be my xml configuration. Before to use the TransactionTemplete and PlatformTransactionManager, I tried to use the ContextSourceTransactionManager and ContextSourceAndDataSourceTransactionManager class but I saw that I had the same problem with my xml configuration, because I think that I mixed the programmatic and declarative manner, and I don't know how has to be my xml configuration for programmatic manner. I know that my xml configuration is wrong because I get exceptions.
                        What class have I to use to do a transaction manager object? To use a TransactionTemplate object is similar or equivalent to use a ContextSourceTransactionManager or ContextSourceAndDataSourceTransactionManager object? and What changes have I to do in my xml configuration for the programmatic manner?

                        When I used the ContextSourceTransactionManager class for PlatformTransactionManager, I did the follow manner:

                        Code:
                        ContextSourceTransactionManager txManager = (ContextSourceTransactionManager)context.getBean("myDataAccessObject");
                        and, for the TransactionTemplate class:

                        Code:
                        TransactionTemplate tt = (TransactionTemplate)context.getBean("contextSourceTarget");
                        I don't know if is correct use "getBean", I assume that is the manner for get the context of xml and initialize the transaction object.

                        I hope that was understandable my explanation, thank you
                        Last edited by sacara; Jul 11th, 2007, 11:51 AM.

                        Comment


                        • #27
                          Did your problem got resolved?

                          Hi Sacara, Did your problem got resolved? I am facing the same issue of not getting rollback when using Spring LDAP Transactions Declaratively. I compared my XML file when you are using the org.springframework.ldap.transaction.compensating. manager.ContextSourceTransactionManager and i am using PROPAGATION_REQUIRES_NEW. The transaction is not getting rolledback.

                          Can anybody help?

                          Comment


                          • #28
                            Is it a conscious choice of having PROPAGATION_REQUIRES_NEW? As Jürgen explains in this post, this transaction definition creates an independent inner transaction, which will be committed or rolled back completely independent of the outer transaction. It's mainly used for manual id generation inside a longer transaction. Is this really what you want?

                            Comment


                            • #29
                              Also, I suggest you create a new thread for this particular problem. This thread is now three pages long.

                              As always, post your configuration (the XML), the bootstrapping code (the one that reads the XML), and the actual code (that uses the beans). Use the [code] tag.

                              Comment


                              • #30
                                It seems i can't start a new thread with the below reply

                                Hi Ulsa,

                                Thanks a lot for your reply. Yes I understood by debugging the code during my trace back to see where exactly it is failing. I can post the location of the Spring code where exactly is failing, but donno the reason where I am going wrong in the settings. First please watch my files below:

                                springConfig.xml

                                <bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapC ontextSource">

                                <property name="xxx" value="xxx" />
                                <property name="base" value="ou=system" />
                                <property name="userName" value="uid=xx,ou=xx" />
                                <property name="password" value="xx" />
                                </bean>
                                <bean id="contextSource" class="org.springframework.ldap.transaction.compen sating.manager.TransactionAwareContextSourceProxy" >
                                <constructor-arg ref="contextSourceTarget" />
                                </bean>
                                <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
                                <constructor-arg ref="contextSource" />
                                </bean>
                                <bean id="transactionManager" class="org.springframework.ldap.transaction.compen sating.manager.ContextSourceTransactionManager">
                                <property name="contextSource" ref="contextSource"/>
                                </bean>

                                <bean id="myDataAccessObjectTarget" class="com.xxx.business.service.adminsecurity.impl .AdminSecurityServiceImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />
                                </bean>

                                <bean id="myDataAccessObject"
                                class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
                                <property name="transactionManager" ref="transactionManager" />
                                <property name="target" ref="myDataAccessObjectTarget" />
                                <property name="transactionAttributes">
                                <props>
                                <prop key="save*">PROPAGATION_REQUIRES_NEW,-AdminSecurityServiceException</prop>
                                </props>
                                </property>
                                </bean>

                                <bean id="userDAOLdap" class="com.xx.persistence.adminsecurity.impl.UserD AOLdapImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />
                                </bean>
                                <bean id="userGroupDAOLdap" class="com.xx.persistence.adminsecurity.impl.UserG roupDAOLdapImpl">
                                <property name="ldapTemplate" ref="ldapTemplate" />
                                </bean>
                                </beans>

                                The code inside the save method which is called and the point where the exception is simulated.

                                try {

                                Resource resource = new ClassPathResource("springconfig.xml");
                                factory = new XmlBeanFactory(resource);
                                ldapUserDAO = (UserDAOLdapImpl) factory.getBean("userDAOLdap");
                                ldapUserGroupDAO = (UserGroupDAOLdapImpl) factory
                                .getBean("userGroupDAOLdap");

                                if (userGroups != null) {
                                Iterator iter = userGroups.iterator();
                                while (iter.hasNext()) {
                                i++;
                                UserGroup userGroup = (UserGroup) iter.next();
                                if(StringUtils.isEmpty(userGroup.getCommonName())) {
                                userGroup.setErrorMessage("Error: User Group Common Name is mandatory.");
                                updatedUserGroups.add(userGroup);
                                ..........................
                                ........................

                                if(i==2)
                                throw new AdminSecurityServiceException();
                                }
                                }

                                } catch (Exception ee){}


                                public UserGroup addUserGroup(UserGroup userGroup) {

                                Name dn = AdminSecurityUtil.buildUserGroupDn(userGroup);
                                DirContextOperations context = null;

                                try {
                                context = ldapTemplate.lookupContext(dn);
                                } catch (NameNotFoundException e) {
                                context = new DirContextAdapter();
                                ldapTemplate.bind(dn, context, null);
                                return userGroup;
                                }
                                return userGroup;
                                }
                                }

                                Location in the Spring Code where it is failing to Rollback.

                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:85)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:58)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:60)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at java.lang.reflect.Method.invoke(Method.java:391)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:304)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:198)
                                [8/26/08 9:07:58:692 EDT] 00000026 SystemErr R at $Proxy0.saveUserGroupChanges(Unknown Source)

                                I am also getting a info message below:
                                [8/26/08 9:08:03:130 EDT] 0000000d TimeoutManage I WTRN0006W: Transaction 0000011BFF1EF2EB000000010000000129960A503C631343F5 4A37DA4DCA3ED5AAD6D8490000011BFF1EF2EB000000010000 000129960A503C631343F54A37DA4DCA3ED5AAD6D849000000 01 has timed out after 120 seconds.

                                Please help.....

                                Comment

                                Working...
                                X