use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class GenericRequestOperator method checkForModifierAndProcess.
private void checkForModifierAndProcess(OwsServiceRequest request) throws OwsExceptionReport {
if (!this.modifierRepository.hasRequestResponseModifier(request)) {
return;
}
List<RequestResponseModifier> splitter = new LinkedList<>();
List<RequestResponseModifier> remover = new LinkedList<>();
List<RequestResponseModifier> defaultModifier = new LinkedList<>();
this.modifierRepository.getRequestResponseModifier(request).stream().forEach(modifier -> {
if (modifier.getFacilitator().isSplitter()) {
splitter.add(modifier);
} else if (modifier.getFacilitator().isAdderRemover()) {
remover.add(modifier);
} else {
defaultModifier.add(modifier);
}
});
// execute adder/remover
for (RequestResponseModifier modifier : remover) {
modifier.modifyRequest(request);
}
// execute default
for (RequestResponseModifier modifier : defaultModifier) {
modifier.modifyRequest(request);
}
// execute splitter
for (RequestResponseModifier modifier : splitter) {
modifier.modifyRequest(request);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SimpleBinding method writeOwsExceptionReport.
protected void writeOwsExceptionReport(HttpServletRequest request, HttpServletResponse response, OwsExceptionReport oer) throws HTTPException {
try {
this.eventBus.submit(new ExceptionEvent(oer));
MediaType contentType = chooseResponseContentTypeForExceptionReport(HTTPHeaders.getAcceptHeader(request), getDefaultContentType());
Object encoded = encodeOwsExceptionReport(oer, contentType);
if (isUseHttpResponseCodes() && oer.hasStatus()) {
response.setStatus(oer.getStatus().getCode());
}
httpUtils.writeObject(request, response, contentType, encoded, this);
} catch (IOException | OwsExceptionReport e) {
throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, e);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SimpleBinding method encodeResponse.
protected Object encodeResponse(OwsServiceResponse response, MediaType contentType) throws OwsExceptionReport {
try {
OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response), contentType);
Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new NoEncoderForKeyException(key);
}
return encoder.encode(response);
} catch (EncodingException ex) {
throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class EXIBinding method decode.
/**
* Parse the incoming EXI encoded {@link InputStream} transform to
* {@link XmlObject}
*
* @param request
* {@link HttpServletRequest} with EXI encoded
* {@link InputStream}
* @return {@link XmlObject} created from the EXI encoded
* {@link InputStream}
* @throws OwsExceptionReport
* If an error occurs during parsing
*/
protected XmlObject decode(HttpServletRequest request) throws OwsExceptionReport {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
EXIFactory ef = this.exiUtils.newEXIFactory();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
if (ef.isFragment()) {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
// decode EXI encoded InputStream
EXISource exiSource = new EXISource(ef);
XMLReader exiReader = exiSource.getXMLReader();
InputSource inputSource = new InputSource(request.getInputStream());
inputSource.setEncoding(request.getCharacterEncoding());
SAXSource saxSource = new SAXSource(inputSource);
saxSource.setXMLReader(exiReader);
transformer.transform(saxSource, new StreamResult(os));
// create XmlObject from OutputStream
return XmlHelper.parseXmlString(os.toString(StandardCharsets.UTF_8.name()));
} catch (IOException | EXIException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while reading request! Message: %s", ex.getMessage());
} catch (TransformerException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while transforming request! Message: %s", ex.getMessage());
} catch (DecodingException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while parsing request! Message: %s", ex.getMessage());
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class EXIBinding method parseRequest.
/**
* Parse and decode the incoming EXI encoded {@link InputStream}
*
* @param request
* {@link HttpServletRequest} with EXI encoded
* {@link InputStream}
* @return {@link OwsServiceRequest} from EXI encoded {@link InputStream}
* @throws OwsExceptionReport
* If an error occurs during parsing
*/
protected OwsServiceRequest parseRequest(HttpServletRequest request) throws OwsExceptionReport {
XmlObject doc = decode(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("EXI-REQUEST: {}", doc.xmlText());
}
Decoder<OwsServiceRequest, XmlObject> decoder = getDecoder(CodingHelper.getDecoderKey(doc));
try {
return decoder.decode(doc).setRequestContext(getRequestContext(request));
} catch (OwsDecodingException ex) {
throw ex.getCause();
} catch (DecodingException ex) {
throw new InvalidParameterValueException().withMessage(ex.getMessage()).causedBy(ex).at(ex.getLocation().orElse(null));
}
}
Aggregations