Search in sources :

Example 16 with MediaType

use of org.n52.janmayen.http.MediaType 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 17 with MediaType

use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.

the class MediaTypeTest method testCompatibleXmlTypes.

// @Test
// public void testUrn() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(OGCConstants.URN_IDENTIFIER_IDENTIFICATION);
// }
// 
// @Test
// public void testOgcUrlUnknown() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(OGCConstants.UNKNOWN);
// }
// 
// @Test
// public void testSensorMLUrl() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(SensorMLConstants.SENSORML_OUTPUT_FORMAT_URL);
// }
@Test
public void testCompatibleXmlTypes() {
    MediaType applicationXml = MediaType.parse("application/xml");
    MediaType textXml = MediaType.parse("text/xml");
    MediaType textPlain = MediaType.parse("text/plain");
    errors.checkThat(applicationXml.isCompatible(textXml), is(true));
    errors.checkThat(textXml.isCompatible(applicationXml), is(true));
    errors.checkThat(applicationXml.isCompatible(textPlain), is(false));
    errors.checkThat(textXml.isCompatible(textPlain), is(false));
}
Also used : MediaType(org.n52.janmayen.http.MediaType) Test(org.junit.Test)

Example 18 with MediaType

use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.

the class MediaTypeTest method applicationXmlWithQuotedParameter.

@Test
public void applicationXmlWithQuotedParameter() {
    MediaType mt = MediaType.parse(" application/xml; a=\"asdf\"");
    errors.checkThat(mt.getType(), is("application"));
    errors.checkThat(mt.getSubtype(), is("xml"));
    errors.checkThat(mt.getParameters().size(), is(1));
    errors.checkThat(mt.getParameter("a").iterator().next(), is("asdf"));
}
Also used : MediaType(org.n52.janmayen.http.MediaType) Test(org.junit.Test)

Example 19 with MediaType

use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.

the class MediaTypeTest method applicationXmlWithQAndFourSpace.

@Test
public void applicationXmlWithQAndFourSpace() {
    MediaType mt = MediaType.parse("application/xml; q=1");
    errors.checkThat(mt.getType(), is("application"));
    errors.checkThat(mt.getSubtype(), is("xml"));
    errors.checkThat(mt.getParameters().size(), is(1));
    errors.checkThat(mt.getParameter("q").iterator().next(), is("1"));
}
Also used : MediaType(org.n52.janmayen.http.MediaType) Test(org.junit.Test)

Example 20 with MediaType

use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.

the class MediaTypeTest method applicationXmlWithQuotedParameterWithUnescapedSlash.

@Test
public void applicationXmlWithQuotedParameterWithUnescapedSlash() {
    MediaType mt = MediaType.parse("application/xml;a=\"a\\\\b\"");
    errors.checkThat(mt.getType(), is("application"));
    errors.checkThat(mt.getSubtype(), is("xml"));
    errors.checkThat(mt.getParameters().size(), is(1));
    errors.checkThat(mt.getParameter("a").size(), is(1));
    errors.checkThat(mt.getParameter("a").iterator().next(), is("a\\b"));
}
Also used : MediaType(org.n52.janmayen.http.MediaType) Test(org.junit.Test)

Aggregations

MediaType (org.n52.janmayen.http.MediaType)28 Test (org.junit.Test)21 HTTPException (org.n52.iceland.exception.HTTPException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)2 ExceptionEvent (org.n52.iceland.event.events.ExceptionEvent)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 DescribeSensor (net.opengis.sos.x10.DescribeSensorDocument.DescribeSensor)1 Binding (org.n52.iceland.binding.Binding)1 ResponseProxy (org.n52.iceland.coding.encode.ResponseProxy)1