Search in sources :

Example 1 with Encoder

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

the class SoapBinding method encodeSoapResponse.

private Object encodeSoapResponse(SoapChain chain) throws OwsExceptionReport, NoEncoderForKeyException {
    EncoderKey key = new XmlEncoderKey(chain.getSoapResponse().getSoapNamespace(), chain.getSoapResponse().getClass());
    Encoder<?, SoapResponse> encoder = getEncoder(key);
    if (encoder != null) {
        try {
            return encoder.encode(chain.getSoapResponse());
        } catch (OwsEncodingException ex) {
            throw ex.getCause();
        } catch (EncodingException ex) {
            throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
    } else {
        NoEncoderForKeyException cause = new NoEncoderForKeyException(key);
        throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) EncoderKey(org.n52.svalbard.encode.EncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException)

Example 2 with Encoder

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

the class SoapChainResponseWriter method write.

private void write(SoapChain chain, OutputStream out) throws EncodingException, IOException {
    String namespace = chain.getSoapResponse().getSoapNamespace();
    EncoderKey key = CodingHelper.getEncoderKey(namespace, chain.getSoapResponse());
    Encoder<?, SoapResponse> encoder = getEncoder(key);
    if (encoder == null) {
        throw new NoEncoderForKeyException(key);
    }
    write(encoder, chain, out);
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) EncoderKey(org.n52.svalbard.encode.EncoderKey)

Example 3 with Encoder

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

the class SimpleBindingTest method mockEncoderRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
private EncoderRepository mockEncoderRepository() {
    EncoderRepository encoderRepository = mock(EncoderRepository.class);
    OwsOperationKey operationKey = new OwsOperationKey(response);
    OperationResponseEncoderKey operationEncoderKey = new OperationResponseEncoderKey(operationKey, MediaTypes.APPLICATION_JSON);
    Encoder encoder = Mockito.mock(Encoder.class);
    when(encoderRepository.getEncoder(operationEncoderKey)).thenReturn(encoder);
    return encoderRepository;
}
Also used : Encoder(org.n52.svalbard.encode.Encoder) EncoderRepository(org.n52.svalbard.encode.EncoderRepository) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey)

Example 4 with Encoder

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

the class UVFEncoder method encodeToUvf.

private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
    List<OmObservation> mergeObservations = mergeTotoList(observationStream);
    String ending = getLineEnding(contentType);
    String filename = getFilename(mergeObservations);
    File uvfFile = new File(tempDir, filename);
    try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
        for (OmObservation o : mergeObservations) {
            if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
                String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
                LOGGER.error(errorMessage);
                throw new EncodingException(errorMessage);
            }
            /*
                 * HEADER: Metadata
                 */
            writeFunktionInterpretation(fw, o, ending);
            writeIndex(fw, ending);
            writeMessGroesse(fw, o, ending);
            writeMessEinheit(fw, o, ending);
            writeMessStellennummer(fw, o, ending);
            writeMessStellenname(fw, o, ending);
            /*
                 * HEADER: Lines 1 - 4
                 */
            writeLine1(fw, ending);
            TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
            writeLine2(fw, o, temporalBBox, ending);
            writeLine3(fw, o, ending);
            writeLine4(fw, temporalBBox, ending);
            /*
                 * Observation Data
                 */
            writeObservationValue(fw, o, ending);
        }
    }
    return uvfFile;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) FileOutputStream(java.io.FileOutputStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with Encoder

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

the class ExiEncoder method encode.

@Override
public EXIObject<XmlObject> encode(T response) throws EncodingException {
    Encoder<Object, T> encoder = getEncoder(response);
    Object encode = encoder.encode(response);
    if (encode != null && encode instanceof XmlObject) {
        return new EXIObject<XmlObject>((XmlObject) encode);
    } else {
        throw new UnsupportedEncoderInputException(encoder, response);
    }
}
Also used : EXIObject(org.n52.shetland.exi.EXIObject) EXIObject(org.n52.shetland.exi.EXIObject) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

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