CRecordSessionGetLongToken
nyssr.net supports two types of session tokens: a long token with data and a short token without data. If you want to exchange a short token for a long token, this message can be used to retrieve the long token from the SessionManager.
This message belongs to the session manager API.
It is part of the kernel.
{
"id": "bb156b98-b587-4e47-8c3a-eba8f1f512b8",
"name": "SESSION_GET_LONG_TOKEN",
"description": "Get a long session token with a short session token.",
"slots": [
{
"key": "1",
"name": "SHORT_TOKEN",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "BYTE_ARRAY",
"description": "The short session token."
},
{
"key": "10",
"name": "LONG_TOKEN",
"direction": "RESPONSE",
"presenceConstraint": "OPTIONAL",
"type": "BYTE_ARRAY",
"description": "The long session token."
}
]
}
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IId SESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");
To fetch the long token, we need the short token. The short token must be valid.
private void getLongToken(final byte[] aToken) throws CException
{
final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);
final CRecord record = CRecordSessionGetLongToken.create();
CRecordSessionGetLongToken.setShortToken(record,
aToken);
sendRequest(env,
record);
}
Dealing with the response
To catch the response of the request, we need a message handler. We add it in the constructor of the message handler registry.
// constructor:
addMessageHandler(CRecordSessionGetLongToken.ID,
this::asyncGetLongToken);
private boolean asyncGetLongToken(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
final int resultCode = aEnvelope.getResultCode();
if (resultCode == CResultCode.SUCCESS)
{
final byte[] token = CRecordSessionGetLongToken.getLongToken(aRecord,
null);
// ...
}
return true;
}
return false;
}