private StringBuffer readMessages(final String xpath) { final StringBuffer sb = new StringBuffer(); final List errs = doc.selectNodes(xpath); if (null != errs) { for (final Object err : errs) { final Node node = (Node) err; if (sb.length() > 0) { sb.append("\n"); } sb.append(node.getStringValue()); logger.error("\t" + node.getStringValue()); } } return sb; }
/** * Validate the response is in expected envlope form with <result> content. * * @param response response * @return Envelope if format is correct and there is no error * @throws com.dtolabs.rundeck.core.dispatcher.CentralDispatcherException if the format is * incorrect, or the Envelope indicates an error response. */ private Envelope validateResponse(final WebserviceResponse response) throws CentralDispatcherException { if (null == response) { throw new CentralDispatcherServerRequestException("Response was null"); } if (null != response.getResponseMessage()) { logger.info("Response: " + response.getResponseMessage()); } final Document resultDoc = response.getResultDoc(); if (null == resultDoc) { throw new CentralDispatcherServerRequestException( "Response content unexpectedly empty. " + (response.getResponseMessage() != null ? response.getResponseMessage() : "")); } try { logger.debug(serialize(resultDoc)); } catch (IOException e) { logger.debug("ioexception serializing result doc", e); } if (!"result".equals(resultDoc.getRootElement().getName())) { throw new CentralDispatcherServerRequestException( "Response had unexpected content: " + resultDoc); } final Envelope envelope = new Envelope(response.getResultDoc()); if (envelope.isErrorResult()) { final StringBuffer sb = new StringBuffer(); final StringBuffer buffer = envelope.errorMessages(); if (buffer.length() > 0) { sb.append(buffer); } else { sb.append("Server reported an error"); if (null != response.getResponseMessage()) { sb.append(": ").append(response.getResponseMessage()); } } if (null != response.getResponseMessage()) { logger.error("Server reported an error: " + response.getResponseMessage()); } else { logger.error("Server reported an error."); } throw new CentralDispatcherFailureResponseException(sb.toString()); } return envelope; }