Search in sources :

Example 21 with Decoder

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

the class InsertSensorRequestDecoderTest method setUp.

@Before
public void setUp() throws DecodingException, IOException {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new InsertSensorRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    SensorMLDecoderV101 sensorMLDecoder = new SensorMLDecoderV101();
    sensorMLDecoder.setXmlOptions(XmlOptions::new);
    sensorMLDecoder.setDecoderRepository(decoderRepository);
    SweCommonDecoderV101 sweCommonDecoder = new SweCommonDecoderV101();
    sweCommonDecoder.setXmlOptions(XmlOptions::new);
    sweCommonDecoder.setDecoderRepository(decoderRepository);
    GmlDecoderv311 gmlDecoderv311 = new GmlDecoderv311();
    decoderRepository.setDecoders(Arrays.asList(decoder, sensorMLDecoder, sweCommonDecoder, gmlDecoderv311));
    decoderRepository.init();
    final JsonNode json = JsonLoader.fromResource("/examples/sos/InsertSensorRequest.json");
    this.req = decoder.decode(json);
    assertThat(req, is(notNullValue()));
}
Also used : SensorMLDecoderV101(org.n52.svalbard.decode.SensorMLDecoderV101) SweCommonDecoderV101(org.n52.svalbard.decode.SweCommonDecoderV101) XmlOptions(org.apache.xmlbeans.XmlOptions) InsertSensorRequestDecoder(org.n52.svalbard.decode.json.InsertSensorRequestDecoder) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecoderRepository(org.n52.svalbard.decode.DecoderRepository) GmlDecoderv311(org.n52.svalbard.decode.GmlDecoderv311) Before(org.junit.Before)

Example 22 with Decoder

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

Example 23 with Decoder

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

the class AbstractCapabilitiesBaseTypeDecoderTest method shouldNotThrowNullPointerExceptionWhenServiceIdentificationIsMissing.

@Test
public void shouldNotThrowNullPointerExceptionWhenServiceIdentificationIsMissing() throws DecodingException {
    AbstractCapabilitiesBaseTypeDecoder<CapabilitiesBaseType, OwsCapabilities> decoder = new TestSeam();
    CapabilitiesBaseType cbt = CapabilitiesBaseType.Factory.newInstance();
    cbt.setVersion("2.0.0");
    cbt.setUpdateSequence("nothing-to-see-here");
    Assert.assertThat(decoder.parseCapabilitiesBaseType("SOS", cbt).getServiceIdentification().isPresent(), Is.is(false));
}
Also used : CapabilitiesBaseType(net.opengis.ows.x11.CapabilitiesBaseType) OwsCapabilities(org.n52.shetland.ogc.ows.OwsCapabilities) Test(org.junit.Test)

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