response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
// Extract request json message
UserConfiguration newConfig = null;
try {
newConfig = UserConfiguration.decode(request.getInputStream());
}
catch (Exception ex) {
getServletContext().log("Cannot decode POSTed configuration parameters", ex);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
// Persist the session configuration into database
EntityManager em = ModelFactory.getEntityManager();
EntityTransaction tx = null;
try {
tx = em.getTransaction();
tx.begin();
user = em.find(User.class, user.getUserName());
UserConfiguration oldConfig = user.getConfiguration();
if (oldConfig != null) {
oldConfig.update(newConfig);
em.merge(oldConfig);
}
else {
em.persist(newConfig);
}