Search in sources :

Example 1 with ExceptionEvent

use of org.n52.iceland.event.events.ExceptionEvent 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 ExceptionEvent

use of org.n52.iceland.event.events.ExceptionEvent in project arctic-sea by 52North.

the class SoapBinding method writeOwsExceptionReport.

private void writeOwsExceptionReport(SoapChain chain, OwsExceptionReport owse) throws HTTPException, IOException {
    try {
        String version = chain.hasBodyRequest() ? chain.getBodyRequest().getVersion() : null;
        getEventBus().submit(new ExceptionEvent(owse));
        chain.getSoapResponse().setException(owse.setVersion(version));
        if (!chain.getSoapResponse().hasSoapVersion()) {
            chain.getSoapResponse().setSoapVersion(SOAPConstants.SOAP_1_2_PROTOCOL);
        }
        if (!chain.getSoapResponse().hasSoapNamespace()) {
            chain.getSoapResponse().setSoapNamespace(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
        }
        if (chain.getSoapResponse().hasException() && chain.getSoapResponse().getException().hasStatus()) {
            chain.getHttpResponse().setStatus(chain.getSoapResponse().getException().getStatus().getCode());
        }
        checkSoapInjection(chain);
        httpUtils.writeObject(chain.getHttpRequest(), chain.getHttpResponse(), checkMediaType(chain), encodeSoapResponse(chain), this);
    } catch (OwsExceptionReport | NoEncoderForKeyException t) {
        throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, t);
    }
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) HTTPException(org.n52.iceland.exception.HTTPException) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 3 with ExceptionEvent

use of org.n52.iceland.event.events.ExceptionEvent in project arctic-sea by 52North.

the class Service method onHttpException.

protected void onHttpException(HttpServletRequest request, HttpServletResponse response, HTTPException exception) throws IOException {
    this.serviceEventBus.submit(new ExceptionEvent(exception));
    response.sendError(exception.getStatus().getCode(), exception.getMessage());
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent)

Example 4 with ExceptionEvent

use of org.n52.iceland.event.events.ExceptionEvent in project arctic-sea by 52North.

the class AbstractStatisticsServiceEventListener method addEventToResolver.

private void addEventToResolver(BatchResolver resolver, Event event) {
    StatisticsServiceEventResolver<?> evtResolver = null;
    if (event instanceof ExceptionEvent) {
        ExceptionEventResolver sosExceptionEventResolver = resolverFactory.getExceptionEventResolver();
        sosExceptionEventResolver.setEvent((ExceptionEvent) event);
        evtResolver = sosExceptionEventResolver;
    } else if (event instanceof OutgoingResponseEvent) {
        OutgoingResponseEventResolver outgoingResponseEventResolver = resolverFactory.getOutgoingResponseEventResolver();
        outgoingResponseEventResolver.setEvent((OutgoingResponseEvent) event);
        evtResolver = outgoingResponseEventResolver;
    } else if (event instanceof CountingOutputStreamEvent) {
        CountingOutputStreamEventResolver countingOutputstreamEventResolver = resolverFactory.getCountingOutputstreamEventResolver();
        countingOutputstreamEventResolver.setEvent((CountingOutputStreamEvent) event);
        evtResolver = countingOutputstreamEventResolver;
    } else {
        evtResolver = findResolver(event);
    }
    // Default fallback event resolver
    if (evtResolver == null) {
        DefaultServiceEventResolver defaultServiceEventResolver = resolverFactory.getDefaultServiceEventResolver();
        defaultServiceEventResolver.setEvent(event);
        evtResolver = defaultServiceEventResolver;
    }
    resolver.addEventResolver(evtResolver);
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) CountingOutputStreamEventResolver(org.n52.iceland.statistics.impl.resolvers.CountingOutputStreamEventResolver) CountingOutputStreamEvent(org.n52.iceland.event.events.CountingOutputStreamEvent) DefaultServiceEventResolver(org.n52.iceland.statistics.impl.resolvers.DefaultServiceEventResolver) OutgoingResponseEventResolver(org.n52.iceland.statistics.impl.resolvers.OutgoingResponseEventResolver) ExceptionEventResolver(org.n52.iceland.statistics.impl.resolvers.ExceptionEventResolver) OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Example 5 with ExceptionEvent

use of org.n52.iceland.event.events.ExceptionEvent in project arctic-sea by 52North.

the class SimpleBinding method writeOwsExceptionReport.

protected void writeOwsExceptionReport(HttpServletRequest request, HttpServletResponse response, OwsExceptionReport oer) throws HTTPException {
    try {
        this.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());
        }
        httpUtils.writeObject(request, response, contentType, encoded, this);
    } catch (IOException | 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) MediaType(org.n52.janmayen.http.MediaType) IOException(java.io.IOException) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Aggregations

ExceptionEvent (org.n52.iceland.event.events.ExceptionEvent)5 HTTPException (org.n52.iceland.exception.HTTPException)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 MediaType (org.n52.janmayen.http.MediaType)2 IOException (java.io.IOException)1 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)1 CountingOutputStreamEvent (org.n52.iceland.event.events.CountingOutputStreamEvent)1 OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)1 CountingOutputStreamEventResolver (org.n52.iceland.statistics.impl.resolvers.CountingOutputStreamEventResolver)1 DefaultServiceEventResolver (org.n52.iceland.statistics.impl.resolvers.DefaultServiceEventResolver)1 ExceptionEventResolver (org.n52.iceland.statistics.impl.resolvers.ExceptionEventResolver)1 OutgoingResponseEventResolver (org.n52.iceland.statistics.impl.resolvers.OutgoingResponseEventResolver)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)1