use of org.n52.iceland.coding.encode.ResponseProxy 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.iceland.coding.encode.ResponseProxy in project arctic-sea by 52North.
the class EXIResponseWriter method write.
@Override
public void write(EXIObject<XmlObject> exiObject, OutputStream out, ResponseProxy responseProxy) throws IOException, EncodingException {
byte[] bytes = getBytes(exiObject);
try (InputStream is = new ByteArrayInputStream(bytes)) {
EXIResult result = new EXIResult(this.exiFactory.get());
result.setOutputStream(out);
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(result.getHandler());
xmlReader.parse(new InputSource(is));
} catch (EXIException | SAXException e) {
throw new EncodingException(e);
}
}
Aggregations