Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 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.servlet.core;
 
 
 
Class that bridges between Undertow native session listeners and servlet ones.

Author(s):
Stuart Douglas
 
 public class SessionListenerBridge implements SessionListener {
 
     public static final String IO_UNDERTOW = "io.undertow";
     private final ThreadSetupAction threadSetup;
     private final ApplicationListeners applicationListeners;
     private final ServletContext servletContext;
 
     public SessionListenerBridge(final ThreadSetupAction threadSetupfinal ApplicationListeners applicationListenersfinal ServletContext servletContext) {
         this. = threadSetup;
         this. = applicationListeners;
         this. = servletContext;
     }
 
     @Override
     public void sessionCreated(final Session sessionfinal HttpServerExchange exchange) {
         final HttpSessionImpl httpSession = SecurityActions.forSession(sessiontrue);
         .sessionCreated(httpSession);
     }
 
     @Override
     public void sessionDestroyed(final Session sessionfinal HttpServerExchange exchangefinal SessionDestroyedReason reason) {
         ThreadSetupAction.Handle handle = null;
         try {
             final HttpSessionImpl httpSession = SecurityActions.forSession(sessionfalse);
             if (reason == .) {
                 handle = .setup(exchange);
             }
             .sessionDestroyed(httpSession);
             //we make a defensive copy here, as there is no guarantee that the underlying session map
             //is a concurrent map, and as a result a concurrent modification exception may be thrown
             HashSet<Stringnames = new HashSet<>(session.getAttributeNames());
             for(String attribute : names) {
                 session.removeAttribute(attribute);
             }
         } finally {
             if (handle != null) {
                 handle.tearDown();
             }
             ServletRequestContext current = SecurityActions.currentServletRequestContext();
             Session underlying = null;
             if(current != null && current.getSession() != null) {
                 if(System.getSecurityManager() == null) {
                     underlying = current.getSession().getSession();
                 } else {
                     underlying = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(current.getSession()));
                 }
             }
 
             if (current != null && underlying == session) {
                 current.setSession(null);
             }
         }
     }
 
     @Override
     public void attributeAdded(final Session sessionfinal String namefinal Object value) {
         if(name.startsWith()) {
             return;
         }
         final HttpSessionImpl httpSession = SecurityActions.forSession(sessionfalse);
        .httpSessionAttributeAdded(httpSessionnamevalue);
        if (value instanceof HttpSessionBindingListener) {
            ((HttpSessionBindingListenervalue).valueBound(new HttpSessionBindingEvent(httpSessionnamevalue));
        }
    }
    @Override
    public void attributeUpdated(final Session sessionfinal String namefinal Object valuefinal Object old) {
        if(name.startsWith()) {
            return;
        }
        final HttpSessionImpl httpSession = SecurityActions.forSession(sessionfalse);
        if (old != value) {
            if (old instanceof HttpSessionBindingListener) {
                ((HttpSessionBindingListenerold).valueUnbound(new HttpSessionBindingEvent(httpSessionnameold));
            }
            .httpSessionAttributeReplaced(httpSessionnameold);
        }
        if (value instanceof HttpSessionBindingListener) {
            ((HttpSessionBindingListenervalue).valueBound(new HttpSessionBindingEvent(httpSessionnamevalue));
        }
    }
    @Override
    public void attributeRemoved(final Session sessionfinal String namefinal Object old) {
        if(name.startsWith()) {
            return;
        }
        final HttpSessionImpl httpSession = SecurityActions.forSession(sessionfalse);
        if (old != null) {
            .httpSessionAttributeRemoved(httpSessionnameold);
            if (old instanceof HttpSessionBindingListener) {
                ((HttpSessionBindingListenerold).valueUnbound(new HttpSessionBindingEvent(httpSessionnameold));
            }
        }
    }
    @Override
    public void sessionIdChanged(Session sessionString oldSessionId) {
    }
New to GrepCode? Check out our FAQ X