Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
john john
regarding PrefsPropsUtil.getString is getting NullPointer Exception...
January 10, 2013 10:32 AM
Answer

john john

Rank: New Member

Posts: 23

Join Date: December 17, 2012

Recent Posts

Hi ,

I am overriding the method completeUserRegistration of UserLocalServiceImpl class by creating a hook..

this method which intern calling send sendEmail method...

in this method i am getting NullPointerException at this line

String fromName = PrefsPropsUtil.getString(user.getCompanyId(), "admin.email.from.name");




Did any one faced same problem..

Please help me i got stuck at the moment..
David H Nebinger
RE: regarding PrefsPropsUtil.getString is getting NullPointer Exception...
January 10, 2013 6:36 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11056

Join Date: September 1, 2006

Recent Posts

It's probably an NPE on the company id. If you haven't saved the user or if no company was assigned, it may be a null Integer that is getting autoboxed to an int for the method call.
john john
RE: regarding PrefsPropsUtil.getString is getting NullPointer Exception...
January 10, 2013 11:58 PM
Answer

john john

Rank: New Member

Posts: 23

Join Date: December 17, 2012

Recent Posts

Hi David,

Thanks for your replay...before getting NPE I just investigated that my custom hook is not able to find out PwdToolkitUtil i am getting the following error.
java.lang.NoClassDefFoundError: com/liferay/portal/security/pwd/PwdToolkitUtil...
as this class is inside portalImpl.jar which is there in liferay war file,do i need to copy this jar in classpath of tomcat or the custom-hook.war,but i am not sure this is the correct way.please advise the best practice.

Basically I am trying to override completeUserRegistration() method so that i can send email with custom verification link after user creation done,through programmatically/api
so i am overriding the following method..
Hence i have created hook extending
 1
 2public class SampleWrapperUserLocalServiceImpl extends UserLocalServiceWrapper {
 3@Override
 4      public void completeUserRegistration(User user, ServiceContext serviceContext)
 5         
 6          throws PortalException, SystemException
 7            {
 8       
 9                System.out.println("i am in custom completeRegistration");
10               
11                super.completeUserRegistration(user, serviceContext);
12                  System.out.println("################Ï am in completeUserRegistration##################1 ");
13                  
14                  System.out.println("################user.getCompanyId##################2 "+user.getCompanyId());
15                  
16                  System.out.println("################user.getCompanyId##################serviceContext.getPlid() "+serviceContext.getPlid());
17                  
18                  System.out.println("################user.getCompanyId##################user.hasCompanyMx() "+user.hasCompanyMx());
19                   boolean sendEmail = GetterUtil.getBoolean(serviceContext.getAttribute("sendEmail"));
20                  System.out.println("################sendEmail##################sendEmail "+sendEmail);
21                  
22              //    super.completeUserRegistration(user, serviceContext);
23                boolean autoPassword = GetterUtil.getBoolean(serviceContext.getAttribute("autoPassword"));
24                String password = null;
25               if(autoPassword)
26                {
27                   // PasswordPolicy passwordPolicy = passwordPolicyLocalService.getPasswordPolicy(user.getCompanyId(), user.getOrganizationIds());
28                    PasswordPolicy passwordPolicy=PasswordPolicyLocalServiceUtil.getPasswordPolicy(user.getCompanyId(), user.getOrganizationIds());
29        //here below line code is failing            
30[b]                    password = PwdToolkitUtil.generate(passwordPolicy);[/b]
31                    user.setPassword(PwdEncryptor.encrypt(password));
32                    user.setPasswordEncrypted(true);
33                    user.setPasswordUnencrypted(password);
34                    UserUtil.getPersistence().update(user, false);
35                    //userPersistence.update(user, false);
36                }
37                if(user.hasCompanyMx())
38                {
39                    String mailPassword = password;
40                    if(Validator.isNull(mailPassword))
41                        mailPassword = user.getPasswordUnencrypted();
42                    MailServiceUtil.addUser(user.getCompanyId(), user.getUserId(), mailPassword, user.getFirstName(), user.getMiddleName(), user.getLastName(), user.getEmailAddress());
43                    System.out.println("################user.hasCompanyMx()##################2 "+user.hasCompanyMx());
44                }
45           //  boolean sendEmail = GetterUtil.getBoolean(serviceContext.getAttribute("sendEmail"));
46             // if(sendEmail)
47                  // sendEmail(user, password, serviceContext);
48             
49             // Company company=CompanyUtil.getPersistence().findByPrimaryKey(user.getCompanyId());
50             
51             
52          //    if(company.isStrangersVerify() && serviceContext.getPlid() > 0L)
53                  // super.sendEmailAddressVerification(user, user.getEmailAddress(), serviceContext) ;
54
55
56}




Please suggest if i am doing wrong.... i am using liferay6.1.1ga2 and tomcat 7.0.27.

Based on the error

do i need any specific jar to be included ..

Appreciate your help.Thanks in Advance.
Tejas Kanani
RE: regarding PrefsPropsUtil.getString is getting NullPointer Exception...
January 11, 2013 1:35 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 655

Join Date: January 6, 2009

Recent Posts

Hi John,

AFAIK, you can do below thing. And not sure if there is any other alternative approach to deal with this issue.
PwdToolkitUtil.generate(passwordPolicy);

In your case, PwdToolkitUtil is in portal-impl so you will not be able to access it directly and giving reference of portal-impl.jar is not advisable.
So either you can write the same logic inside your overridden class which actually does generates password.

Check generate(PasswordPolicy passwordPolicy) method from com.liferay.portal.security.pwd.PasswordPolicyToolkit class which is actually getting called at last.
So you can copy that method inside your class and call the same instead of PwdToolkitUtil.generate(passwordPolicy).

But this is the one place, going ahead you'll also get the same error for PwdEncryptor on next line. So you'll have to do similar thing for that as well.

Thanks,
Tejas