title: HttpServletRequest.GetSession returns null
body: <p>I have a simple JEE app, which breaks at login. It was working fine before I transferred it from Neon to Mars. Although I changed Server Runtime to WildFly 10.0, it still says that my Server Runtime 10.x is not bound (I changed the runtime both for the Web and EJB project. Anyway, this is my method:</p>
  
  <pre><code>public String login(){
          UserDto user = usersBean.validateUser(username, password);
          if(null == user){
              MessageUtils.addErrorMessage("login.error.invalid.credentials");
              return "";
          } else{
              request.getSession().setAttribute("LOGGED_USER", user);
              ******the upper code fails********
              return SUCCESS_LOGIN_REDIRECT;
          }
      }
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>Context Path:/JEEProjectWeb
  Servlet Path:/page/login.html
  Path Info:null
  Query String:null
  Stack Trace
  javax.servlet.ServletException: java.lang.NullPointerException
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
  io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
  io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
  bg.JEE.web.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:60)
  io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
  io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
  io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
  io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
  io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
  org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
  io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
  io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
  io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
  io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
  io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
  io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
  io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
  io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
  io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
  io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
  io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
  io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
  io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
  io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
  io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I am very new at this and have no clue what may be causing this error. But I've tried putting request.getSession() in a variable and on debugging it returned null, so there should be no problem with the setAttribute function.</p>
  
  <p>Please assist me! Thanks in advance!</p>
  
  <p>Additional info:</p>
  
  <p>Authentication filter:</p>
  
  <pre><code>package bg.JEE.web.filter;
  import java.io.IOException;
  import java.io.Serializable;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import bg.JEE.dto.UserDto;
  
  public class AuthenticationFilter implements Filter, Serializable {
  
      private static final long serialVersionUID = 1L;
  
      public static final String PATH_INDEX = "/index.jsp";
      public static final String PATH_LOGIN = "/page/login.html";
      public static final String PATH_LOGOUT = "/page/logout.jsp";
  
      public void init(FilterConfig filterConfig) throws ServletException {
  
      }
  
      public void destroy() {
      }
  
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
              throws IOException, ServletException {
  
          HttpServletRequest httpRequest = (HttpServletRequest) request;
  
          String requestedPath = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
  
          /*
           * Skip the action with path "index.jsp" - there is no logged user, but
           * the user is redirected to login screen
           */
          if (PATH_INDEX.equals(requestedPath)) {
              chain.doFilter(request, response); --row 60
              return;
          }
          /*
           * Skip the action with path "/login.login.html" - there is no logged
           * user, but the user is trying to log in
           */
          if (PATH_LOGIN.equals(requestedPath)) {
              chain.doFilter(request, response);
              return;
          }
  
          /*
           * Get logged user from the HttpSession
           */
          HttpSession session = httpRequest.getSession();
          UserDto loggedUser = (UserDto) session.getAttribute("LOGGED_USER");
  
          /*
           * Redirect to login page if there is no logged user and trying to
           * access protected resource
           */
          if (loggedUser == null) {
              RequestDispatcher requestDispatcher = request.getRequestDispatcher(PATH_LOGIN);
              requestDispatcher.forward(request, response);
              return;
          } else {
              chain.doFilter(request, response);
              return;
          }
  
      }
  }
  </code></pre>
  
  <p>And here's the row 60 code from LoginBean:</p>
  
  <pre><code>public void setUsername(String username) {
          this.username = username;
      }
  </code></pre>