on 2025 Feb 05 7:55 AM
Hi,
I am using sap bo rest apis in my C# application.
The user get token and requests the relevant services to access the data, but a user can have more than one session or a session can be open for a long time, which causes the system to crash. How can I kill these sessions for a certain period of time with Sap Bo Rest API?
Request clarification before answering.
I checked the Platform REST API docs and I don't believe it's possible with the REST API.
A while back I created a Java program object to do this, because we had a big problem with sessions not being closed. You might be able to adapt it to your needs. The heart of the code is:
long minsThreshold;
try
{
minsThreshold = Long.parseLong(args[0]) * 60;
}
catch (NumberFormatException nfe)
{
throw new Exception("Invalid value in arguments -- expected integer specifying number of hours for purge: " + args[0]);
}
System.out.println("Threshhold is: " + minsThreshold);
IInfoObjects boInfoObjects = oInfoStore.query("select si_id, si_name, si_creation_time,si_cuid from ci_systemobjects where si_kind='Connection' and si_parentid=41 and si_name not in ('QaaWSServletPrincipal','System Account') and SI_AUTHEN_METHOD != 'server-token' and SI_FAILOVER_AVAILABLE_UNTIL is null");
for (int i = 0; i < boInfoObjects.size(); i++)
{
IInfoObject io = (IInfoObject) boInfoObjects.get(i);
IProperties properties = io.properties();
String siName = io.getTitle();
Date dateCreate = properties.getDate("SI_CREATION_TIME");
if(!userInfos.containsKey(siName))
userInfos.put(siName, new UserInfo(siName));
try
{
Date dateNow = new Date();
if (dateCreate.getTime() < dateNow.getTime())
{
long differenceInMilliSecs = dateNow.getTime() - dateCreate.getTime();
long differenceInMins = differenceInMilliSecs / 1000L / 60L;
if (differenceInMins >= (long) minsThreshold)
{
userInfos.get(siName).addSession(dateCreate);
System.out.println("Deleting session for user: " + siName + ", created: " + sdf.format(dateCreate) + ", session CUID: " + io.getCUID());
boInfoObjects.delete(io);
delCount++;
}
}
}
catch (Exception e)
{
System.out.println("Error killing session: " + e.getMessage());
}
}
oInfoStore.commit(boInfoObjects);
System.out.println("Deleted " + delCount + " sessions.");
for(UserInfo userInfo : userInfos.values())
if(userInfo.getSessionCount() > 0 )
System.out.println(userInfo.format());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.