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