Search in sources :

Example 26 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class Iso19139GmdEncoderTest method setup.

@Before
public void setup() {
    encoder = new Iso19139GmdEncoder();
    encoder.setXmlOptions(XmlOptions::new);
    Iso19139GcoEncoder iso19139GcoEncoder = new Iso19139GcoEncoder();
    iso19139GcoEncoder.setXmlOptions(XmlOptions::new);
    EncoderRepository encoderRepository = new EncoderRepository();
    encoderRepository.setEncoders(Arrays.asList(encoder, iso19139GcoEncoder));
    encoderRepository.init();
    encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
Also used : Iso19139GmdEncoder(org.n52.svalbard.encode.Iso19139GmdEncoder) XmlOptions(org.apache.xmlbeans.XmlOptions) Before(org.junit.Before)

Example 27 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class SamplingEncoderv20Test method setup.

@Before
public void setup() throws InvalidSridException, ParseException {
    EncoderRepository encoderRepository = new EncoderRepository();
    OmEncoderv20 omEncoderv20 = new OmEncoderv20();
    omEncoderv20.setXmlOptions(XmlOptions::new);
    omEncoderv20.setEncoderRepository(encoderRepository);
    GmlEncoderv321 gmlEncoderv321 = new GmlEncoderv321();
    gmlEncoderv321.setEncoderRepository(encoderRepository);
    gmlEncoderv321.setXmlOptions(XmlOptions::new);
    SensorMLEncoderv20 sensorMLEncoderv20 = new SensorMLEncoderv20();
    sensorMLEncoderv20.setXmlOptions(XmlOptions::new);
    sensorMLEncoderv20.setEncoderRepository(encoderRepository);
    SweCommonEncoderv20 sweCommonEncoderv20 = new SweCommonEncoderv20();
    sweCommonEncoderv20.setEncoderRepository(encoderRepository);
    sweCommonEncoderv20.setXmlOptions(XmlOptions::new);
    encoder = new SamplingEncoderv20();
    encoder.setEncoderRepository(encoderRepository);
    encoder.setXmlOptions(XmlOptions::new);
    encoderRepository.setEncoders(Arrays.asList(omEncoderv20, gmlEncoderv321, sensorMLEncoderv20, sweCommonEncoderv20, encoder));
    encoderRepository.init();
    featureOfInterest = new SamplingFeature(new CodeWithAuthority("test-feature"));
    featureOfInterest.setIdentifier("test-feature-identifier");
    featureOfInterest.setName(new CodeType("test-feature-name"));
    featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
    featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT (30 10)", 4326));
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) CodeType(org.n52.shetland.ogc.gml.CodeType) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) Before(org.junit.Before)

Example 28 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class SosInsertionMetadataTypeEncoderTest method prepare.

@Before
public void prepare() {
    insertionMetadata = new SosInsertionMetadata();
    insertionMetadata.setObservationTypes(CollectionHelper.list("type-1", "type-2"));
    insertionMetadata.setFeatureOfInterestTypes(CollectionHelper.list("f-type-1", "f-type-2"));
    encoder = new SosInsertionMetadataTypeEncoder();
    encoder.setXmlOptions(() -> new XmlOptions());
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) SosInsertionMetadata(org.n52.shetland.ogc.sos.SosInsertionMetadata) Before(org.junit.Before)

Example 29 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element.

@Test
public void should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element() throws EncodingException {
    thrown.expect(EncodingException.class);
    thrown.expectMessage("The element type '" + getClass().getName() + "$1' " + "of the received '" + SweField.class.getName() + "' is not supported" + " by this encoder '" + SweCommonEncoderv101.class.getName() + "'.");
    sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField("test", new SweAbstractDataComponent() {

        @Override
        public SweDataComponentType getDataComponentType() {
            return null;
        }

        @Override
        public <T, X extends Throwable> T accept(SweDataComponentVisitor<T, X> visitor) {
            return null;
        }

        @Override
        public <X extends Throwable> void accept(VoidSweDataComponentVisitor<X> visitor) {
        }

        @Override
        public SweAbstractDataComponent copy() {
            return null;
        }
    })));
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SweDataComponentType(org.n52.shetland.ogc.swe.SweConstants.SweDataComponentType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Test(org.junit.Test)

Example 30 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class Soap11Encoder method encode.

@Override
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public SOAPMessage encode(SoapResponse soapResponse, EncodingContext additionalValues) throws EncodingException {
    if (soapResponse == null) {
        throw new UnsupportedEncoderInputException(this, soapResponse);
    }
    String soapVersion = soapResponse.getSoapVersion();
    SOAPMessage soapResponseMessage;
    String action = null;
    try {
        soapResponseMessage = SoapHelper.getSoapMessageForProtocol(soapVersion);
        if (soapResponse.getSoapFault() != null) {
            createSOAPFault(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getSoapFault());
        } else {
            if (soapResponse.getException() != null) {
                action = createSOAPFaultFromExceptionResponse(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getException());
                addSchemaLocationForExceptionToSOAPMessage(soapResponseMessage);
            } else {
                action = createSOAPBody(soapResponseMessage, soapResponse, soapResponse.getSoapAction());
            }
        }
        if (soapResponse.getHeader() != null) {
            List<SoapHeader> headers = soapResponse.getHeader();
            for (SoapHeader header : headers) {
                if (WsaConstants.NS_WSA.equals(header.getNamespace()) && header instanceof WsaActionHeader) {
                    ((WsaHeader) header).setValue(action);
                }
                Encoder<Map<QName, String>, SoapHeader> encoder = getEncoder(CodingHelper.getEncoderKey(header.getNamespace(), header));
                if (encoder != null) {
                    Map<QName, String> headerElements = encoder.encode(header);
                    for (Entry<QName, String> entry : headerElements.entrySet()) {
                        QName qName = entry.getKey();
                        soapResponseMessage.getSOAPHeader().addChildElement(qName).setTextContent(headerElements.get(qName));
                    }
                }
            }
        } else {
            soapResponseMessage.getSOAPHeader().detachNode();
        }
        soapResponseMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, String.valueOf(true));
        return soapResponseMessage;
    } catch (SOAPException soape) {
        throw new EncodingException("Error while encoding SOAPMessage!", soape);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) QName(javax.xml.namespace.QName) SOAPMessage(javax.xml.soap.SOAPMessage) WsaHeader(org.n52.shetland.w3c.wsa.WsaHeader) WsaActionHeader(org.n52.shetland.w3c.wsa.WsaActionHeader) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SOAPException(javax.xml.soap.SOAPException) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader) Map(java.util.Map) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Test (org.junit.Test)28 XmlObject (org.apache.xmlbeans.XmlObject)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)7 InsertResultTemplateRequest (org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest)7 InsertSensorRequest (org.n52.shetland.ogc.sos.request.InsertSensorRequest)7 Before (org.junit.Before)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)5 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)5 InsertObservationRequest (org.n52.shetland.ogc.sos.request.InsertObservationRequest)5 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)5 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)4 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)4 InsertResultRequest (org.n52.shetland.ogc.sos.request.InsertResultRequest)4 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)4 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)4 CodeType (org.n52.shetland.ogc.gml.CodeType)3