/** * Handles POST requests. It retrieves a list of mails and generate requests to target resources. * * @param entity The representation of the mails list. * @throws ResourceException */ @Post public void acceptMails(Representation entity) throws ResourceException { // 1 - Get list of identifiers for the mails in the inbox final List<String> mailIdentifiers = getMailIdentifiers(); // 2 - Process the list of mails final List<String> mailsSuccessful = new ArrayList<String>(); final Map<String, String> mailsUnsuccessful = new HashMap<String, String>(); Representation mail; for (final String mailIdentifier : mailIdentifiers) { try { mail = getMail(mailIdentifier); if (mail != null) { this.resolver = getResolver(mailIdentifier, mail); callTarget(this.resolver); deleteMail(mailIdentifier); mailsSuccessful.add(mailIdentifier); } } catch (ResourceException e) { mailsUnsuccessful.put(mailIdentifier, e.getMessage()); } } // 3 - Set response for timer client getResponse().setEntity(getResponseRepresentation(mailsSuccessful, mailsUnsuccessful)); getResponse().setStatus(getResponseStatus(mailsSuccessful, mailsUnsuccessful)); }
protected String buildUploadFailedHtmlResponse(Throwable t, Request request, Response response) { try { handleException(request, response, t); } catch (ResourceException e) { getLogger().debug("Got error while uploading artifact", t); StringBuffer resp = new StringBuffer(); resp.append("<html>"); resp.append("<body>"); resp.append("<error>" + e.getMessage() + "</error>"); resp.append("</body>"); resp.append("</html>"); String forceSuccess = request.getResourceRef().getQueryAsForm().getFirstValue("forceSuccess"); if (!"true".equals(forceSuccess)) { response.setStatus(e.getStatus()); } return resp.toString(); } // We have an error at this point, can't get here return null; }