Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 32

Thread: LDAP Transactions

  1. #21
    Join Date
    Jul 2007
    Posts
    22

    Default

    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)

  2. #22
    Join Date
    Jul 2007
    Posts
    22

    Default

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

  3. #23
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    When creating a ContextSource programmatically you need to call afterPropertiesSet once you're done setting the properties. That might account for the IllegalArgumentException.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  4. #24
    Join Date
    Jul 2007
    Posts
    22

    Default

    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.

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

    Default

    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?
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  6. #26
    Join Date
    Jul 2007
    Posts
    22

    Default

    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 at 11:51 AM.

  7. #27
    Join Date
    Aug 2008
    Posts
    7

    Default 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?

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

    Default

    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?
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

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

    Default

    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.
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  10. #30
    Join Date
    Aug 2008
    Posts
    7

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

Posting Permissions

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