cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1490
Views
0
Helpful
3
Replies

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

mitshett
Cisco Employee
Cisco Employee
1 Accepted Solution

Accepted Solutions

mvolf
Cisco Employee
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
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.

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!