* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
getServletContext().log("-> SessionConfigurationSvr.doPost()\nParameters= " + request.getParameterMap().toString());
// Extract request parameters
SessionConfiguration newConfig = null;
try {
newConfig = SessionConfiguration.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();
SessionConfiguration oldConfig = null;
// search if old configuration exists, or create it
try {
TypedQuery<SessionConfiguration> query = em.createQuery(
"select config from SessionConfiguration config where config.user = ?1 and config.pwd = ?2", SessionConfiguration.class)
.setParameter(1, newConfig.getUser()).setParameter(2, newConfig.getPwd());
oldConfig = query.getSingleResult();
oldConfig.update(newConfig);
em.merge(oldConfig);
} catch (NoResultException ex) {
getServletContext().log("No directory data for: " + newConfig.getUser(), ex);
em.persist(newConfig);
}