Search in sources :

Example 1 with OwsEncodingException

use of org.n52.iceland.coding.encode.OwsEncodingException 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 OwsEncodingException

use of org.n52.iceland.coding.encode.OwsEncodingException 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)

Aggregations

OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 ExceptionEvent (org.n52.iceland.event.events.ExceptionEvent)1 HTTPException (org.n52.iceland.exception.HTTPException)1 MediaType (org.n52.janmayen.http.MediaType)1 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)1 SoapResponse (org.n52.shetland.w3c.soap.SoapResponse)1 EncoderKey (org.n52.svalbard.encode.EncoderKey)1 XmlEncoderKey (org.n52.svalbard.encode.XmlEncoderKey)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)1