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);
}
}
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);
}
}
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());
}
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);
}
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);
}
}
Aggregations