@Override public void close(final IoCallback callback) { try { outputStream.close(); invokeOnComplete(callback); } catch (IOException e) { callback.onException(exchange, this, e); } }
private void invokeOnException(IoCallback callback, IOException e) { if (pooledBuffers != null) { for (PooledByteBuffer buffer : pooledBuffers) { buffer.close(); } pooledBuffers = null; } callback.onException(exchange, this, e); }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException x) { log.error("execution of {} resulted in exception", exchange.getRequestPath(), x); callback.onException(exchange, sender, x); }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException ex) { done(); callback.onException(exchange, sender, ex); }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); try { entry.dereference(); } finally { callback.onException(exchange, sender, exception); } } }
private void performTransfer(FileChannel source, IoCallback callback) { if (outputStream instanceof BufferWritableOutputStream) { try { ((BufferWritableOutputStream) outputStream).transferFrom(source); } catch (IOException e) { callback.onException(exchange, this, e); } } else { try (PooledByteBuffer pooled = exchange.getConnection().getByteBufferPool().getArrayBackedPool().allocate()){ ByteBuffer buffer = pooled.getBuffer(); long pos = source.position(); long size = source.size(); while (size - pos > 0) { int ret = source.read(buffer); if (ret <= 0) { break; } pos += ret; outputStream.write(buffer.array(), buffer.arrayOffset(), ret); buffer.clear(); } if (pos != size) { throw new EOFException("Unexpected EOF reading file"); } } catch (IOException e) { callback.onException(exchange, this, e); } } }
return true; } catch (IOException e) { callback.onException(exchange, this, e); return false; outputStream.write(buffer.array(), buffer.arrayOffset(), buffer.remaining()); } catch (IOException e) { callback.onException(exchange, this, e); return false; outputStream.write(pooled.getBuffer().array(), pooled.getBuffer().arrayOffset(), toRead); } catch (IOException e) { callback.onException(exchange, this, e); return false;
/** * Sends a continuation using async IO, and calls back when it is complete. * * @param exchange The exchange * @param callback The completion callback */ public static void sendContinueResponse(final HttpServerExchange exchange, final IoCallback callback) { if (!exchange.isResponseChannelAvailable()) { callback.onException(exchange, null, UndertowMessages.MESSAGES.cannotSendContinueResponse()); return; } internalSendContinueResponse(exchange, callback); }
@Override public void send(final String data, final IoCallback callback) { byte[] bytes = data.getBytes(StandardCharsets.UTF_8); if (inCall) { queue(new ByteBuffer[]{ByteBuffer.wrap(bytes)}, callback); return; } else { long responseContentLength = exchange.getResponseContentLength(); if(responseContentLength > 0 && bytes.length > responseContentLength) { callback.onException(exchange, this, UndertowLogger.ROOT_LOGGER.dataLargerThanContentLength(bytes.length, responseContentLength)); return; } if (!exchange.isResponseStarted() && callback == IoCallback.END_EXCHANGE) { if (responseContentLength == -1 && !exchange.getResponseHeaders().contains(Headers.TRANSFER_ENCODING)) { exchange.setResponseContentLength(bytes.length); } } } try { outputStream.write(bytes); invokeOnComplete(callback); } catch (IOException e) { callback.onException(exchange, this, e); } }
@Override public void send(final String data, final Charset charset, final IoCallback callback) { byte[] bytes = data.getBytes(charset); if (inCall) { queue(new ByteBuffer[]{ByteBuffer.wrap(bytes)}, callback); return; }else { long responseContentLength = exchange.getResponseContentLength(); if(responseContentLength > 0 && bytes.length > responseContentLength) { callback.onException(exchange, this, UndertowLogger.ROOT_LOGGER.dataLargerThanContentLength(bytes.length, responseContentLength)); return; } if (!exchange.isResponseStarted() && callback == IoCallback.END_EXCHANGE) { if (responseContentLength == -1 && !exchange.getResponseHeaders().contains(Headers.TRANSFER_ENCODING)) { exchange.setResponseContentLength(bytes.length); } } } try { outputStream.write(bytes); invokeOnComplete(callback); } catch (IOException e) { callback.onException(exchange, this, e); } }
@Override public void send(final ByteBuffer buffer, final IoCallback callback) { if (inCall) { queue(new ByteBuffer[]{buffer}, callback); return; } else { long responseContentLength = exchange.getResponseContentLength(); if(responseContentLength > 0 && buffer.remaining() > responseContentLength) { callback.onException(exchange, this, UndertowLogger.ROOT_LOGGER.dataLargerThanContentLength(buffer.remaining(), responseContentLength)); return; } if (!exchange.isResponseStarted() && callback == IoCallback.END_EXCHANGE) { if (responseContentLength == -1 && !exchange.getResponseHeaders().contains(Headers.TRANSFER_ENCODING)) { exchange.setResponseContentLength(buffer.remaining()); } } } if (writeBuffer(buffer, callback)) { invokeOnComplete(callback); } }
@Override public void send(final ByteBuffer[] buffer, final IoCallback callback) { if (inCall) { queue(buffer, callback); return; } else { long responseContentLength = exchange.getResponseContentLength(); if(responseContentLength > 0 && Buffers.remaining(buffer) > responseContentLength) { callback.onException(exchange, this, UndertowLogger.ROOT_LOGGER.dataLargerThanContentLength(Buffers.remaining(buffer), responseContentLength)); return; } if (!exchange.isResponseStarted() && callback == IoCallback.END_EXCHANGE) { if (responseContentLength == -1 && !exchange.getResponseHeaders().contains(Headers.TRANSFER_ENCODING)) { exchange.setResponseContentLength(Buffers.remaining(buffer)); } } } if (!writeBuffer(buffer, callback)) { return; } invokeOnComplete(callback); }
callback.onException(exchange, null, e);
@Override public void close(final IoCallback callback) { try { outputStream.close(); invokeOnComplete(callback); } catch (IOException e) { callback.onException(exchange, this, e); } }
@Override public void onException(HttpServerExchange exchange, Sender sender, IOException exception) { IO.close(channel); IoCallback.END_EXCHANGE.onException(exchange, sender, exception); } });
private void invokeOnException(IoCallback callback, IOException e) { if (pooledBuffers != null) { for (PooledByteBuffer buffer : pooledBuffers) { buffer.close(); } pooledBuffers = null; } callback.onException(exchange, this, e); }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException x) { log.error("execution of {} resulted in exception", exchange.getRequestPath(), x); callback.onException(exchange, sender, x); }
@Override public void close(final IoCallback callback) { try { outputStream.close(); invokeOnComplete(callback); } catch (IOException e) { callback.onException(exchange, this, e); } }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); try { entry.dereference(); } finally { callback.onException(exchange, sender, exception); } } }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); try { entry.dereference(); } finally { callback.onException(exchange, sender, exception); } } }