@Override public void requestDone(final HttpServerExchange serverExchange) { Long existing = serverExchange.getAttachment(FIRST_REQUEST_ACCESS); if(existing != null) { lastAccessed = existing; } }
/** * * @return The current reason phrase */ public String getReasonPhrase() { return getAttachment(REASON_PHRASE); }
@Override public HeaderMap getTrailers() { Supplier<HeaderMap> supplier = exchange.getAttachment(HttpAttachments.RESPONSE_TRAILER_SUPPLIER); if(supplier != null) { return supplier.get(); } return exchange.getAttachment(HttpAttachments.RESPONSE_TRAILERS); } });
@Override public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException { Map<String, Object> context = exchange.getAttachment(Predicate.PREDICATE_CONTEXT); if (context != null) { context.put(name, newValue); } }
@Override public String readAttribute(final HttpServerExchange exchange) { Map<String, Object> context = exchange.getAttachment(Predicate.PREDICATE_CONTEXT); if (context != null) { Object object = context.get(name); return object == null ? null : object.toString(); } return null; }
void requestStarted(HttpServerExchange serverExchange) { Long existing = serverExchange.getAttachment(FIRST_REQUEST_ACCESS); if(existing == null) { if (!invalid) { serverExchange.putAttachment(FIRST_REQUEST_ACCESS, System.currentTimeMillis()); } } }
@Override public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) { AuthenticatedSessionManager sessionManager = exchange.getAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY); if (sessionManager != null) { return runCached(exchange, securityContext, sessionManager); } else { return AuthenticationMechanismOutcome.NOT_ATTEMPTED; } }
@Override public long transferTo(long position, long count, FileChannel target) throws IOException { PooledByteBuffer[] buffered = getAttachment(BUFFERED_REQUEST_DATA); if (buffered == null) { return super.transferTo(position, count, target); } return target.transferFrom(this, position, count); }
public boolean isSecure() { Boolean secure = getAttachment(SECURE_REQUEST); if(secure != null && secure) { return true; } String scheme = getRequestScheme(); if (scheme != null && scheme.equalsIgnoreCase(HTTPS)) { return true; } return false; }
@Override public void clearSession(HttpServerExchange exchange) { SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY); SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY); if (sessionManager == null || sessionConfig == null) { return; } Session httpSession = sessionManager.getSession(exchange, sessionConfig); if (httpSession != null) { httpSession.removeAttribute(ATTRIBUTE_NAME); } }
protected Session getSession(HttpServerExchange exchange) { SessionConfig sc = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY); SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY); if (sc == null || sm == null) { return null; } Session session = sm.getSession(exchange, sc); if (session == null) { return sm.createSession(exchange, sc); } return session; }
@Override public boolean isOpen() { PooledByteBuffer[] buffered = getAttachment(BUFFERED_REQUEST_DATA); if (buffered != null) { return true; } return super.isOpen(); }
static boolean isFormAuthentication(HttpServerExchange exchange) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); List<AuthenticationMechanism> mechanisms = src.getDeployment().getAuthenticationMechanisms(); for (AuthenticationMechanism mech : mechanisms) { if (mech instanceof ServletFormAuthenticationMechanism) return true; } return false; } }
@Override public void awaitReadable(long time, TimeUnit timeUnit) throws IOException { if(Thread.currentThread() == super.getIoThread()) { throw UndertowMessages.MESSAGES.awaitCalledFromIoThread(); } PooledByteBuffer[] buffered = getAttachment(BUFFERED_REQUEST_DATA); if (buffered == null) { super.awaitReadable(time, timeUnit); } }
@Override public void awaitReadable() throws IOException { if(Thread.currentThread() == super.getIoThread()) { throw UndertowMessages.MESSAGES.awaitCalledFromIoThread(); } PooledByteBuffer[] buffered = getAttachment(BUFFERED_REQUEST_DATA); if (buffered == null) { super.awaitReadable(); } }
@Override public boolean isReadResumed() { PooledByteBuffer[] buffered = getAttachment(BUFFERED_REQUEST_DATA); if (buffered != null) { return readsResumed; } if(isFinished()) { return false; } return anyAreSet(state, FLAG_SHOULD_RESUME_READS) || super.isReadResumed(); }
@Override public String findSessionId(HttpServerExchange exchange) { String encodedSessionId = this.config.findSessionId(exchange); if (encodedSessionId == null) return null; String sessionId = this.codec.decode(encodedSessionId); // Check if the encoding for this session has changed String reencodedSessionId = this.codec.encode(sessionId); if (!reencodedSessionId.equals(encodedSessionId) && exchange.getAttachment(SESSION_ID_SET) == null) { this.config.setSessionId(exchange, reencodedSessionId); } return sessionId; }
/** * <p> * Builds the JASPIC application context. * </p> * * @return a {@code String} representing the application context. */ private String buildAppContext() { final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletRequest servletRequest = requestContext.getServletRequest(); return servletRequest.getServletContext().getVirtualServerName() + " " + servletRequest.getServletContext().getContextPath(); }
private GenericMessageInfo createMessageInfo(final HttpServerExchange exchange, final SecurityContext securityContext) { ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); GenericMessageInfo messageInfo = new GenericMessageInfo(); messageInfo.setRequestMessage(servletRequestContext.getServletRequest()); messageInfo.setResponseMessage(servletRequestContext.getServletResponse()); messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", isMandatory(servletRequestContext).toString()); // additional context data, useful to provide access to Undertow resources during the modules processing messageInfo.getMap().put(SECURITY_CONTEXT_ATTACHMENT_KEY, securityContext); messageInfo.getMap().put(HTTP_SERVER_EXCHANGE_ATTACHMENT_KEY, exchange); return messageInfo; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String old = exchange.getAttachment(OLD_RELATIVE_PATH); if(!old.equals(exchange.getRelativePath())) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletPathMatch info = src.getDeployment().getServletPaths().getServletHandlerByPath(exchange.getRelativePath()); src.setCurrentServlet(info.getServletChain()); src.setServletPathMatch(info); } handler.handleRequest(exchange); } };