do not break if userprofile store can not be found

This commit is contained in:
Jörg Prante 2024-06-05 14:34:54 +02:00
parent 7d8205dd7a
commit f0d743642a
2 changed files with 15 additions and 17 deletions

View file

@ -1,3 +1,3 @@
group = org.xbib
name = net-http
version = 4.7.0
version = 4.7.1

View file

@ -108,16 +108,7 @@ public class IncomingContextHandler implements HttpHandler {
// important
context.getAttributes().put("session", session);
if (userProfile == null) {
try {
userProfile = recoverUserProfile(context, session, payload);
if (userProfile != null) {
logger.log(Level.FINE, "user profile recovered");
} else {
logger.log(Level.FINE, "no user profile recovered");
}
} catch (IOException e) {
logger.log(Level.FINE, "unable to recover new user profile: " + e.getMessage(), e);
}
userProfile = recoverUserProfile(context, session, payload);
}
// important
context.getAttributes().put("userprofile", userProfile);
@ -178,25 +169,32 @@ public class IncomingContextHandler implements HttpHandler {
@SuppressWarnings("unchecked")
protected UserProfile recoverUserProfile(HttpRouterContext context,
Session session,
Map<String, Object> payload)
throws IOException {
Map<String, Object> payload) {
// already in context from previous handler?
UserProfile userProfile = context.getAttributes().get(UserProfile.class, "userprofile");
if (userProfile != null) {
return userProfileCodec.read(userProfile.getUserId());
try {
return userProfileCodec.read(userProfile.getUserId());
} catch (IOException e) {
// ignore I/O error, leads to empty user profile
}
}
// initialize
Map<String, Object> map = null;
// from session?
// is user profile present in session?
if (payload == null && session != null) {
// session has stored user profile? this is important for spanning HTTP request/response like in HTTP POST/FORWARD/GET
map = (Map<String, Object>) session.get("userprofile");
} else if (payload != null) {
// otherwise from cookie?
// is a mini user profile otherwise present in our cookie?
map = (Map<String, Object>) payload.get("map");
}
if (map != null && map.containsKey(UserProfile.USER_ID)) {
return userProfileCodec.read(BaseUserProfile.fromMap(map).getUserId());
try {
return userProfileCodec.read(BaseUserProfile.fromMap(map).getUserId());
} catch (IOException e) {
// ignore I/O error, leads to incomplete user profile
}
} else {
logger.log(Level.FINE, "unable to find info for initialize user profile");
}