/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.api.core.websocket.impl;

import com.google.inject.Injector;
import javax.inject.Inject;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * Allows inject Guice instances on WEB SOCKET endpoint creation.
 *
 * @author Dmitry Kuleshov
 */
public class GuiceInjectorEndpointConfigurator extends ServerEndpointConfig.Configurator {
  @Inject private static Injector injector;

  public <T> T getEndpointInstance(Class<T> endpointClass) {
    return injector.getInstance(endpointClass);
  }

  @Override
  public void modifyHandshake(
      ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    HttpSession httpSession = (HttpSession) request.getHttpSession();
    Object sessionSubject = httpSession.getAttribute("che_subject");
    if (sessionSubject != null) {
      sec.getUserProperties().put("che_subject", sessionSubject);
    }
  }
}

@@ -1185,16 +1185,49 @@
 sion();%0A
+    if (httpSession != null) %7B%0A  
     Obje
@@ -1287,24 +1287,26 @@
 ject%22);%0A    
+ 
+ 
 if (sessionS
@@ -1319,24 +1319,26 @@
  != null) %7B%0A
+  
       sec.ge
@@ -1391,16 +1391,24 @@
 bject);%0A
+      %7D%0A
     %7D%0A  

Fix putting Che Subject into ServerEndpointConfig if http session is null (#10993)