/** * {@inheritDoc} */ @Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String endpoint = StringUtils.substringAfter(req.getPathInfo(), "/clients/"); if (StringUtils.isEmpty(endpoint)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } LOG.debug("Removing security info for end-point {}", endpoint); if (this.store.remove(endpoint) != null) { resp.sendError(HttpServletResponse.SC_OK); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } }
/** * {@inheritDoc} */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] path = StringUtils.split(req.getPathInfo(), '/'); if (path.length != 1 && "clients".equals(path[0])) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } try { SecurityInfo info = gsonDes.fromJson(new InputStreamReader(req.getInputStream()), SecurityInfo.class); LOG.debug("New security info for end-point {}: {}", info.getEndpoint(), info); store.add(info); resp.setStatus(HttpServletResponse.SC_OK); } catch (NonUniqueSecurityInfoException e) { LOG.warn("Non unique security info: " + e.getMessage()); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().append(e.getMessage()).flush(); } catch (JsonParseException e) { LOG.warn("Could not parse request body", e); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().append("Invalid request body").flush(); } catch (RuntimeException e) { LOG.warn("unexpected error for request " + req.getPathInfo(), e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
Collection<SecurityInfo> infos = this.store.getAll();