public void handle(Throwable t, HttpRequest request, HttpResponder responder) { if (t instanceof HandlerException) { HandlerException handlerException = (HandlerException) t; responder.sendString(handlerException.getFailureStatus(), handlerException.getMessage()); } else { String message = String.format("Exception encountered while processing request : %s", t.getMessage()); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, message); } }
private String dispatch(Document document, HandlerContext handlercontext) throws RequestFailureException, SAXException { StringBuilder results = new StringBuilder("<?xml version=\"1.0\"?><results>"); NodeList nodes = document.getFirstChild().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { try { if ("audit".equals(nodes.item(i).getNodeName())) { continue; } if ("#text".equals(nodes.item(i).getNodeName())) { // Noeud ajoute lorsque le manager est execute dans le container. continue; } String id = XMLUtils.getNodeValue(nodes.item(i), "id"); Handler handler = getHandler(id); handler.setContext(handlercontext); if (!handlercontext.isAllowedTo(id)) { throw new SecurityException( "Vous n'avez pas les droits pour effectuer ce traitement (" + id + ")"); } fireHandlerStarted(handlercontext, handler); String result = handler.proceed(nodes.item(i)); fireHandlerStopped(handlercontext, handler); results.append(result); } catch (HandlerException handlerException) { Exception cause = handlerException; if (handlerException.getCausedBy() != null && handlerException.getMessage() == null) { cause = handlerException.getCausedBy(); } throw new RequestFailureException( XMLUtils.getAttribute(nodes.item(i), "request_id"), cause); } catch (Exception exception) { throw new RequestFailureException( XMLUtils.getAttribute(nodes.item(i), "request_id"), exception); } } return results.append("</results>").toString(); }