cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
981
Views
0
Helpful
3
Replies
mitshett
Cisco Employee

How to create new transaction when getTransaction is returning -1 . i am using java to create a action which would be called through rest api

 
1 ACCEPTED SOLUTION

Accepted Solutions
mvolf
Cisco Employee

This is described in NSO documentation, book Development, chapter Java API overview/MAAPI:

 

    maapi.startUserSession("admin",
                           InetAddress.getByName("localhost"),
                           "maapi",
                           new String[] {"admin"},
                           MaapiUserSessionFlag.PROTO_TCP);

 

    int th = maapi.startTrans(Conf.DB_RUNNING,
                              Conf.MODE_READ_WRITE);

Your needs may vary a bit, e.g. you may want to use the username from the action context, or you need READ_ONLY transaction, etc.

View solution in original post

3 REPLIES 3
mvolf
Cisco Employee

This is described in NSO documentation, book Development, chapter Java API overview/MAAPI:

 

    maapi.startUserSession("admin",
                           InetAddress.getByName("localhost"),
                           "maapi",
                           new String[] {"admin"},
                           MaapiUserSessionFlag.PROTO_TCP);

 

    int th = maapi.startTrans(Conf.DB_RUNNING,
                              Conf.MODE_READ_WRITE);

Your needs may vary a bit, e.g. you may want to use the username from the action context, or you need READ_ONLY transaction, etc.

View solution in original post

Thank you very much

I want to take the opportunity to warn a little against starting user sessions from code. Because in this case you are hardcoding the username ‘admin’ into your code. This will work in local installs, but not by default in system installs. If you want to start user-sessions you need to make sure that the code always uses an appropriate user-name!