private ResponseBodyProcessor createBodyProcessor() { if (this.responseChannel == null) { this.responseChannel = this.exchange.getResponseChannel(); } return new ResponseBodyProcessor(this.responseChannel); }
private ResponseBodyProcessor createBodyProcessor() { if (this.responseChannel == null) { this.responseChannel = this.exchange.getResponseChannel(); } return new ResponseBodyProcessor(this.responseChannel); }
@Override public Mono<Void> writeWith(Path file, long position, long count) { return doCommit(() -> Mono.defer(() -> { try (FileChannel source = FileChannel.open(file, StandardOpenOption.READ)) { StreamSinkChannel destination = this.exchange.getResponseChannel(); Channels.transferBlocking(destination, source, position, count); return Mono.empty(); } catch (IOException ex) { return Mono.error(ex); } })); }
private void writeBufferBlocking(final boolean writeFinal) throws IOException { if (channel == null) { channel = exchange.getResponseChannel(); } buffer.flip(); while (buffer.hasRemaining()) { if(writeFinal) { channel.writeFinal(buffer); } else { channel.write(buffer); } if(buffer.hasRemaining()) { channel.awaitWritable(); } } buffer.clear(); state |= FLAG_WRITE_STARTED; }
@Override public Mono<Void> writeWith(Path file, long position, long count) { return doCommit(() -> Mono.defer(() -> { try (FileChannel source = FileChannel.open(file, StandardOpenOption.READ)) { StreamSinkChannel destination = this.exchange.getResponseChannel(); Channels.transferBlocking(destination, source, position, count); return Mono.empty(); } catch (IOException ex) { return Mono.error(ex); } })); }
/** * {@inheritDoc} */ public void flush() throws IOException { if (anyAreSet(state, FLAG_CLOSED)) { throw UndertowMessages.MESSAGES.streamIsClosed(); } if (buffer != null && buffer.position() != 0) { writeBufferBlocking(false); } if (channel == null) { channel = exchange.getResponseChannel(); } Channels.flushBlocking(channel); }
@Override public void transferFrom(FileChannel source) throws IOException { if (anyAreSet(state, FLAG_CLOSED)) { throw UndertowMessages.MESSAGES.streamIsClosed(); } if (buffer != null && buffer.position() != 0) { writeBufferBlocking(false); } if (channel == null) { channel = exchange.getResponseChannel(); } long position = source.position(); long size = source.size(); Channels.transferBlocking(channel, source, position, size); updateWritten(size - position); }
channel = exchange.getResponseChannel(); } else { if (channel == null) { channel = exchange.getResponseChannel();
public static void renderDirectoryListing(HttpServerExchange exchange, Resource resource) { String requestPath = exchange.getRequestPath(); if (! requestPath.endsWith("/")) { exchange.setStatusCode(StatusCodes.FOUND); exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, exchange.getRelativePath() + "/", true)); exchange.endExchange(); return; } StringBuilder builder = renderDirectoryListing(requestPath, resource); try { ByteBuffer output = ByteBuffer.wrap(builder.toString().getBytes(StandardCharsets.UTF_8)); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8"); exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(output.limit())); exchange.getResponseHeaders().put(Headers.LAST_MODIFIED, DateUtils.toDateString(new Date())); exchange.getResponseHeaders().put(Headers.CACHE_CONTROL, "must-revalidate"); Channels.writeBlocking(exchange.getResponseChannel(), output); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } catch (IOException e) { UndertowLogger.REQUEST_IO_LOGGER.ioException(e); exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); } exchange.endExchange(); }
channel = dest = exchange.getResponseChannel(); if (dest == null) { throw UndertowMessages.MESSAGES.responseChannelAlreadyProvided();
channel = exchange.getResponseChannel();
this.channel = channel = exchange.getResponseChannel(); if (channel == null) { throw UndertowMessages.MESSAGES.responseChannelAlreadyProvided();
final StreamSinkChannel response = exchange.getResponseChannel(); exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/event-stream; charset=UTF-8"); exchange.setPersistent(false); final StreamSinkChannel sink = exchange.getResponseChannel(); if(!sink.flush()) { sink.getWriteSetter().set(ChannelListeners.flushingChannelListener(new ChannelListener<StreamSinkChannel>() { @Override public void handleEvent(StreamSinkChannel channel) { handleConnect(channel, exchange); } }, new ChannelExceptionHandler<StreamSinkChannel>() { @Override public void handleException(StreamSinkChannel channel, IOException exception) { IoUtils.safeClose(exchange.getConnection()); } })); sink.resumeWrites(); } else { exchange.dispatch(exchange.getIoThread(), new Runnable() { @Override public void run() { handleConnect(sink, exchange); } }); } }
newExchange.setStatusCode(StatusCodes.CONTINUE); newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0); final StreamSinkChannel responseChannel = newExchange.getResponseChannel(); return new ContinueResponseSender() { boolean shutdown = false;
this.channel = channel = exchange.getResponseChannel(); if (channel == null) { throw UndertowMessages.MESSAGES.responseChannelAlreadyProvided();
exchange.setResponseContentLength(0); this.channel = channel = exchange.getResponseChannel(); if (channel == null) { throw UndertowMessages.MESSAGES.responseChannelAlreadyProvided();
newExchange.setStatusCode(StatusCodes.CONTINUE); newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0); final StreamSinkChannel responseChannel = newExchange.getResponseChannel(); try { responseChannel.shutdownWrites();
Transfer.initiateTransfer(result.getResponseChannel(), exchange.getResponseChannel(), ChannelListeners.closingChannelListener(), new HTTPTrailerChannelListener(result, exchange, exchange, proxyClientHandler, idempotentPredicate), handler, handler, exchange.getConnection().getByteBufferPool());