Search in sources :

Example 6 with OperationResponseEncoderKey

use of org.n52.svalbard.encode.OperationResponseEncoderKey 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 7 with OperationResponseEncoderKey

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

the class DescribeSensorResponseEncoderTest method should_return_correct_encoder_keys.

@Test
public void should_return_correct_encoder_keys() {
    Set<EncoderKey> returnedKeySet = new DescribeSensorResponseEncoder().getKeys();
    assertThat(returnedKeySet.size(), is(3));
    assertThat(returnedKeySet, hasItem(new XmlEncoderKey(SwesConstants.NS_SWES_20, DescribeSensorResponse.class)));
    assertThat(returnedKeySet, hasItem(new OperationResponseEncoderKey(SosConstants.SOS, Sos2Constants.SERVICEVERSION, SosConstants.Operations.DescribeSensor, MediaTypes.TEXT_XML)));
    assertThat(returnedKeySet, hasItem(new OperationResponseEncoderKey(SosConstants.SOS, Sos2Constants.SERVICEVERSION, SosConstants.Operations.DescribeSensor, MediaTypes.APPLICATION_XML)));
}
Also used : EncoderKey(org.n52.svalbard.encode.EncoderKey) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) DescribeSensorResponseEncoder(org.n52.svalbard.encode.DescribeSensorResponseEncoder) Test(org.junit.Test)

Aggregations

OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)5 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)4 OperationResponseEncoderKey (org.n52.svalbard.encode.OperationResponseEncoderKey)4 XmlObject (org.apache.xmlbeans.XmlObject)3 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)3 Test (org.junit.Test)1 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)1 MediaType (org.n52.janmayen.http.MediaType)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 DescribeSensorResponseEncoder (org.n52.svalbard.encode.DescribeSensorResponseEncoder)1 Encoder (org.n52.svalbard.encode.Encoder)1 EncoderKey (org.n52.svalbard.encode.EncoderKey)1 EncoderRepository (org.n52.svalbard.encode.EncoderRepository)1 EncodingContext (org.n52.svalbard.encode.EncodingContext)1 StreamingEncoder (org.n52.svalbard.encode.StreamingEncoder)1 XmlEncoderKey (org.n52.svalbard.encode.XmlEncoderKey)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1