Announcement Announcement Module
Collapse
No announcement yet.
Spring Ldap NewBiew connect to Tivoli Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Ldap NewBiew connect to Tivoli

    Hi guys and gongrats for this forum!

    I am newbie in Spring LDAP and trying to connect to IBM tivoli server.

    My Configuration is

    Code:
    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
            <property name="url" value="ldap://10.1.100.74:389" />
            <property name="base" value="o=aspisbank" />
            <property name="userDn" value="cn=root" />
            <property name="password" value="giannis" />
        </bean>
        <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
            <constructor-arg ref="contextSource" />
        </bean>
        <bean id="userService" class="gr.tbank.ebankingservice.impl.PersonDaoImpl">
                <property name="ldapTemplate" ref="ldapTemplate"/>
        </bean>
    and my class for making a search to retrieve all users is

    Code:
    public class PersonDaoImpl {
    
        public LdapTemplate ldapTemplate;
    
        public void setLdapTemplate(LdapTemplate ldapTemplate){
            this.ldapTemplate = ldapTemplate;
        }
    
        public List getAllPersonNames() {
            if(this.ldapTemplate == null)
                System.out.println("template not null");
    
            return this.ldapTemplate.search(
                    "", "(objectclass=*)",
                    new AttributesMapper() {
    
                        public Object mapFromAttributes(Attributes attrs)
                                throws NamingException {
                            return attrs.get("cn").get();
                        }
                    });
        }
    }
    But when I try to run this from a Controller (I use Spring MVC) I get a null pointer exception.

    Here is my controller method

    Code:
    //LdapTemplate ldapTemplate
        @RequestMapping(value = "/index", method = RequestMethod.GET)
        public String ldapQ(Model model) {
            logger.info("Accessing ldapQ in tokenController");
            PersonDaoImpl pdi = new PersonDaoImpl();
            List list = pdi.getAllPersonNames();
           
    
       logger.info(list.size());
            return ("/index");
        }
    And my Stack Trace

    Code:
    SEVERE: StandardWrapperValve[dispatcher]: PWC1406: Servlet.service() for servlet dispatcher threw exception
    java.lang.NullPointerException
            at gr.tbank.ebankingservice.impl.PersonDaoImpl.getAllPersonNames(PersonDaoImpl.java:29)
            at gr.tbank.ebankingservice.services.tokenService.ldapQ(tokenService.java:52)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:174)
            at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
            at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
            at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
            at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
            at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
            at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
            at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
            at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
            at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
            at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
            at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
            at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
            at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
            at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
            at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
            at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)

    Can you help out here my fellow Springers???

  • #2
    Don't create a new instance of the dao inject the one from the applicationcontext.

    Comment


    • #3
      So in plain English you mean ???

      Sorry mate but you write as a code so that I can understand what you mean because I am newbie?

      Comment


      • #4
        Well that is plain English .

        Code:
        //LdapTemplate ldapTemplate
        @RequestMapping(value = "/index", method = RequestMethod.GET)
        public String ldapQ(Model model) {
        	logger.info("Accessing ldapQ in tokenController");
        	PersonDaoImpl pdi = new PersonDaoImpl();
        	List list = pdi.getAllPersonNames();
        	logger.info(list.size());
        	return ("/index");
        }
        The red line creates a new instance of the dao... You should be using the one you configure int he applicationcontext. I suggest the forum search and a read of the spring reference guide.

        Comment


        • #5
          thanks mate!

          Comment


          • #7
            Code:
            return this.ldapTemplate.search(
                            "", "(objectclass=*)",
                            new AttributesMapper() {
            
                                public Object mapFromAttributes(Attributes attrs)
                                        throws NamingException {
                                    return attrs.get("cn").get();
                                }
                            });

            Comment

            Working...
            X