Since the official methods I have seen so far seem inefficient for this part of the project, I used the following method to set two cookies to make the project work:
String cookieHeader = "ESPSESSIONID=" + sessionId + "; Path=/; Expires=" + expires + "; HttpOnly\r\n"
"Set-Cookie: UserRole=" + role + "; Path=/; Expires=" + expires;
response->addHeader("Set-Cookie", cookieHeader);