Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package io.undertow.servlet.handlers;
  
  import java.util.List;
  
 
All the information that servlet needs to attach to the exchange.

This is all stored under this class, rather than using individual attachments, as this approach has significant performance advantages.

The ServletInitialHandler also pushed this information to the CURRENT thread local, which allows it to be access even if the request or response have been wrapped with non-compliant wrapper classes.

Author(s):
Stuart Douglas
 
 public class ServletRequestContext {
 
     private static final RuntimePermission GET_CURRENT_REQUEST = new RuntimePermission("io.undertow.servlet.GET_CURRENT_REQUEST");
     private static final RuntimePermission SET_CURRENT_REQUEST = new RuntimePermission("io.undertow.servlet.SET_CURRENT_REQUEST");
 
     private static final ThreadLocal<ServletRequestContextCURRENT = new ThreadLocal<ServletRequestContext>();
 
     public static void setCurrentRequestContext(ServletRequestContext servletRequestContext) {
         if(System.getSecurityManager() != null) {
             AccessController.checkPermission();
         }
         .set(servletRequestContext);
     }
 
     public static void clearCurrentServletAttachments() {
         if(System.getSecurityManager() != null) {
             AccessController.checkPermission();
         }
         .remove();
     }
 
     public static ServletRequestContext requireCurrent() {
         if(System.getSecurityManager() != null) {
             AccessController.checkPermission();
         }
         ServletRequestContext attachments = .get();
         if (attachments == null) {
             throw ..noRequestActive();
         }
         return attachments;
     }
 
     public static ServletRequestContext current() {
         if(System.getSecurityManager() != null) {
             AccessController.checkPermission();
         }
         return .get();
     }
 
     public static final AttachmentKey<ServletRequestContextATTACHMENT_KEY = AttachmentKey.create(ServletRequestContext.class);
 
     private final Deployment deployment;
     private final HttpServletRequestImpl originalRequest;
     private final HttpServletResponseImpl originalResponse;
     private final ServletPathMatch originalServletPathMatch;
     private ServletResponse servletResponse;
     private ServletRequest servletRequest;
     private DispatcherType dispatcherType;
 
     private ServletChain currentServlet;
 
     private HttpSessionImpl session;
 
 
     public ServletRequestContext(final Deployment deploymentfinal HttpServletRequestImpl originalRequestfinal HttpServletResponseImpl originalResponsefinal ServletPathMatch originalServletPathMatch) {
         this. = deployment;
         this. = originalRequest;
         this. = originalResponse;
         this. = originalRequest;
         this. = originalResponse;
        this. = originalServletPathMatch;
        this. = deployment.getServletContext();
    }
    public Deployment getDeployment() {
        return ;
    }
    public ServletChain getCurrentServlet() {
        return ;
    }
    public void setCurrentServlet(ServletChain currentServlet) {
        this. = currentServlet;
    }
        return ;
    }
    public void setServletPathMatch(ServletPathMatch servletPathMatch) {
        this. = servletPathMatch;
    }
        return ;
    }
    public void setRequiredConstrains(List<SingleConstraintMatchrequiredConstrains) {
        this. = requiredConstrains;
    }
        return ;
    }
    public void setTransportGuarenteeType(TransportGuaranteeType transportGuarenteeType) {
        this. = transportGuarenteeType;
    }
        return ;
    }
    public void setServletResponse(ServletResponse servletResponse) {
        this. = servletResponse;
    }
    public ServletRequest getServletRequest() {
        return ;
    }
    public void setServletRequest(ServletRequest servletRequest) {
        this. = servletRequest;
    }
    public DispatcherType getDispatcherType() {
        return ;
    }
    public void setDispatcherType(DispatcherType dispatcherType) {
        this. = dispatcherType;
    }
        return ;
    }
        return ;
    }
    public HttpSessionImpl getSession() {
        return ;
    }
    public void setSession(final HttpSessionImpl session) {
        this. = session;
    }
    public HttpServerExchange getExchange() {
        return .getExchange();
    }
        return ;
    }
        return ;
    }
    public void setCurrentServletContext(ServletContextImpl currentServletContext) {
        this. = currentServletContext;
    }
    public boolean displayStackTraces() {
        if (mode == .) {
            return false;
        } else if (mode == .) {
            return true;
        } else {
            InetSocketAddress localAddress = getExchange().getSourceAddress();
            if(localAddress == null) {
                return false;
            }
            if(!localAddress.getAddress().isLoopbackAddress()) {
                return false;
            }
            return !getExchange().getRequestHeaders().contains(.);
        }
    }
New to GrepCode? Check out our FAQ X