Search in sources :

Example 1 with CodedException

use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.

the class AbstractXmlBinding method getDecoderKey.

@VisibleForTesting
protected DecoderKey getDecoderKey(String xmlContent, String characterEncoding) throws CodedException {
    try (ByteArrayInputStream stream = new ByteArrayInputStream(xmlContent.getBytes(characterEncoding))) {
        // FIXME do not parse the complete request, if we only need the first element
        Document document = documentFactory.newDocumentBuilder().parse(stream);
        Element element = document.getDocumentElement();
        // TODO is this REALLY needed!?
        element.normalize();
        if (element.hasAttributes() && element.hasAttribute(OWSConstants.RequestParams.service.name())) {
            OwsOperationKey operationKey = getOperationKey(element);
            XmlStringOperationDecoderKey decoderKey = new XmlStringOperationDecoderKey(operationKey, getDefaultContentType());
            return decoderKey;
        } else {
            return getNamespaceOperationDecoderKey(element);
        }
    } catch (SAXException | IOException | ParserConfigurationException e) {
        throw new NoApplicableCodeException().causedBy(e).withMessage("An error occured when parsing the request! Message: %s", e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) Element(org.w3c.dom.Element) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) SAXException(org.xml.sax.SAXException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CodedException

use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.

the class AbstractSoapEncoder method createSOAPFaultFromExceptionResponse.

/**
 * Creates a SOAPFault element from SOS exception
 *
 * @param soapFault          SOAPFault element
 * @param owsExceptionReport SOS exception
 *
 * @return SOAP action URI.
 *
 * @throws SOAPException if an error occurs.
 */
protected String createSOAPFaultFromExceptionResponse(SOAPFault soapFault, OwsExceptionReport owsExceptionReport) throws SOAPException {
    // exceptions!
    if (!owsExceptionReport.getExceptions().isEmpty()) {
        CodedException firstException = owsExceptionReport.getExceptions().iterator().next();
        if (soapFault.getNamespaceURI().equalsIgnoreCase(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
            QName qname = new QName(soapFault.getNamespaceURI(), "Client", soapFault.getPrefix());
            soapFault.setFaultCode(qname);
        } else {
            soapFault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            if (firstException.getCode() != null) {
                soapFault.appendFaultSubcode(new QName(OWSConstants.NS_OWS, firstException.getCode().toString(), OWSConstants.NS_OWS_PREFIX));
            } else {
                soapFault.appendFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
            }
        }
        soapFault.addFaultReasonText(SoapHelper.getSoapFaultReasonText(firstException.getCode()), Locale.ENGLISH);
        Detail detail = soapFault.addDetail();
        for (CodedException exception : owsExceptionReport.getExceptions()) {
            createSOAPFaultDetail(detail, exception);
        }
        return getExceptionActionURI(firstException.getCode());
    } else {
        SoapFault fault = new SoapFault();
        fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
        fault.setFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
        fault.setFaultReason(DEFAULT_FAULT_REASON);
        fault.setLocale(Locale.ENGLISH);
        fault.setDetailText(MISSING_EXCEPTION_DETAIL_TEXT);
        createSOAPFault(soapFault, fault);
        return SosSoapConstants.RESP_ACTION_SOS;
    }
}
Also used : SoapFault(org.n52.shetland.w3c.soap.SoapFault) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) QName(javax.xml.namespace.QName) Detail(javax.xml.soap.Detail)

Example 3 with CodedException

use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.

the class WmlTVPEncoderv20 method createMeasurementTimeseries.

/**
 * Create a XML MeasurementTimeseries object from SOS observation for
 * om:result
 *
 * @param sosObservation
 *            SOS observation
 *
 * @return XML MeasurementTimeseries object
 *
 * @throws CodedException
 *             if the encoding fails
 */
private XmlObject createMeasurementTimeseries(OmObservation sosObservation) throws OwsExceptionReport {
    MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
    MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
    measurementTimeseries.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // Default value
    TimeseriesMetadata timeseriesMetadata = new MeasurementTimeseriesMetadata().setCumulative(false);
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getValue().getValue().getClass().isAssignableFrom(TVPValue.class) && sosObservation.getObservationConstellation().isSetMetadata() && sosObservation.getObservationConstellation().getMetadata().isSetTimeseriesMetadata()) {
        timeseriesMetadata = sosObservation.getObservationConstellation().getMetadata().getTimeseriesmetadata();
    }
    addTimeseriesMetadata(measurementTimeseries, sosObservation.getPhenomenonTime().getGmlId(), timeseriesMetadata);
    TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
    DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
    TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
    // Default value
    InterpolationType interpolationType = InterpolationType.Continuous;
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getObservationConstellation().isSetDefaultPointMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
        interpolationType = sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
    }
    defaultTVPMeasurementMetadata.addNewInterpolationType().setHref(interpolationType.getIdentifier());
    xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle(interpolationType.getTitle());
    String unit = addValues(measurementTimeseries, sosObservation.getValue());
    // set uom
    if (unit != null && !unit.isEmpty()) {
        defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
    } else {
        OmObservableProperty observableProperty = (OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty();
        if (observableProperty.isSetUnit()) {
            defaultTVPMeasurementMetadata.addNewUom().setCode(observableProperty.getUnit());
        }
    }
    xbMetaComponent.set(xbDefMeasureMetaComponent);
    return measurementTimeseriesDoc;
}
Also used : TimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) MeasurementTimeseriesType(net.opengis.waterml.x20.MeasurementTimeseriesType) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) TVPMeasurementMetadataType(net.opengis.waterml.x20.TVPMeasurementMetadataType) DefaultTVPMeasurementMetadataDocument(net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument) InterpolationType(org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 4 with CodedException

use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.

the class WmlTVPEncoderv20 method addValues.

private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
    String unit = null;
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
        String time = getTimeString(singleObservationValue.getPhenomenonTime());
        unit = singleObservationValue.getValue().getUnit();
        String value = null;
        if (singleObservationValue.getValue() instanceof QuantityValue) {
            QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
            if (quantityValue.isSetValue()) {
                value = quantityValue.getValue().toPlainString();
            }
        } else if (singleObservationValue.getValue() instanceof CountValue) {
            CountValue countValue = (CountValue) singleObservationValue.getValue();
            if (countValue.getValue() != null) {
                value = Integer.toString(countValue.getValue());
            }
        } else if (singleObservationValue.getValue() instanceof ProfileValue) {
            ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
            if (profileValue.isSetValue()) {
                if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                    QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                    if (quantityValue.isSetValue()) {
                        value = Double.toString(quantityValue.getValue().doubleValue());
                    }
                }
            }
        }
        addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
    } else if (observationValue instanceof MultiObservationValues) {
        MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
        TVPValue tvpValue = (TVPValue) mov.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        unit = tvpValue.getUnit();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            String time = getTimeString(timeValuePair.getTime());
            String value = null;
            if (timeValuePair.getValue() instanceof QuantityValue) {
                QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
                if (quantityValue.isSetValue()) {
                    value = quantityValue.getValue().toPlainString();
                }
            } else if (timeValuePair.getValue() instanceof ProfileValue) {
                ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
                if (profileValue.isSetValue()) {
                    if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                        QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                        if (quantityValue.isSetValue()) {
                            value = Double.toString(quantityValue.getValue().doubleValue());
                        }
                    }
                }
            } else if (timeValuePair.getValue() instanceof CountValue) {
                CountValue countValue = (CountValue) timeValuePair.getValue();
                if (countValue.isSetValue()) {
                    value = Integer.toString(countValue.getValue());
                }
            } else {
                throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
            }
            addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
        }
    }
    return unit;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) List(java.util.List) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 5 with CodedException

use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.

the class Soap12Encoder method createSOAP12FaultFromExceptionResponse.

// see
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300
// for more details
private XmlObject createSOAP12FaultFromExceptionResponse(final OwsExceptionReport owsExceptionReport) throws EncodingException {
    final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
    final Fault fault = faultDoc.addNewFault();
    final Faultcode code = fault.addNewCode();
    code.setValue(SOAPConstants.SOAP_SENDER_FAULT);
    // 19.2.3 SOAP 1.2 Fault Binding
    if (!owsExceptionReport.getExceptions().isEmpty()) {
        final CodedException firstException = owsExceptionReport.getExceptions().get(0);
        final Subcode subcode = code.addNewSubcode();
        QName qName;
        if (firstException.getCode() != null) {
            qName = OwsHelper.getQNameForLocalName(firstException.getCode().toString());
        } else {
            qName = OwsHelper.getQNameForLocalName(OwsExceptionCode.NoApplicableCode.name());
        }
        subcode.setValue(qName);
        final Reasontext addNewText = fault.addNewReason().addNewText();
        addNewText.setLang(Locale.ENGLISH.getLanguage());
        addNewText.setStringValue(SoapHelper.getSoapFaultReasonText(firstException.getCode()));
        fault.addNewDetail().set(encodeObjectToXml(OWSConstants.NS_OWS, firstException, EncodingContext.of(XmlBeansEncodingFlags.ENCODE_OWS_EXCEPTION_ONLY)));
    }
    return faultDoc;
}
Also used : Faultcode(org.w3.x2003.x05.soapEnvelope.Faultcode) Subcode(org.w3.x2003.x05.soapEnvelope.Subcode) FaultDocument(org.w3.x2003.x05.soapEnvelope.FaultDocument) Reasontext(org.w3.x2003.x05.soapEnvelope.Reasontext) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) QName(javax.xml.namespace.QName) SoapFault(org.n52.shetland.w3c.soap.SoapFault) Fault(org.w3.x2003.x05.soapEnvelope.Fault)

Aggregations

CodedException (org.n52.shetland.ogc.ows.exception.CodedException)6 Test (org.junit.Test)5 DecoderKey (org.n52.svalbard.decode.DecoderKey)4 OperationDecoderKey (org.n52.svalbard.decode.OperationDecoderKey)4 XmlNamespaceOperationDecoderKey (org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey)4 QName (javax.xml.namespace.QName)2 ExceptionType (net.opengis.ows.x11.ExceptionType)2 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)2 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)2 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)2 TVPMeasurementMetadataType (net.opengis.waterml.x20.TVPMeasurementMetadataType)2 MeasurementTimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata)2 TimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata)2 InterpolationType (org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType)2 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 SoapFault (org.n52.shetland.w3c.soap.SoapFault)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1