java - How to make the following code in alfresco work properly? -


i have created class name createuserhandler in alfresco in order generate username , random password email address. getting exception in this..please me this...

public class createuserhandler {      private static logger logger = loggerfactory.getlogger(createuserhandler.class);      private nodeservice nodeservice = getserviceregistry().getnodeservice();      private personservice personservice = getserviceregistry()                 .getpersonservice();      private actionservice actionservice = getserviceregistry()                 .getactionservice();      private searchservice searchservice = getserviceregistry()                 .getsearchservice();          private policycomponent eventmanager;         private serviceregistry serviceregistry;         //private string username;          public void setserviceregistry(serviceregistry serviceregistry) {             this.serviceregistry = serviceregistry;         }          private serviceregistry getserviceregistry() {             // todo auto-generated method stub             return null;         }          public void setpolicycomponent(policycomponent policycomponent) {             this.eventmanager = policycomponent;         }          public void registereventhandlers() {             eventmanager.bindclassbehaviour(                     nodeservicepolicies.oncreatenodepolicy.qname,                     contentmodel.type_user,                     new javabehaviour(this, "onadduser",                             behaviour.notificationfrequency.every_event));           }         protected string username = null;         protected string password = null;         /**          * user password          * @return user password          */         public string getpassword() {            return password;         }          /**          * set user password          * @param password user password          */         public void setpassword(string password) {            this.password = password;         }           public void onadduser(childassociationref parentchildassocref) {             //new personservice().setpersonproperties(username, properties);             system.out.println("creation of user completed");              //noderef usernoderef;             // string stempusername = this.username;             noderef person = null;              string username = (string) serviceregistry.getnodeservice().getproperty(person,contentmodel.prop_username);                         system.out.println("username got :" + username);                        if (personservice.personexists(username)) {                              //noderef person = personservice.getperson(stempusername);                           person = personservice.getperson(username);                              string address = (string) nodeservice.getproperty(person,                                          contentmodel.prop_email);                              if (address != null && address.length() != 0) {                                    // recipients.add(address);                                    system.out.println("email address :" + address);                                   string newpassword = password.generatepassword();                                    char[] cadchars = new char[newpassword.length()];                                    (int i=0; i<newpassword.length(); i++)                                    {                                      cadchars[i] = newpassword.charat(i);                                   }                                   // save new password                                    serviceregistry.getauthenticationservice().setauthentication(username, newpassword.tochararray());                                   // save new password                                    setpassword(newpassword);                                    system.out.println("password :" + newpassword);                              }                        }                 }     } 

i attaching log stack-trace of null-pointer exception:

nov 10, 2016 4:46:33 pm org.apache.catalina.core.standardcontext listenerstart severe: exception sending context initialized event listener instance of class org.alfresco.repo.webdav.webdavsessionlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'com.eisenvault.automailgenerate.createuserhandler' defined in class path resource [alfresco/module/demoact1-repo/context/service-context.xml]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.eisenvault.automailgenerate.createuserhandler]: constructor threw exception; nested exception java.lang.nullpointerexception     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1038)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:984)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:487)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:293)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:290)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:191)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:633)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479)     @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:410)     @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306)     @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112)     @ org.alfresco.web.app.contextloaderlistener.contextinitialized(contextloaderlistener.java:63)     @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4939)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5434)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549)     @ java.util.concurrent.futuretask.run(futuretask.java:266)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)     @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.eisenvault.automailgenerate.createuserhandler]: constructor threw exception; nested exception java.lang.nullpointerexception     @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:163)     @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:87)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1031)     ... 23 more caused by: java.lang.nullpointerexception     @ com.eisenvault.automailgenerate.createuserhandler.<init>(createuserhandler.java:30)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     @ java.lang.reflect.constructor.newinstance(constructor.java:422)     @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:148)     ... 25 more 

this because of

    private serviceregistry getserviceregistry() {         // todo auto-generated method stub         return null;     } 

and

 private personservice personservice = getserviceregistry()             .getpersonservice(); 

as result npe thrown.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -