Search in sources :

Example 11 with Decoder

use of org.n52.svalbard.decode.Decoder 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 12 with Decoder

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

the class AbstractStringRequestDecoder method decode.

@Override
public OwsServiceCommunicationObject decode(String string) throws DecodingException {
    XmlObject xml = CodingHelper.readXML(string);
    DecoderKey key = CodingHelper.getDecoderKey(xml);
    Decoder<OwsServiceCommunicationObject, XmlObject> decoder = decoderRepository.getDecoder(key);
    if (decoder == null) {
        throw new NoDecoderForKeyException(key);
    }
    return decoder.decode(xml);
}
Also used : OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 13 with Decoder

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

the class GetFeatureOfInterestResponseDecoderTest method testMultiCurve.

@Test
public void testMultiCurve() throws XmlException, IOException, DecodingException {
    try {
        XmlObject xml = XmlObject.Factory.parse(getClass().getResourceAsStream("/GetFeatureOfInterestResponse.xml"));
        DecoderKey decoderKey = CodingHelper.getDecoderKey(xml);
        System.out.println(decoderKey);
        Decoder<GetFeatureOfInterestResponse, XmlObject> decoder = decoderRepository.getDecoder(decoderKey);
        GetFeatureOfInterestResponse response = decoder.decode(xml);
        assertThat(response, is(notNullValue()));
        assertThat(response.getAbstractFeature(), is(instanceOf(FeatureCollection.class)));
        FeatureCollection abstractFeature = (FeatureCollection) response.getAbstractFeature();
        assertThat(abstractFeature.getMembers().size(), is(266));
        System.out.println("feature: " + response.getAbstractFeature());
    } catch (Throwable t) {
        t.printStackTrace(System.out);
        throw t;
    }
}
Also used : GetFeatureOfInterestResponse(org.n52.shetland.ogc.sos.response.GetFeatureOfInterestResponse) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 14 with Decoder

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

the class BatchRequestDecoder method getDecoder.

private Decoder<OwsServiceRequest, JsonNode> getDecoder(JsonNode n) throws DecodingException {
    String service = n.path(JSONConstants.SERVICE).textValue();
    String version = n.path(JSONConstants.VERSION).textValue();
    String request = n.path(JSONConstants.REQUEST).textValue();
    OperationDecoderKey k = new OperationDecoderKey(service, version, request, MediaTypes.APPLICATION_JSON);
    Decoder<OwsServiceRequest, JsonNode> decoder = getDecoder(k);
    if (decoder == null) {
        // TODO other exception?
        throw new NoDecoderForKeyException(k);
    }
    return decoder;
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) JsonNode(com.fasterxml.jackson.databind.JsonNode) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey)

Example 15 with Decoder

use of org.n52.svalbard.decode.Decoder 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)

Aggregations

DecodingException (org.n52.svalbard.decode.exception.DecodingException)13 XmlObject (org.apache.xmlbeans.XmlObject)11 XmlException (org.apache.xmlbeans.XmlException)7 NoDecoderForKeyException (org.n52.svalbard.decode.exception.NoDecoderForKeyException)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Before (org.junit.Before)4 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)4 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)4 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)4 DecoderRepository (org.n52.svalbard.decode.DecoderRepository)4 InvalidParameterValueException (org.n52.shetland.ogc.ows.exception.InvalidParameterValueException)3 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)3 OperationDecoderKey (org.n52.svalbard.decode.OperationDecoderKey)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 Test (org.junit.Test)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 XmlNamespaceDecoderKey (org.n52.svalbard.decode.XmlNamespaceDecoderKey)2