Search in sources :

Example 46 with OwsExceptionReport

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);
    }
}
Also used : RequestResponseModifier(org.n52.iceland.convert.RequestResponseModifier) LinkedList(java.util.LinkedList)

Example 47 with OwsExceptionReport

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);
    }
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) HTTPException(org.n52.iceland.exception.HTTPException) MediaType(org.n52.janmayen.http.MediaType) IOException(java.io.IOException) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 48 with OwsExceptionReport

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);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 49 with OwsExceptionReport

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());
    }
}
Also used : InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) EXISource(com.siemens.ct.exi.api.sax.EXISource) StreamResult(javax.xml.transform.stream.StreamResult) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EXIException(com.siemens.ct.exi.exceptions.EXIException) SAXSource(javax.xml.transform.sax.SAXSource) XMLReader(org.xml.sax.XMLReader) TransformerException(javax.xml.transform.TransformerException) EXIFactory(com.siemens.ct.exi.EXIFactory)

Example 50 with OwsExceptionReport

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));
    }
}
Also used : OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest)

Aggregations

OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)27 EncodingException (org.n52.svalbard.encode.exception.EncodingException)14 Test (org.junit.Test)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)9 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)8 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)8 XmlObject (org.apache.xmlbeans.XmlObject)7 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)7 IOException (java.io.IOException)6 DateTime (org.joda.time.DateTime)6 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)6 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)5 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)5 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)5 LinkedList (java.util.LinkedList)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)4 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3