Search in sources :

Example 61 with OwsExceptionReport

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

the class InspireEncoderTest method getMinimalInspireExtendedCapabilities.

/*
     * xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
     * "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"
     */
// 
// @BeforeClass
// public static void init() {
// Map<String, String> prefixes = new HashMap<String, String>();
// prefixes.put(InspireConstants.NS_INSPIRE_COMMON, InspireConstants.NS_INSPIRE_COMMON_PREFIX);
// prefixes.put(InspireConstants.NS_INSPIRE_DLS, InspireConstants.NS_INSPIRE_DLS_PREFIX);
// xmlOptions.setSaveSuggestedPrefixes(prefixes);
// xmlOptions.setSaveImplicitNamespaces(prefixes);
// xmlOptions.setSaveAggressiveNamespaces();
// xmlOptions.setSavePrettyPrint();
// xmlOptions.setSaveNamespacesFirst();
// xmlOptions.setCharacterEncoding("UTF-8");
// }
// 
// @Test
// public void enocodeMinimalInspireExtendedCapabilities() throws UnsupportedEncoderInputException,
// OwsExceptionReport, SAXException, IOException {
// InspireXmlEncoder inspireEncoder = new InspireXmlEncoder();
// validate(inspireEncoder.encode(getMinimalInspireExtendedCapabilities()));
// }
// 
// @Test
// public void enocodeFullIsnpireExtendedCapabilities() throws UnsupportedEncoderInputException, OwsExceptionReport,
// SAXException, IOException {
// InspireXmlEncoder inspireEncoder = new InspireXmlEncoder();
// validate(inspireEncoder.encode(getFullInspireExtendedCapabilities()));
// }
// 
// @Test
// public void valid_iso8601() {
// // date
// String datePattern = "\\d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])";
// String date = "2013-09-26";
// Assert.assertThat(Pattern.matches(datePattern, date), Matchers.is(true));
// // time
// String timePattern = "(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?)?";
// String time_HH_MM_SS_S = "T12:49:41.740";
// Assert.assertThat(Pattern.matches(timePattern, time_HH_MM_SS_S), Matchers.is(true));
// String time_HH_MM_SS = "T12:49:41";
// Assert.assertThat(Pattern.matches(timePattern, time_HH_MM_SS), Matchers.is(true));
// // offset
// String offsetPattern = "(Z|[+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]))?";
// String offset_PLUS_HH_MM = "+02:00";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_PLUS_HH_MM), Matchers.is(true));
// String offset_MINUS_HH_MM = "-02:00";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_MINUS_HH_MM), Matchers.is(true));
// String offset_Z = "Z";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_Z), Matchers.is(true));
// // date time
// String dtPattern = datePattern + timePattern;
// Assert.assertThat(Pattern.matches(dtPattern, date + time_HH_MM_SS_S), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtPattern, date + time_HH_MM_SS), Matchers.is(true));
// // date time offset
// String dtoPattern = dtPattern + offsetPattern;
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_PLUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_MINUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_Z), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_PLUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_MINUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_Z), Matchers.is(true));
// // valid patter for schema: \d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?)?(Z|[+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]))?
// 
// //        String pattern =
// //                "\\d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?)?(Z|([+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9])?)?)?";
// //        Assert.assertThat(Pattern.matches(pattern, "2013-09-26T12:49:41.740+02:00"), Matchers.is(true));
// }
private MinimalInspireExtendedCapabilities getMinimalInspireExtendedCapabilities() {
    // --------------------
    InspireResourceLocator resourceLocator = new InspireResourceLocator("http://min.test.org/sos");
    resourceLocator.addMediaType(MediaTypes.APPLICATION_SOAP_XML);
    // --------------------
    InspireSupportedLanguages inspireSupportedLanguages = new InspireSupportedLanguages(InspireLanguageISO6392B.ENG);
    // --------------------
    InspireLanguageISO6392B responseLanguage = InspireLanguageISO6392B.ENG;
    // --------------------
    Set<InspireUniqueResourceIdentifier> spatialDataSetIdentifier = Sets.newHashSet();
    InspireUniqueResourceIdentifier iuri = new InspireUniqueResourceIdentifier("test");
    iuri.setNamespace("http://test.org");
    spatialDataSetIdentifier.add(iuri);
    // --------------------
    return new MinimalInspireExtendedCapabilities(resourceLocator, inspireSupportedLanguages, responseLanguage, spatialDataSetIdentifier, new InspireSupportedCRS("4326"));
}
Also used : InspireSupportedCRS(org.n52.shetland.inspire.InspireSupportedCRS) InspireUniqueResourceIdentifier(org.n52.shetland.inspire.InspireUniqueResourceIdentifier) InspireResourceLocator(org.n52.shetland.inspire.InspireResourceLocator) InspireLanguageISO6392B(org.n52.shetland.inspire.InspireLanguageISO6392B) InspireSupportedLanguages(org.n52.shetland.inspire.InspireSupportedLanguages) MinimalInspireExtendedCapabilities(org.n52.shetland.inspire.dls.MinimalInspireExtendedCapabilities)

Example 62 with OwsExceptionReport

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

the class WmlTVPEncoderv20XmlStreamWriter method writeResult.

@Override
protected void writeResult() throws XMLStreamException, EncodingException {
    start(OmConstants.QN_OM_20_RESULT);
    namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20);
    start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES);
    OmObservation observation = getElement();
    attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID());
    writeMeasurementTimeseriesMetadata(observation);
    if (observation.getValue() instanceof SingleObservationValue) {
        SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        String time = getTimeString(observationValue.getPhenomenonTime());
        writePoint(time, getValue(observation.getValue().getValue()));
        close();
    } else if (observation.getValue() instanceof MultiObservationValues) {
        // XML streaming to client
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            if (timeValuePair != null) {
                writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
            }
        }
        close();
    } else if (observation.getValue() instanceof StreamingValue) {
        // Database streaming + XML streaming to client
        StreamingValue<?> observationValue = (StreamingValue<?>) observation.getValue();
        if (observationValue.isSetUnit()) {
            writeDefaultPointMetadata(observationValue, observationValue.getUnit());
        } else if (observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
            writeDefaultPointMetadata(observationValue, ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
        } else {
            writeDefaultPointMetadata(observationValue, null);
        }
        try {
            while (observationValue.hasNext()) {
                TimeValuePair timeValuePair = observationValue.nextValue();
                if (timeValuePair != null) {
                    writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
                }
            }
        } catch (DateTimeFormatException | OwsExceptionReport e) {
            throw new EncodingException(e);
        }
        close();
    } else {
        super.writeResult();
    }
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) List(java.util.List) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 63 with OwsExceptionReport

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

the class Soap11Decoder method createEnvelope.

/**
 * Parses SOAP 1.1 Envelope to a SOS internal SOAP request.
 *
 * @param doc Request as xml representation
 *
 * @return SOS internal SOAP request
 *
 * @throws DecodingException if an error occurs.
 */
@Override
protected SoapRequest createEnvelope(XmlObject doc) throws DecodingException {
    SoapRequest soapRequest = new SoapRequest(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, SOAPConstants.SOAP_1_1_PROTOCOL);
    String soapAction = "";
    try {
        SOAPMessage soapMessageRequest;
        try {
            soapMessageRequest = SoapHelper.getSoapMessageForProtocol(SOAPConstants.SOAP_1_1_PROTOCOL, doc.newInputStream());
        } catch (IOException | SOAPException ioe) {
            throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while parsing SOAPMessage from request string!");
        }
        // if SOAPAction is not spec conform, create SOAPFault
        if (soapAction.isEmpty() || !soapAction.startsWith(SOAP_ACTION)) {
            SoapFault fault = new SoapFault();
            fault.setFaultCode(QN_CLIENT);
            fault.setFaultReason("The SOAPAction parameter in the HTTP-Header is missing or not valid!");
            fault.setLocale(Locale.ENGLISH);
            soapRequest.setSoapFault(fault);
            soapRequest.setSoapFault(fault);
        } else {
            // trim SOAPAction value
            soapAction = soapAction.replace("\"", "").replace(" ", "").replace(SOAP_ACTION, "").trim();
        }
        try {
            if (soapMessageRequest.getSOAPHeader() != null) {
                soapRequest.setSoapHeader(getSoapHeader(soapMessageRequest.getSOAPHeader()));
            }
            soapRequest.setAction(checkSoapAction(soapAction, soapRequest.getSoapHeader()));
            soapRequest.setSoapBodyContent(getSOAPBodyContent(soapMessageRequest));
        } catch (SOAPException | DecodingException soape) {
            throw new NoApplicableCodeException().causedBy(soape).withMessage("Error while parsing SOAPMessage!");
        }
    } catch (OwsExceptionReport owse) {
        throw new DecodingException(owse);
    }
    return soapRequest;
}
Also used : SoapFault(org.n52.shetland.w3c.soap.SoapFault) SoapRequest(org.n52.shetland.w3c.soap.SoapRequest) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SOAPException(javax.xml.soap.SOAPException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 64 with OwsExceptionReport

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

the class Soap12Decoder method createEnvelope.

/**
 * Parses SOAP 1.2 Envelope to a SOS internal SOAP request.
 *
 * @param doc
 *            request as xml representation
 *
 * @return SOS internal SOAP request
 *
 * @throws DecodingException
 *             if an error occurs.
 */
@Override
protected SoapRequest createEnvelope(XmlObject doc) throws DecodingException {
    SoapRequest soapRequest = new SoapRequest(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, SOAPConstants.SOAP_1_2_PROTOCOL);
    String soapAction = "";
    try {
        SOAPMessage message;
        try {
            message = SoapHelper.getSoapMessageForProtocol(SOAPConstants.SOAP_1_2_PROTOCOL, doc.newInputStream());
        } catch (IOException | SOAPException ioe) {
            throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while parsing SOAPMessage from request string!");
        }
        try {
            if (message.getSOAPHeader() != null) {
                soapRequest.setSoapHeader(getSoapHeader(message.getSOAPHeader()));
            }
            soapRequest.setAction(checkSoapAction(soapAction, soapRequest.getSoapHeader()));
            soapRequest.setSoapBodyContent(getBodyContent((EnvelopeDocument) doc));
        } catch (SOAPException soape) {
            throw new NoApplicableCodeException().causedBy(soape).withMessage("Error while parsing SOAPMessage!");
        }
    } catch (OwsExceptionReport owse) {
        throw new DecodingException(owse);
    }
    return soapRequest;
}
Also used : SoapRequest(org.n52.shetland.w3c.soap.SoapRequest) EnvelopeDocument(org.w3.x2003.x05.soapEnvelope.EnvelopeDocument) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SOAPException(javax.xml.soap.SOAPException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 65 with OwsExceptionReport

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

the class GetDataAvailabilityV20XmlDecoder method parseGetDataAvailability.

/**
 * Parse the GetDataAvailability XML request
 *
 * @param xml
 *            GetDataAvailability XML request
 * @return {@code GetDataAvailabilityRequest}
 * @throws OwsExceptionReport
 *             If the document could no be parsed
 */
private GetDataAvailabilityRequest parseGetDataAvailability(GetDataAvailabilityDocument xml) throws DecodingException {
    GetDataAvailabilityRequest request = new GetDataAvailabilityRequest();
    GetDataAvailabilityType gdat = xml.getGetDataAvailability();
    request.setNamespace(XmlHelper.getNamespace(xml));
    request.setResponseFormat(XmlHelper.getNamespace(xml));
    request.setService(gdat.getService());
    request.setVersion(gdat.getVersion());
    if (CollectionHelper.isNotNullOrEmpty(gdat.getObservedPropertyArray())) {
        for (String s : gdat.getObservedPropertyArray()) {
            request.addObservedProperty(s);
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(gdat.getProcedureArray())) {
        for (String s : gdat.getProcedureArray()) {
            request.addProcedure(s);
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(gdat.getFeatureOfInterestArray())) {
        for (String s : gdat.getFeatureOfInterestArray()) {
            request.addFeatureOfInterest(s);
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(gdat.getOfferingArray())) {
        for (String s : gdat.getOfferingArray()) {
            request.addOffering(s);
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(gdat.getResponseFormatArray())) {
        for (String s : gdat.getResponseFormatArray()) {
            request.setResponseFormat(s);
        }
    }
    request.setExtensions(parseExtensibleRequest(gdat));
    return request;
}
Also used : GetDataAvailabilityRequest(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityRequest) GetDataAvailabilityType(net.opengis.sosgda.x20.GetDataAvailabilityType)

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