private Document checkInputStream(InputStream is) throws WPSClientException { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); try { Document doc = fac.newDocumentBuilder().parse(is); if(getFirstElementNode(doc.getFirstChild()).getLocalName().equals("ExceptionReport") && getFirstElementNode(doc.getFirstChild()).getNamespaceURI().equals(OGC_OWS_URI)) { try { ExceptionReportDocument exceptionDoc = ExceptionReportDocument.Factory.parse(doc); LOGGER.debug(exceptionDoc.xmlText(options)); throw new WPSClientException("Error occured while executing query", exceptionDoc); } catch(XmlException e) { throw new WPSClientException("Error while parsing ExceptionReport retrieved from server", e); } } return doc; } catch (SAXException e) { throw new WPSClientException("Error while parsing input.", e); } catch (IOException e) { throw new WPSClientException("Error occured while transfer", e); } catch (ParserConfigurationException e) { throw new WPSClientException("Error occured, parser is not correctly configured", e); } }
erDoc = ExceptionReportDocument.Factory.parse(doc); } catch (XmlException e1) { throw new WPSClientException("Error occured while parsing executeResponse", e);
private ExceptionReport parseExceptionReport_100(OperationResult result) throws XmlException { String requestResult = new String(result.getIncomingResult()); ExceptionReportDocument exceptionReportDocument = ExceptionReportDocument.Factory.parse(requestResult); String language = exceptionReportDocument.getExceptionReport().getLang(); String version = exceptionReportDocument.getExceptionReport().getVersion(); ExceptionReport exceptionReport = new ExceptionReport(version, language); ExceptionType[] exceptions = exceptionReportDocument.getExceptionReport().getExceptionArray(); for (ExceptionType exceptionType : exceptions) { String exceptionCode = exceptionType.getExceptionCode(); String[] exceptionMessages = exceptionType.getExceptionTextArray(); if ("ResponseExceedsSizeLimit".equalsIgnoreCase(exceptionCode)) { String errorMsg = Arrays.toString(exceptionMessages); errorMsg = errorMsg.replace("[", "").replace("]", ""); throw new ResponseExceedsSizeLimitException(errorMsg); } String locator = exceptionType.getLocator(); String sentRequest = result.getSendedRequest(); OWSException owsException = new OWSException(exceptionMessages, exceptionCode, sentRequest, locator); exceptionReport.addException(owsException); } return exceptionReport; }
/** * either an ExecuteResponseDocument or an InputStream if asked for RawData or an Exception Report * @param url * @param doc * @param rawData * @return * @throws WPSClientException */ private Object retrieveExecuteResponseViaPOST(String url, ExecuteDocument doc, boolean rawData) throws WPSClientException{ InputStream is = retrieveDataViaPOST(doc, url); if(rawData) { return is; } Document documentObj = checkInputStream(is); ExceptionReportDocument erDoc = null; try { return ExecuteResponseDocument.Factory.parse(documentObj); } catch(XmlException e) { try { erDoc = ExceptionReportDocument.Factory.parse(documentObj); } catch (XmlException e1) { throw new WPSClientException("Error occured while parsing executeResponse", e); } return erDoc; } }
private ExceptionReport parseOws110ExceptionReport(final OperationResult result) throws IOException, XmlException { final ExceptionReportDocument xb_execRepDoc = ExceptionReportDocument.Factory.parse(result.getIncomingResultAsAutoCloseStream()); final net.opengis.ows.x11.ExceptionType[] xb_exceptions = xb_execRepDoc.getExceptionReport().getExceptionArray(); final String language = xb_execRepDoc.getExceptionReport().getLang(); final String version = xb_execRepDoc.getExceptionReport().getVersion(); final ExceptionReport oxf_execReport = new ExceptionReport(version, language); for (final ExceptionType xb_exec : xb_exceptions) { final String execCode = xb_exec.getExceptionCode(); final String[] execMsgs = xb_exec.getExceptionTextArray(); final String locator = xb_exec.getLocator(); final OWSException owsExec = new OWSException(execMsgs, execCode, result.getSendedRequest(), locator); oxf_execReport.addException(owsExec); } return oxf_execReport; }