public ChunkedStreamSourceConduit(final StreamSourceConduit next, final HttpServerExchange exchange, final ConduitListener<? super ChunkedStreamSourceConduit> finishListener) { this(next, new BufferWrapper() { @Override public PooledByteBuffer allocate() { return exchange.getConnection().getByteBufferPool().allocate(); } @Override public void pushBack(PooledByteBuffer pooled) { ((HttpServerConnection) exchange.getConnection()).ungetRequestBytes(pooled); } }, finishListener, exchange, exchange, exchange.getConnection()); }
@Override protected String initId() { return ObjectUtils.getIdentityHexString(this.exchange.getConnection()); }
@Nullable @Override protected SslInfo initSslInfo() { SSLSession session = this.exchange.getConnection().getSslSession(); if (session != null) { return new DefaultSslInfo(session); } return null; }
@Override protected String initId() { return ObjectUtils.getIdentityHexString(this.exchange.getConnection()); }
@Override public OptionMap getOptions() { return exchange.getConnection().getUndertowOptions(); } }
@Override public String readAttribute(final HttpServerExchange exchange) { InetSocketAddress localAddress = (InetSocketAddress) exchange.getConnection().getLocalAddress(); return localAddress.getAddress().getHostAddress(); }
@Override public void onError(Throwable ex) { logger.trace(this.logPrefix + "Failed to complete: " + ex.getMessage()); if (this.exchange.isResponseStarted()) { try { logger.debug(this.logPrefix + "Closing connection"); this.exchange.getConnection().close(); } catch (IOException ex2) { // ignore } } else { logger.debug(this.logPrefix + "Setting HttpServerExchange status to 500 Server Error"); this.exchange.setStatusCode(500); this.exchange.endExchange(); } }
@Nullable @Override protected SslInfo initSslInfo() { SSLSession session = this.exchange.getConnection().getSslSession(); if (session != null) { return new DefaultSslInfo(session); } return null; }
public RequestBodyPublisher(HttpServerExchange exchange, DataBufferFactory bufferFactory) { super(UndertowServerHttpRequest.this.getLogPrefix()); this.channel = exchange.getRequestChannel(); this.bufferFactory = bufferFactory; this.byteBufferPool = exchange.getConnection().getByteBufferPool(); }
public long transferTo(final long position, final long count, final FileChannel target) throws IOException { try { return target.transferFrom(new ConduitReadableByteChannel(this), position, count); } catch (IOException | RuntimeException | Error e) { IoUtils.safeClose(exchange.getConnection()); throw e; } }
@Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { exchange.getConnection().setSslSessionInfo(null); nextListener.proceed(); } };
public RequestBodyPublisher(HttpServerExchange exchange, DataBufferFactory bufferFactory) { super(UndertowServerHttpRequest.this.getLogPrefix()); this.channel = exchange.getRequestChannel(); this.bufferFactory = bufferFactory; this.byteBufferPool = exchange.getConnection().getByteBufferPool(); }
@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); try { exchange.endExchange(); } finally { IoUtils.safeClose(exchange.getConnection()); } } }
/** * @return A mutable map of request cookies */ public Map<String, Cookie> getRequestCookies() { if (requestCookies == null) { requestCookies = Cookies.parseRequestCookies( getConnection().getUndertowOptions().get(UndertowOptions.MAX_COOKIES, 200), getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false), requestHeaders.get(Headers.COOKIE)); } return requestCookies; }
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException { final long val = state; if (allAreSet(val, FLAG_CLOSED) || val == 0L) { return; } try { next.awaitReadable(time, timeUnit); } catch (IOException | RuntimeException | Error e) { IoUtils.safeClose(exchange.getConnection()); throw e; } }
/** * Gets the channel wrapper that implements the buffering */ public void setupPipelineBuffer(final HttpServerExchange exchange) { ((HttpServerConnection) exchange.getConnection()).getChannel().getSinkChannel().setConduit(this); }
@Override public void couldNotResolveBackend(HttpServerExchange exchange) { if (exchange.isResponseStarted()) { IoUtils.safeClose(exchange.getConnection()); } else { exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE); exchange.endExchange(); } }
public UndertowInputStream(final HttpServerExchange exchange) { if (exchange.isRequestChannelAvailable()) { this.channel = exchange.getRequestChannel(); } else { this.channel = new EmptyStreamSourceChannel(exchange.getIoThread()); } this.bufferPool = exchange.getConnection().getByteBufferPool(); }
public void exchangeComplete(final HttpServerExchange exchange) { if (!exchange.isUpgrade() && exchange.isPersistent()) { startRequest(); ConduitStreamSourceChannel channel = ((AjpServerConnection) exchange.getConnection()).getChannel().getSourceChannel(); channel.getReadSetter().set(this); channel.wakeupReads(); } else if(!exchange.isPersistent()) { safeClose(exchange.getConnection()); } }
static void handleFailure(HttpServerExchange exchange, ProxyClientHandler proxyClientHandler, Predicate idempotentRequestPredicate, IOException e) { UndertowLogger.PROXY_REQUEST_LOGGER.proxyRequestFailed(exchange.getRequestURI(), e); if(exchange.isResponseStarted()) { IoUtils.safeClose(exchange.getConnection()); } else if(idempotentRequestPredicate.resolve(exchange) && proxyClientHandler != null) { proxyClientHandler.failed(exchange); //this will attempt a retry if configured to do so } else { exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE); exchange.endExchange(); } }