Skip to Content
avatar image
Former Member

MDM java API

Hi,

I am using the below code for searching in MDM repository. But I am getting null pointer exception.

ConnectionAccessor simpleConnection = null;

String connection = "servername";

//AuthenticateServerSessionCommand testAuthenticateUserSession;

RepositorySchema repositorySchema;

String session;

String repository = "repository name";

String str = "Table name";

String tabId;

int totalRecord;

DBMSType dbmsType = DBMSType.ORACLE;

RepositoryIdentifier repIdentifier;

RegionProperties regionProperties = new RegionProperties();

regionProperties.setLocale(Locale.ENGLISH);

regionProperties.setName("English US");

regionProperties.setRegionCode("engUSA");

wdComponentAPI.getMessageManager().reportSuccess("test1");

try {

simpleConnection = SimpleConnectionFactory.getInstance(connection);

repIdentifier = new RepositoryIdentifier(repository, connection, dbmsType);

RegionProperties dataRegion=regionProperties;

CreateUserSessionCommand createUserSessionCommand = new CreateUserSessionCommand(simpleConnection);

createUserSessionCommand.setRepositoryIdentifier(repIdentifier);

createUserSessionCommand.setDataRegion(dataRegion);

wdComponentAPI.getMessageManager().reportSuccess("test2");

try {

createUserSessionCommand.execute();

} catch (CommandException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

session = createUserSessionCommand.getUserSession();

AuthenticateUserSessionCommand authenticateUserSessionCmd = new AuthenticateUserSessionCommand(simpleConnection);

authenticateUserSessionCmd.setSession(session);

authenticateUserSessionCmd.setUserName("Admin");

authenticateUserSessionCmd.setUserPassword("");

try {

authenticateUserSessionCmd.execute();

} catch (CommandException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

GetRepositorySchemaCommand getRepositorySchemaCommand = new GetRepositorySchemaCommand(simpleConnection);

getRepositorySchemaCommand.setSession(session);

try {

getRepositorySchemaCommand.execute();

} catch (CommandException e3) {

// TODO Auto-generated catch block

e3.printStackTrace();

}

repositorySchema = getRepositorySchemaCommand.getRepositorySchema();

TableId tableId= repositorySchema.getTable("Products").getId();

FieldId[] fields = new FieldId[2];

fields[0] = repositorySchema.getFieldId("Products", "Name");

fields[1] = repositorySchema.getFieldId("Products", "Father's Name");

FieldSearchDimension fieldSearchDimension = new FieldSearchDimension(fields[1]);

TextSearchConstraint textSearchConstraint = new TextSearchConstraint("john", TextSearchConstraint.EQUALS);

FieldSearchDimension fieldSearchDimension1 = new FieldSearchDimension(fields[0]);

TextSearchConstraint textSearchConstraint1 = new TextSearchConstraint("test", TextSearchConstraint.EQUALS);

Search search = new Search(tableId);

search.addSearchItem(fieldSearchDimension, textSearchConstraint);

search.addSearchItem(fieldSearchDimension1, textSearchConstraint1);

ResultDefinition rd = new ResultDefinition(tableId);

rd.setSelectFields(fields);

RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(simpleConnection);

retrieveLimitedRecordsCommand.setSession(authenticateUserSessionCmd.getSession());

retrieveLimitedRecordsCommand.setResultDefinition(rd);

retrieveLimitedRecordsCommand.setSearch(search);

try {

retrieveLimitedRecordsCommand.execute();

} catch (CommandException e4) {

// TODO Auto-generated catch block

e4.printStackTrace();

}

totalRecord = retrieveLimitedRecordsCommand.getRecords().getCount();

wdComponentAPI.getMessageManager().reportSuccess("records are"+totalRecord);

RecordResultSet records=retrieveLimitedRecordsCommand.getRecords();

for(int i=0; i<records.getCount(); i++)

{

Record record = records.getRecord(i);

//wdComponentAPI.getMessageManager().reportSuccess(""+record.getDisplayValue());

//System.out.println(record.getDisplayValue());

}

} catch (ConnectionException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

And the error i am getting is

java.lang.NullPointerException

at com.sap.mdm.internal.SessionConvertHelper.convertToLong(SessionConvertHelper.java:11)

at com.sap.mdm.commands.AuthenticateUserSessionCommand.execute(AuthenticateUserSessionCommand.java:62)

at com.sap.search.SearchView.onActionsubmit(SearchView.java:304)

at com.sap.search.wdp.InternalSearchView.wdInvokeEventHandler(InternalSearchView.java:160)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequest(WindowPhaseModel.java:132)

at com.sap.tc.webdynpro.clientserver.window.WebDynproWindow.processRequest(WebDynproWindow.java:335)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:143)

at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:319)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingStandalone(ClientSession.java:713)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:666)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:250)

at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:149)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:62)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:53)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)

Kindly suggest.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

11 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 16, 2009 at 09:44 AM

    Debugg your application.......by putting break point.....and see where you are getting this null pointer

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 09:58 AM

    Hi Jyothi,

    plz check the below points to rectify null pointer exception.

    1. user Session should not be null.

    2. repository name should be name of repository which exists in mdm

    3. please check before every .execute() method as this error comes when we pass some null value and then execute that command.

    Regards

    Narendra

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 10:18 AM

    Hi Jyothi,

    In continuation to what Narendra has told:

    Take care of parameters case as these are case sensitive.

    Regards.

    Rajat

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 12:55 PM

    Hi Narendra,

    if i print the repIdentifier from below code, It is giving me the repository name. So i think there is no problem with that. Kindly suggest

    repIdentifier = new RepositoryIdentifier(repository, connection, dbmsType);

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      RepositoryIdentifier just creates an instance. You provided the name in the constructor & hence the name is returned properly. It doesn't check against the MDM server.

      While using this code:

      SimpleConnectionFactory.getInstance(connection);
      

      are you only using the MDM server name or also the port? If you are only mentioning the server name are you sure that the server is running on the default port 20005? If it's not then you'll need to mention the port number like this "<server name>:<port number>" in the above mentioned code.

      Regards,

      Satyajit

  • avatar image
    Former Member
    Feb 16, 2009 at 10:05 AM

    Hi,

    I am getting null pointer exception at below piece of code. Kindly suggest me.

    authenticateUserSessionCmd.execute();

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 10:12 AM

    Hi,

    Please check the values of session and simpleConnection which you are passing for authentication of the use.I thinkone of the value is null.Also check if you are passing the correct userID and password.

    Regards

    Narendra

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 10:21 AM

    Hi Narendra,

    Thanks for the info...

    My session value is null...

    What could be the problem for this....How ll it be rectified. please suggest me if you have some idea.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 10:26 AM

    Hi Jyothi,

    /** Create the User Session */
    				CreateUserSessionCommand createUserSessionCommand =
    					new CreateUserSessionCommand(connections);
    				/** Set the repository identifier (mandatory)*/
    				createUserSessionCommand.setRepositoryIdentifier(repositoryID);
    				/** Set the region properties for the session (mandatory) */
    				createUserSessionCommand.setDataRegion(dataRegion);
    				createUserSessionCommand.execute();
    				/** Get the session identifier */
    				this.userSession = createUserSessionCommand.getUserSession();
    				AuthenticateUserSessionCommand authenticateUserSessionCommand =
    					new AuthenticateUserSessionCommand(connections);
    				/** Set session identifier (mandatory)*/
    				authenticateUserSessionCommand.setSession(userSession);
    				/** Set id of repository user(mandatory) */
    				authenticateUserSessionCommand.setUserName(userId);
    				/** Set password (mandatory)*/
    				authenticateUserSessionCommand.setUserPassword(passWord);
    				/** Establish the session */
    				authenticateUserSessionCommand.execute();
    
    

    Hope you understand now what is needed to be done.

    Regards.

    Rajat

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 10:37 AM

    Hi Rajat,

    I had used the same code...

    please see the code i have given in the beginning of the code....

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2009 at 11:11 AM

    I am getting the user session value as null....please suggest.

    Add comment
    10|10000 characters needed characters exceeded