Search in sources :

Example 56 with Encoder

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

the class AbstractOmV20XmlStreamWriter method writeFeatureOfIntererst.

/**
 * Write om:featureOfInterest encoded or as xlink:href to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeFeatureOfIntererst() throws XMLStreamException, EncodingException {
    Optional<String> namespace = getDefaultFeatureEncodingNamespace();
    AbstractFeature foi = getElement().getObservationConstellation().getFeatureOfInterest();
    if (namespace.isPresent()) {
        EncodingContext codingContext = EncodingContext.of(XmlEncoderFlags.ENCODE_NAMESPACE, namespace.get());
        Encoder<XmlObject, AbstractFeature> encoder = getEncoder(GmlConstants.NS_GML_32, foi);
        writeXmlObject(encoder.encode(foi, codingContext), OmConstants.QN_OM_20_FEATURE_OF_INTEREST);
    } else {
        empty(OmConstants.QN_OM_20_FEATURE_OF_INTEREST);
        addXlinkHrefAttr(foi.getIdentifier());
        if (foi.isSetName() && foi.getFirstName().isSetValue()) {
            addXlinkTitleAttr(foi.getFirstName().getValue());
        }
    }
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject)

Example 57 with Encoder

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

the class Soap12XmlStreamWriter method writeBodyContent.

/**
 * Encode and write the {@link OwsServiceResponse} to stream
 *
 * @param bodyResponse The service internal response to encode and write
 *
 * @throws XMLStreamException If an error occurs when writing to {@link OutputStream}
 * @throws EncodingException  If an encoding error occurs
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void writeBodyContent(OwsServiceResponse bodyResponse) throws XMLStreamException, EncodingException {
    Encoder<Object, OwsServiceResponse> encoder = getEncoder(new OperationResponseEncoderKey(new OwsOperationKey(bodyResponse), MediaTypes.APPLICATION_XML));
    if (encoder instanceof StreamingEncoder<?, ?>) {
        EncodingContext ctx = getContext().with(XmlBeansEncodingFlags.DOCUMENT).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE).with(StreamingEncoderFlags.EMBEDDED, true);
        ((StreamingEncoder) encoder).encode(bodyResponse, getOutputStream(), ctx);
    } else {
        String soapBodyContent = ((XmlObject) encoder.encode(bodyResponse)).xmlText(getXmlOptions());
        rawText(stripXmlDeclaration(soapBodyContent));
    }
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) StreamingEncoder(org.n52.svalbard.encode.StreamingEncoder) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey)

Example 58 with Encoder

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

the class Soap12XmlStreamWriter method getSchemaLocation.

protected Set<SchemaLocation> getSchemaLocation() throws EncodingException, XMLStreamException {
    SoapResponse response = getElement();
    Set<SchemaLocation> schemaLocations = Sets.newHashSet();
    schemaLocations.add(SoapConstants.SOAP_12_SCHEMA_LOCATION);
    if (response.isSetBodyContent()) {
        Encoder<Object, OwsServiceResponse> encoder = getEncoder(response.getBodyContent());
        if (encoder != null && encoder instanceof SchemaAwareEncoder) {
            schemaLocations.addAll(((SchemaAwareEncoder<?, ?>) encoder).getSchemaLocations());
        }
    }
    return schemaLocations;
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) SchemaAwareEncoder(org.n52.svalbard.encode.SchemaAwareEncoder) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 59 with Encoder

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

the class AbstractSwesRequestEncoderTest method shouldThrowExceptionIfVersionIsMissing.

@Test
public void shouldThrowExceptionIfVersionIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + AbstractSwesRequestEncoderSeam.class.getSimpleName() + " can not encode 'missing version'"));
    encoder.validateInput(new OwsServiceRequest("SOS", "") {
    });
}
Also used : OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) Test(org.junit.Test)

Example 60 with Encoder

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

the class AbstractSwesRequestEncoderTest method shouldThrowExceptionIfServiceIsMissing.

@Test
public void shouldThrowExceptionIfServiceIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + AbstractSwesRequestEncoderSeam.class.getSimpleName() + " can not encode 'missing service'"));
    encoder.validateInput(new OwsServiceRequest() {
    });
}
Also used : OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) Test(org.junit.Test)

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