Search in sources :

Example 1 with EncodingException

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

the class SimpleBinding method handleEncodingException.

@Override
public Object handleEncodingException(HttpServletRequest request, HttpServletResponse response, EncodingException ex) throws HTTPException {
    try {
        OwsExceptionReport oer;
        if (ex instanceof OwsEncodingException) {
            oer = ((OwsEncodingException) ex).getCause();
        } else if (ex.getCause() instanceof OwsExceptionReport) {
            oer = (OwsExceptionReport) ex.getCause();
        } else {
            oer = new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
        eventBus.submit(new ExceptionEvent(oer));
        MediaType contentType = chooseResponseContentTypeForExceptionReport(HTTPHeaders.getAcceptHeader(request), getDefaultContentType());
        Object encoded = encodeOwsExceptionReport(oer, contentType);
        if (isUseHttpResponseCodes() && oer.hasStatus()) {
            response.setStatus(oer.getStatus().getCode());
        }
        return encoded;
    } catch (OwsExceptionReport e) {
        throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) HTTPException(org.n52.iceland.exception.HTTPException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) MediaType(org.n52.janmayen.http.MediaType) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 2 with EncodingException

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

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

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

the class HttpUtils method writeObject.

private void writeObject(HttpServletRequest request, HttpServletResponse response, MediaType contentType, Writable writable, EncodingExceptionHandler owserHandler) throws IOException, HTTPException {
    OutputStream out = null;
    response.setContentType(writable.getEncodedContentType().toString());
    try {
        out = response.getOutputStream();
        if (HTTPHeaders.supportsGzipEncoding(request) && writable.supportsGZip()) {
            out = new GZIPOutputStream(out);
            response.setHeader(HTTPHeaders.CONTENT_ENCODING, HTTPConstants.GZIP_ENCODING);
        }
        if (isCountingOutputStream) {
            out = new CountingOutputStream(out);
        }
        if (writable.hasForcedHttpStatus()) {
            response.setStatus(writable.getForcedHttpStatus().getCode());
        }
        writable.write(out, new ResponseProxy(response));
        out.flush();
    } catch (EncodingException e) {
        Object writeOwsExceptionReport = owserHandler.handleEncodingException(request, response, e);
        if (writeOwsExceptionReport != null) {
            Writable owserWritable = getWritable(writeOwsExceptionReport, contentType);
            try {
                owserWritable.write(out, new ResponseProxy(response));
                if (out != null) {
                    out.flush();
                }
            } catch (EncodingException ex) {
                throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, ex);
            }
        }
    } finally {
        if (out instanceof CountingOutputStream) {
            Long bytesWritten = ((CountingOutputStream) out).getCount();
            eventBus.submit(new CountingOutputStreamEvent(bytesWritten));
        }
        if (out != null) {
            LOGGER.debug("Response status = " + response.getStatus());
            out.close();
        }
    }
}
Also used : ResponseProxy(org.n52.iceland.coding.encode.ResponseProxy) CountingOutputStream(com.google.common.io.CountingOutputStream) HTTPException(org.n52.iceland.exception.HTTPException) GZIPOutputStream(java.util.zip.GZIPOutputStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) CountingOutputStreamEvent(org.n52.iceland.event.events.CountingOutputStreamEvent) CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream)

Example 5 with EncodingException

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

the class SweHelper method getFieldForValue.

private SweField getFieldForValue(Value<?> iValue, String name) throws EncodingException {
    SweAbstractDataComponent value = getValue(iValue);
    value.setDefinition(name);
    return new SweField(name, value);
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)124 Test (org.junit.Test)93 EncodingException (org.n52.svalbard.encode.exception.EncodingException)60 SweField (org.n52.shetland.ogc.swe.SweField)29 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)29 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)22 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)21 XmlException (org.apache.xmlbeans.XmlException)20 DateTime (org.joda.time.DateTime)19 OmObservation (org.n52.shetland.ogc.om.OmObservation)19 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)17 Time (org.n52.shetland.ogc.gml.time.Time)15 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)15 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)13 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)13 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)12 SystemType (net.opengis.sensorML.x101.SystemType)11 DataRecordType (net.opengis.swe.x101.DataRecordType)11