Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package io.undertow.server.session;
 
Handler that attaches the session to the request.

This handler is also the place where session cookie configuration properties are configured.

note: this approach is not used by Servlet, which has its own session handlers

Author(s):
Stuart Douglas
 
 public class SessionAttachmentHandler implements HttpHandler {
 
     private volatile HttpHandler next = .;
 
     private volatile SessionManager sessionManager;
 
     private final SessionConfig sessionConfig;
 
     public SessionAttachmentHandler(final SessionManager sessionManagerfinal SessionConfig sessionConfig) {
         this. = sessionConfig;
         if (sessionManager == null) {
             throw ..sessionManagerMustNotBeNull();
         }
         this. = sessionManager;
     }
 
     public SessionAttachmentHandler(final HttpHandler nextfinal SessionManager sessionManagerfinal SessionConfig sessionConfig) {
         this. = sessionConfig;
         if (sessionManager == null) {
             throw ..sessionManagerMustNotBeNull();
         }
         this. = next;
         this. = sessionManager;
     }
 
     @Override
     public void handleRequest(final HttpServerExchange exchangethrows Exception {
         exchange.addExchangeCompleteListener(handler);
         .handleRequest(exchange);
 
     }
 
 
     public HttpHandler getNext() {
         return ;
     }
 
     public SessionAttachmentHandler setNext(final HttpHandler next) {
         Handlers.handlerNotNull(next);
         this. = next;
         return this;
     }
 
     public SessionManager getSessionManager() {
         return ;
     }
 
     public SessionAttachmentHandler setSessionManager(final SessionManager sessionManager) {
         if (sessionManager == null) {
             throw ..sessionManagerMustNotBeNull();
         }
         this. = sessionManager;
         return this;
     }
 
     private static class UpdateLastAccessTimeListener implements ExchangeCompletionListener {
 
         private final SessionConfig sessionConfig;
         private final SessionManager sessionManager;
 
        private UpdateLastAccessTimeListener(final SessionConfig sessionConfigfinal SessionManager sessionManager) {
            this. = sessionConfig;
            this. = sessionManager;
        }
        @Override
        public void exchangeEvent(final HttpServerExchange exchangefinal NextListener next) {
            try {
                final Session session = .getSession(exchange);
                if (session != null) {
                    session.requestDone(exchange);
                }
            } finally {
                next.proceed();
            }
        }
    }
New to GrepCode? Check out our FAQ X