@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { UndertowLogger.SESSION_LOGGER.tracef("Clearing path parameter session id %s on %s", sessionId, exchange); exchange.getPathParameters().remove(name); }
@Override public String findSessionId(final HttpServerExchange exchange) { Deque<String> stringDeque = exchange.getPathParameters().get(name); if (stringDeque == null) { return null; } UndertowLogger.SESSION_LOGGER.tracef("Found path parameter session id %s on %s", stringDeque.getFirst(), exchange); return stringDeque.getFirst(); }
@Override public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) { UndertowLogger.REQUEST_LOGGER.tracef("Created DEFLATE response conduit for %s", exchange); return new DeflatingStreamSinkConduit(factory, exchange, deflaterPool); } };
@Override public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) { UndertowLogger.REQUEST_LOGGER.tracef("Created GZIP response conduit for %s", exchange); return new GzipStreamSinkConduit(factory, exchange, deflaterPool); } };
@Override public void setSessionId(final HttpServerExchange exchange, final String sessionId) { exchange.getPathParameters().remove(name); exchange.addPathParam(name, sessionId); UndertowLogger.SESSION_LOGGER.tracef("Setting path parameter session id %s on %s", sessionId, exchange); }
@Override public String findSessionId(final HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getRequestCookies(); if (cookies != null) { Cookie sessionId = cookies.get(cookieName); if (sessionId != null) { UndertowLogger.SESSION_LOGGER.tracef("Found session cookie session id %s on %s", sessionId, exchange); return sessionId.getValue(); } } return null; }
@Override public Object removeAttribute(final String name) { if (invalid) { throw UndertowMessages.MESSAGES.sessionIsInvalid(sessionId); } final Object existing = attributes.remove(name); sessionManager.sessionListeners.attributeRemoved(this, name, existing); bumpTimeout(); UndertowLogger.SESSION_LOGGER.tracef("Removing session attribute %s for session %s", name, sessionId); return existing; }
@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { UndertowLogger.SESSION_LOGGER.tracef("Clearing SSL session id %s on %s", sessionId, exchange); SSLSessionInfo sslSession = exchange.getConnection().getSslSessionInfo(); if (sslSession == null) { if (fallbackSessionConfig != null) { fallbackSessionConfig.clearSession(exchange, sessionId); } } else { synchronized (this) { Key sid = reverse.remove(sessionId); if (sid != null) { sessions.remove(sid); } } } }
/** * Forcibly closes the {@link io.undertow.server.protocol.framed.AbstractFramedChannel}. */ @Override public void close() throws IOException { if(UndertowLogger.REQUEST_IO_LOGGER.isTraceEnabled()) { UndertowLogger.REQUEST_IO_LOGGER.tracef(new ClosedChannelException(), "Channel %s is being closed", this); } safeClose(channel); if(readData != null) { readData.close(); readData = null; } closeSubChannels(); }
@Override public void setSessionId(final HttpServerExchange exchange, final String sessionId) { UndertowLogger.SESSION_LOGGER.tracef("Setting SSL session id %s on %s", sessionId, exchange); SSLSessionInfo sslSession = exchange.getConnection().getSslSessionInfo(); if (sslSession == null) { if (fallbackSessionConfig != null) { fallbackSessionConfig.setSessionId(exchange, sessionId); } } else { Key key = new Key(sslSession.getSessionId()); synchronized (this) { sessions.put(key, sessionId); reverse.put(sessionId, key); } } }
@Override public String findSessionId(final HttpServerExchange exchange) { SSLSessionInfo sslSession = exchange.getConnection().getSslSessionInfo(); if (sslSession == null) { if (fallbackSessionConfig != null) { return fallbackSessionConfig.findSessionId(exchange); } } else { synchronized (this) { String sessionId = sessions.get(new Key(sslSession.getSessionId())); if(sessionId != null) { UndertowLogger.SESSION_LOGGER.tracef("Found SSL session id %s on %s", sessionId, exchange); } return sessionId; } } return null; }
@Override public Object setAttribute(final String name, final Object value) { if (value == null) { return removeAttribute(name); } if (invalid) { throw UndertowMessages.MESSAGES.sessionIsInvalid(sessionId); } final Object existing = attributes.put(name, value); if (existing == null) { sessionManager.sessionListeners.attributeAdded(this, name, value); } else { sessionManager.sessionListeners.attributeUpdated(this, name, value, existing); } bumpTimeout(); UndertowLogger.SESSION_LOGGER.tracef("Setting session attribute %s to %s for session %s", name, value, sessionId); return existing; }
@Override public FormDataParser create(final HttpServerExchange exchange) { String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (forceCreation || (mimeType != null && mimeType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED))) { String charset = defaultEncoding; String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (contentType != null) { String cs = Headers.extractQuotedValueFromHeader(contentType, "charset"); if (cs != null) { charset = cs; } } UndertowLogger.REQUEST_LOGGER.tracef("Created form encoded parser for %s", exchange); return new FormEncodedDataParser(charset, exchange); } return null; }
private ReferenceCountedPooled allocateReferenceCountedBuffer() { if(maxQueuedBuffers > 0) { int expect; do { expect = outstandingBuffersUpdater.get(this); if (expect == maxQueuedBuffers) { synchronized (this) { //we need to re-read in a sync block, to prevent races expect = outstandingBuffersUpdater.get(this); if (expect == maxQueuedBuffers) { if(UndertowLogger.REQUEST_IO_LOGGER.isTraceEnabled()) { UndertowLogger.REQUEST_IO_LOGGER.tracef("Suspending reads on %s due to too many outstanding buffers", this); } channel.getSourceChannel().suspendReads(); return null; } } } } while (!outstandingBuffersUpdater.compareAndSet(this, expect, expect + 1)); } PooledByteBuffer buf = bufferPool.allocate(); return this.readData = new ReferenceCountedPooled(buf, 1, maxQueuedBuffers > 0 ? freeNotifier : null); }
@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { Cookie cookie = new CookieImpl(cookieName, sessionId) .setPath(path) .setDomain(domain) .setDiscard(discard) .setSecure(secure) .setHttpOnly(httpOnly) .setMaxAge(0); exchange.setResponseCookie(cookie); UndertowLogger.SESSION_LOGGER.tracef("Clearing session cookie session id %s on %s", sessionId, exchange); }
@Override public FormDataParser create(final HttpServerExchange exchange) { String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (mimeType != null && mimeType.startsWith(MULTIPART_FORM_DATA)) { String boundary = Headers.extractQuotedValueFromHeader(mimeType, "boundary"); if (boundary == null) { UndertowLogger.REQUEST_LOGGER.debugf("Could not find boundary in multipart request with ContentType: %s, multipart data will not be available", mimeType); return null; } final MultiPartUploadHandler parser = new MultiPartUploadHandler(exchange, boundary, maxIndividualFileSize, fileSizeThreshold, defaultEncoding); exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override public void exchangeEvent(final HttpServerExchange exchange, final NextListener nextListener) { IoUtils.safeClose(parser); nextListener.proceed(); } }); Long sizeLimit = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MULTIPART_MAX_ENTITY_SIZE); if(sizeLimit != null) { exchange.setMaxEntitySize(sizeLimit); } UndertowLogger.REQUEST_LOGGER.tracef("Created multipart parser for %s", exchange); return parser; } return null; }
@Override public void setSessionId(final HttpServerExchange exchange, final String sessionId) { Cookie cookie = new CookieImpl(cookieName, sessionId) .setPath(path) .setDomain(domain) .setDiscard(discard) .setSecure(secure) .setHttpOnly(httpOnly) .setComment(comment); if (maxAge > 0) { cookie.setMaxAge(maxAge); } exchange.setResponseCookie(cookie); UndertowLogger.SESSION_LOGGER.tracef("Setting session cookie session id %s on %s", sessionId, exchange); }
@Override public void run() { handle = null; if (expireTime == -1) { return; } long current = System.currentTimeMillis(); if (current < expireTime) { //timeout has been bumped, re-schedule handle = WorkerUtils.executeAfter(getWriteThread(),timeoutCommand, (expireTime - current) + FUZZ_FACTOR, TimeUnit.MILLISECONDS); return; } UndertowLogger.REQUEST_LOGGER.tracef("Timing out channel %s due to inactivity", connection.getSinkChannel()); IoUtils.safeClose(connection); if (connection.getSourceChannel().isReadResumed()) { ChannelListeners.invokeChannelListener(connection.getSourceChannel(), connection.getSourceChannel().getReadListener()); } if (connection.getSinkChannel().isWriteResumed()) { ChannelListeners.invokeChannelListener(connection.getSinkChannel(), connection.getSinkChannel().getWriteListener()); } } };
@Override public void run() { handle = null; if (expireTime == -1) { return; } long current = System.currentTimeMillis(); if (current < expireTime) { //timeout has been bumped, re-schedule handle = WorkerUtils.executeAfter(connection.getIoThread(),timeoutCommand, (expireTime - current) + FUZZ_FACTOR, TimeUnit.MILLISECONDS); return; } UndertowLogger.REQUEST_LOGGER.tracef("Timing out channel %s due to inactivity", connection.getSourceChannel()); IoUtils.safeClose(connection); if (connection.getSourceChannel().isReadResumed()) { ChannelListeners.invokeChannelListener(connection.getSourceChannel(), connection.getSourceChannel().getReadListener()); } if (connection.getSinkChannel().isWriteResumed()) { ChannelListeners.invokeChannelListener(connection.getSinkChannel(), connection.getSinkChannel().getWriteListener()); } } };
public void handleEvent(final StreamConnection channel, PooledByteBuffer buffer) { if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) { UndertowLogger.REQUEST_LOGGER.tracef("Opened HTTP/2 connection with %s", channel.getPeerAddress()); } //cool, we have a Http2 connection. Http2Channel http2Channel = new Http2Channel(channel, protocol, bufferPool, buffer, false, false, undertowOptions); Integer idleTimeout = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT); if (idleTimeout != null && idleTimeout > 0) { http2Channel.setIdleTimeout(idleTimeout); } if(statisticsEnabled) { channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator())); channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator())); connectorStatistics.incrementConnectionCount(); http2Channel.addCloseTask(closeTask); } connections.add(http2Channel); http2Channel.addCloseTask(new ChannelListener<Http2Channel>() { @Override public void handleEvent(Http2Channel channel) { connections.remove(channel); } }); http2Channel.getReceiveSetter().set(new Http2ReceiveListener(rootHandler, getUndertowOptions(), bufferSize, connectorStatistics)); http2Channel.resumeReceives(); }