Search in sources :

Example 1 with XmlNamespaceDecoderKey

use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.

the class GetResultTemplateResponseEncoder method encodeResultStructure.

private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
    SweAbstractDataComponent structure;
    SosResultStructure rs = t.getResultStructure();
    if (rs.isDecoded()) {
        structure = t.getResultStructure().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
            Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (structure instanceof SweDataRecord) {
        encodeSweDataRecord(structure, jrs);
    } else {
        LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 2 with XmlNamespaceDecoderKey

use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.

the class SwesDecoderv20 method parseInsertSensor.

private OwsServiceRequest parseInsertSensor(final InsertSensorDocument xbInsSensDoc) throws DecodingException {
    final InsertSensorRequest request = new InsertSensorRequest();
    final InsertSensorType xbInsertSensor = xbInsSensDoc.getInsertSensor();
    request.setService(xbInsertSensor.getService());
    request.setVersion(xbInsertSensor.getVersion());
    // format
    request.setProcedureDescriptionFormat(xbInsertSensor.getProcedureDescriptionFormat());
    // observable properties
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getObservablePropertyArray())) {
        request.setObservableProperty(Arrays.asList(xbInsertSensor.getObservablePropertyArray()));
    }
    // related features
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getRelatedFeatureArray())) {
        request.setRelatedFeature(parseRelatedFeature(xbInsertSensor.getRelatedFeatureArray()));
    }
    // metadata
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getMetadataArray())) {
        request.setMetadata(parseMetadata(xbInsertSensor.getMetadataArray()));
    }
    // extensions
    request.setExtensions(parseExtensibleRequest(xbInsertSensor));
    try {
        final XmlObject xbProcedureDescription = XmlObject.Factory.parse(getNodeFromNodeList(xbInsertSensor.getProcedureDescription().getDomNode().getChildNodes()));
        checkFormatWithNamespace(xbInsertSensor.getProcedureDescriptionFormat(), XmlHelper.getNamespace(xbProcedureDescription));
        final Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(xbInsertSensor.getProcedureDescriptionFormat(), xbProcedureDescription.getClass()));
        if (decoder != null) {
            final Object decodedProcedureDescription = decoder.decode(xbProcedureDescription);
            if (decodedProcedureDescription instanceof SosProcedureDescription) {
                request.setProcedureDescription((SosProcedureDescription) decodedProcedureDescription);
            } else if (decodedProcedureDescription instanceof AbstractFeature) {
                request.setProcedureDescription(new SosProcedureDescription<>((AbstractFeature) decodedProcedureDescription));
            }
        }
    } catch (final XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
    return request;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) InsertSensorType(net.opengis.swes.x20.InsertSensorType) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) InsertSensorRequest(org.n52.shetland.ogc.sos.request.InsertSensorRequest)

Example 3 with XmlNamespaceDecoderKey

use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.

the class AbstractSoapDecoder method getSoapHeader.

protected List<SoapHeader> getSoapHeader(SOAPHeader soapHeader) {
    Map<String, List<SOAPHeaderElement>> headersByNamespace = new HashMap<>();
    Iterator<?> headerElements = soapHeader.extractAllHeaderElements();
    while (headerElements.hasNext()) {
        SOAPHeaderElement element = (SOAPHeaderElement) headerElements.next();
        headersByNamespace.computeIfAbsent(element.getNamespaceURI(), Functions.forSupplier(LinkedList::new)).add(element);
    }
    List<SoapHeader> soapHeaders = Lists.newArrayList();
    for (Entry<String, List<SOAPHeaderElement>> key : headersByNamespace.entrySet()) {
        String namespace = key.getKey();
        try {
            Decoder<?, List<SOAPHeaderElement>> decoder = getDecoder(new XmlNamespaceDecoderKey(namespace, SOAPHeaderElement.class));
            if (decoder != null) {
                Object object = decoder.decode(headersByNamespace.get(namespace));
                if (object instanceof SoapHeader) {
                    soapHeaders.add((SoapHeader) object);
                } else if (object instanceof List<?>) {
                    for (Object o : (List<?>) object) {
                        if (o instanceof SoapHeader) {
                            soapHeaders.add((SoapHeader) o);
                        }
                    }
                }
            } else {
                LOGGER.info("The SOAP-Header elements for namespace '{}' are not supported by this server!", namespace);
            }
        } catch (DecodingException owse) {
            LOGGER.debug("Requested SOAPHeader element is not supported", owse);
        }
    }
    return soapHeaders;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) HashMap(java.util.HashMap) DecodingException(org.n52.svalbard.decode.exception.DecodingException) LinkedList(java.util.LinkedList) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader) LinkedList(java.util.LinkedList) List(java.util.List) XmlObject(org.apache.xmlbeans.XmlObject)

Example 4 with XmlNamespaceDecoderKey

use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.

the class UpdateSensorRequestDecoder method parseProcedureDesciption.

private SosProcedureDescription<?> parseProcedureDesciption(String xml, String pdf) throws DecodingException {
    try {
        final XmlObject xb = XmlObject.Factory.parse(xml);
        Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(pdf, xb.getClass()));
        if (decoder == null) {
            throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
        }
        Object decode = decoder.decode(xb);
        if (decode instanceof SosProcedureDescription<?>) {
            return (SosProcedureDescription<?>) decode;
        } else if (decode instanceof AbstractFeature) {
            return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
        } else {
            throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
}
Also used : XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 5 with XmlNamespaceDecoderKey

use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.

the class GetResultTemplateResponseEncoder method encodeResultEncoding.

private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
    SweAbstractEncoding encoding = null;
    SosResultEncoding re = t.getResultEncoding();
    if (re.isDecoded()) {
        encoding = t.getResultEncoding().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
            Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (encoding instanceof SweTextEncoding) {
        encodeSweTextEncoding(encoding, jre);
    } else {
        LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweAbstractEncoding(org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 XmlException (org.apache.xmlbeans.XmlException)4 XmlNamespaceDecoderKey (org.n52.svalbard.decode.XmlNamespaceDecoderKey)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)2 NoDecoderForKeyException (org.n52.svalbard.decode.exception.NoDecoderForKeyException)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)1 InsertSensorType (net.opengis.swes.x20.InsertSensorType)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 SosResultEncoding (org.n52.shetland.ogc.sos.SosResultEncoding)1 SosResultStructure (org.n52.shetland.ogc.sos.SosResultStructure)1 InsertSensorRequest (org.n52.shetland.ogc.sos.request.InsertSensorRequest)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1