Results 1 to 9 of 9

Thread: LDAP Transactions - Continued

  1. #1
    Join Date
    Aug 2008
    Posts
    7

    Default LDAP Transactions - Continued

    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.....

  2. #2
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    OK, I guess you don't understand what I mean by "use the [code] tag". Let me explain.

    When you want to show source code, XML, or computer output, you must use a formatting tag in order to make the output readable. If you don't, the forum tools will break lines and add blanks, thus distorting what you want to show. I mean, who can tell if the output was correct when you pasted it or if it actually did contain blanks at the wrong places?

    You use the tag like this:

    [code]
    My source code
    [/code]
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  3. #3
    Join Date
    Aug 2008
    Posts
    7

    Default LDAP Transactions continued

    Ulsa,

    As per your directions i kept it in code tags.

    Code:
    <beans>
    	<bean id="contextSourceTarget"
    		class="org.springframework.ldap.core.support.LdapContextSource">
    		<property name="url" value="ldap://xxx.xx.xxx.xxx:xxx" />
            <property name="base" value="ou=xxx" />
            <property name="userName" value="uid=xxx,ou=xxx" />
            <property name="password" value="xxx" />
        </bean>
        <bean id="contextSource" class="org.springframework.ldap.transaction.compensating.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.compensating.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.xxx.persistence.adminsecurity.impl.UserDAOLdapImpl">
    		<property name="ldapTemplate" ref="ldapTemplate" />
    	</bean>	
    	<bean id="userGroupDAOLdap"	class="com.xxx.persistence.adminsecurity.impl.UserGroupDAOLdapImpl">
    		<property name="ldapTemplate" ref="ldapTemplate" />
    	</bean>		
    </beans>

    Code:
    try {
    public List saveUserGroupChanges(List userGroups)
    			throws AdminSecurityServiceException {
    		myLog
    				.debug("Executing saveUserGroupChanges(String groupName, String groupDescription)");
    	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){}
    }
    Code:
    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;
    		}
    }

  4. #4
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    Thank you, that was much better.

    I believe the problem lies in the bootstrapping code. You use a BeanFactory implementation, not an ApplicationContext. The major difference is that the beans in a BeanFactory are not post-processed automatically, and that might affect proxy-based AOP such as transactions.

    Try this:

    Code:
    ApplicationContext context = new ClassPathXmlApplicationContext("springconfig.xml");
    ldapUserDAO = (UserDAOLdapImpl) context.getBean("userDAOLdap");
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  5. #5
    Join Date
    Aug 2008
    Posts
    7

    Default org.springframework.transaction.compensating.suppo rt.compensatingTransactionUtils

    Hi Ulsa,

    Thanks for your directions. We have modified the code for the process of initializing the spring context as pasted below snippet. Again,
    During our debug we found that code snippet# 2 of Spring Framework has something to do with the phase of recording operation during
    an LDAP call.

    We can clearly check the variable state that transactionResourceHolder is always null which inturn is not letting the recording happen
    in the lifecycle of events as described in Spring LDAP documentation. Please advise if we can do anything else via this declarative
    approach.


    Code:
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy;
    
    import com.adt.business.service.adminsecurity.AdminSecurityService;
    
    public class AdminServiceProxy {
    
    public static  ApplicationContext _serviceContext= null;
    
    private static void initialize()
    {
    	_serviceContext = new ClassPathXmlApplicationContext(new String[]{"springconfig.xml"});
    }
    
    static{
    	initialize();
    }
    
    public static AdminSecurityService getAdminSecurityService(){
    
    	return (AdminSecurityService)_serviceContext.getBean("myDataAccessObject");
    }
    
    public static TransactionAwareContextSourceProxy getTransactionProxyClass(){
    	 return (TransactionAwareContextSourceProxy)_serviceContext.getBean("ContextSource");
     }
     
    }
    Code:
      public static void performOperation(Object synchronizationKey,
                Object target, Method method, Object[] args) throws Throwable {
            CompensatingTransactionHolderSupport transactionResourceHolder = (CompensatingTransactionHolderSupport) TransactionSynchronizationManager
                    .getResource(synchronizationKey);
            if (transactionResourceHolder != null) {
    
                CompensatingTransactionOperationManager transactionOperationManager = transactionResourceHolder
                        .getTransactionOperationManager();
                transactionOperationManager.performOperation(
                        transactionResourceHolder.getTransactedResource(), method
                                .getName(), args);
            } else {
                // Perform the target operation
                try {
                    method.invoke(target, args);
                } catch (InvocationTargetException e) {
                    throw e.getTargetException();
                }
            }
        }

  6. #6
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    Could the following line in your test code have anything to do with it?

    Code:
       } catch (Exception ee){}
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  7. #7
    Join Date
    Aug 2008
    Posts
    7

    Default LDAP Transactions continued

    No, I just edited that catch block and there is nothing special in it.

  8. #8
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    Does the method saveUserGroupChanges belong to AdminSecurityServiceImpl?
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  9. #9
    Join Date
    Aug 2008
    Posts
    7

    Default The problem is resolved

    Hi Ulsa,

    Thanks for the inputs. Actually the method you mentioned is part of the Impl class itself. I just realised that the testCase i used to test the transaction is incorrect. I am throwing an application specific exception during successive bind call but did not realize the transaction manager could not understand to rollback.

    I tested the same test case removing the exception and generated exception by giving incorrect parameters during the bind call and it worked. It rolled back successfully.

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •