Topic
  • 6 replies
  • Latest Post - ‏2014-04-30T09:58:06Z by yoga1290
snehamandre
snehamandre
31 Posts

Pinned topic Null pointer Error in Ajax login in websphere commerce

‏2012-11-26T10:45:21Z |
Hi,

I am implementing ajax login in websphere commerce. Below is the code in controller command,

public void performExecute() throws ECException {
String result ="Success";
String sessionId = "";
String logsessionId = "";
TypedProperty resProperty = new TypedProperty();
try{
ViewCommandContext context = (ViewCommandContext) getCommandContext();
LogonCmd mylogon = (LogonCmd)CommandFactory.createCommand("com.ibm.commerce.security.commands.LogonCmd", getStoreId());
mylogon.setCommandContext(context);
mylogon.setLogonId(super.requestProperties.getString("logonId"));
mylogon.setLogonPassword(super.requestProperties.getString("logonPassword"));
System.out.println(super.requestProperties.getString("reLogonURL"));
System.out.println(super.requestProperties.getString("URL"));
mylogon.setReLogonURL(super.requestProperties.getString("reLogonURL"));
mylogon.setPostLogonURL(super.requestProperties.getString("URL"));
try{
mylogon.execute();
}catch(Exception e1){
e1.printStackTrace();
}finally{
if(context.getUser().getRegisterType().equalsIgnoreCase("G"))
result="login fail";
logsessionId = context.getUniqueSessionTag();
sessionId = ((com.ibm.commerce.webcontroller.HttpControllerRequestObject) context.getRequest()).getHttpRequest().getSession().getId();
}
//super.execute();
}catch(Exception e){
e.printStackTrace();
System.out.println("in second catch");
}
resProperty.put("result", result);
resProperty.put("sessionId", sessionId);
resProperty.put("logsessionId", logsessionId);
setResponseProperties(resProperty);
}

I am able to login successfully but if login is successfull I am getting null pointer exception after mylogon.execute(). Can anybody tell me how to avoid this exception.

Thanks in advance,
Sneha
Updated on 2013-02-12T17:29:12Z at 2013-02-12T17:29:12Z by snehamandre
  • Raj.S
    Raj.S
    533 Posts

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2012-11-26T12:49:05Z  
    I do not see the snippet to set the requestproperties. If your request has the parameters logonId, logonPassword, reLogonURL, URL with none of them as NULL, this should not throw a NullPointer.

    LogonCmd mylogon = (LogonCmd)CommandFactory.createCommand(LogonCmd.class.getName(), getStoreId());
    mylogon.setCommandContext(getCommandContext());
    mylogon.setRequestProperties(super.getRequestProperties());
    mylogon.execute();
    Also, why are you explicitly wrapping the commandcontext object to ViewCommandContext?
    Hope the code you have posted is a test code, please do not catch the runtime exceptions..
    Post the logs if you still face the exception.

    Regards,
    Raj
  • snehamandre
    snehamandre
    31 Posts

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2012-11-26T13:56:22Z  
    • Raj.S
    • ‏2012-11-26T12:49:05Z
    I do not see the snippet to set the requestproperties. If your request has the parameters logonId, logonPassword, reLogonURL, URL with none of them as NULL, this should not throw a NullPointer.

    LogonCmd mylogon = (LogonCmd)CommandFactory.createCommand(LogonCmd.class.getName(), getStoreId());
    mylogon.setCommandContext(getCommandContext());
    mylogon.setRequestProperties(super.getRequestProperties());
    mylogon.execute();
    Also, why are you explicitly wrapping the commandcontext object to ViewCommandContext?
    Hope the code you have posted is a test code, please do not catch the runtime exceptions..
    Post the logs if you still face the exception.

    Regards,
    Raj
    Thank you so much for the reply. I was getting the null pointer exception because I was wrapping the commandcontext object to ViewCommandContext. The exception is not coming after removing it.

    Regards,
    Sneha
  • snehamandre
    snehamandre
    31 Posts

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2013-02-11T12:19:41Z  
    Thank you so much for the reply. I was getting the null pointer exception because I was wrapping the commandcontext object to ViewCommandContext. The exception is not coming after removing it.

    Regards,
    Sneha
    Hi,
    I want to create a webservice by which I want to logon into websphere commerce from an other domain say my localhost. Is it possible to do that? I want to use Ajax in this case.

    Anybody has idea how to do it.

    Thanks in advance,
    Sneha
  • Raj.S
    Raj.S
    533 Posts

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2013-02-12T04:45:57Z  
    Hi,
    I want to create a webservice by which I want to logon into websphere commerce from an other domain say my localhost. Is it possible to do that? I want to use Ajax in this case.

    Anybody has idea how to do it.

    Thanks in advance,
    Sneha
    Hi Sneha,

    This should be possible with the help of member services. Could you try ProcessPerson with "AuthenticatePassword" as action code.
    The following link gives you the request and response xml formats

    http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.services.doc/Member/Person/noun.htm

    Rgds,Raj.
  • snehamandre
    snehamandre
    31 Posts

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2013-02-12T17:29:12Z  
    • Raj.S
    • ‏2013-02-12T04:45:57Z
    Hi Sneha,

    This should be possible with the help of member services. Could you try ProcessPerson with "AuthenticatePassword" as action code.
    The following link gives you the request and response xml formats

    http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.services.doc/Member/Person/noun.htm

    Rgds,Raj.
    Hi Raj,

    Thanks for the reply. I was following below document for creating webservice

    http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.webservices.doc%2Ftutorial%2Ftwvinboundws_2a.htm

    Bu when I tried to generate Java bean Skeleton, it did not create any entry in ibm-webservices-bnd.xmi, ibm-webservices-ext.xmi, webservices.xml. Neither it created any mapping file like MyCompany-CustomerServices_mapping.xml. I did not get any error though.

    Can you help me in this.

    Thanks & regards,
    Sneha
  • yoga1290
    yoga1290
    1 Post

    Re: Null pointer Error in Ajax login in websphere commerce

    ‏2014-04-30T09:58:06Z  
    Hi Raj,

    Thanks for the reply. I was following below document for creating webservice

    http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.webservices.doc%2Ftutorial%2Ftwvinboundws_2a.htm

    Bu when I tried to generate Java bean Skeleton, it did not create any entry in ibm-webservices-bnd.xmi, ibm-webservices-ext.xmi, webservices.xml. Neither it created any mapping file like MyCompany-CustomerServices_mapping.xml. I did not get any error though.

    Can you help me in this.

    Thanks & regards,
    Sneha

    If CORS is your problem, then this might help, I've tried it b4:
     

    HttpServletResponse response = (HttpServletResponse) (getCommandContext().getResponse());
       response.setHeader("Access-Control-Allow-Origin", "*");