javax.websocket.HandshakeResponse Java Examples

The following examples show how to use javax.websocket.HandshakeResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void afterRequest(final HttpHeaders headers) {
    ClientEndpointConfig.Configurator configurator = config.getConfigurator();
    if (configurator != null) {
        final Map<String, List<String>> newHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        for (Map.Entry<String, String> entry : headers) {
            ArrayList<String> arrayList = new ArrayList<>(headers.getAll(entry.getKey()));
            newHeaders.put(entry.getKey(), arrayList);
        }
        configurator.afterResponse(new HandshakeResponse() {
            @Override
            public Map<String, List<String>> getHeaders() {
                return newHeaders;
            }
        });
    }
    headers.remove(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
    super.afterRequest(headers);
}
 
Example #2
Source File: Channels.java    From symphonyx with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(final ServerEndpointConfig config,
        final HandshakeRequest request, final HandshakeResponse response) {
    final HttpSession httpSession = (HttpSession) request.getHttpSession();

    config.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
 
Example #3
Source File: HttpChatSessionConfigurator.java    From belling-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
	HttpSession httpSession = (HttpSession) request.getHttpSession();
	if (null != httpSession) {
		config.getUserProperties().put(HttpSession.class.getName(), httpSession);
	}
}
 
Example #4
Source File: MCRWebsocketDefaultConfigurator.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
    HttpSession httpSession = (HttpSession) request.getHttpSession();
    config.getUserProperties().put(MCRServlet.ATTR_MYCORE_SESSION,
        httpSession.getAttribute(MCRServlet.ATTR_MYCORE_SESSION));
    config.getUserProperties().put(HTTP_SESSION, httpSession);
}
 
Example #5
Source File: WsConfigurator.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
	try {
		EffectivePerson effectivePerson = this.getEffectivePerson(request);
		config.getUserProperties().put(HttpToken.X_Person, effectivePerson);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: WsConfigurator.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
	try {
		EffectivePerson effectivePerson = this.getEffectivePerson(request);
		config.getUserProperties().put(HttpToken.X_Person, effectivePerson);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #7
Source File: RestrictedGuacamoleWebSocketTunnelEndpoint.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request, HandshakeResponse response) {

    super.modifyHandshake(config, request, response);
    
    // Store tunnel request and tunnel request service for retrieval
    // upon WebSocket open
    Map<String, Object> userProperties = config.getUserProperties();
    userProperties.clear();
    userProperties.put(TUNNEL_REQUEST_PROPERTY, new WebSocketTunnelRequest(request));
    userProperties.put(TUNNEL_REQUEST_SERVICE_PROPERTY, tunnelRequestServiceProvider.get());

}
 
Example #8
Source File: WebsocketSecurityConfigurator.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    super.modifyHandshake(sec, request, response);
    
    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_PRINCIPAL, request.getUserPrincipal());
    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_SUBJECT, SecurityContextAssociation.getSubject());
    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_CREDENTIAL, SecurityContextAssociation.getPrincipal());
    Map<String,List<String>> headers = request.getHeaders();
    if (headers != null) {
        List<String> loginHeader = headers.get(REQUEST_LOGIN_TIME_HEADER);
        if (loginHeader != null && !loginHeader.isEmpty()) {
            sec.getUserProperties().put(REQUEST_LOGIN_TIME_HEADER, loginHeader.get(0));
        }
    }
}
 
Example #9
Source File: WebsocketSessionConfigurator.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request,
        HandshakeResponse response) {
    HttpSession httpSession = (HttpSession)request.getHttpSession();
    config.getUserProperties().put("webUserID", httpSession.getAttribute("webUserID"));
}
 
Example #10
Source File: GuiceInjectorEndpointConfigurator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(
    ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
  HttpSession httpSession = (HttpSession) request.getHttpSession();
  if (httpSession != null) {
    Object sessionSubject = httpSession.getAttribute("che_subject");
    if (sessionSubject != null) {
      sec.getUserProperties().put("che_subject", sessionSubject);
    }
  }
}
 
Example #11
Source File: AngularBeansServletContextListener.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
	return new ServerEndpointConfig.Configurator() {

		@Override
		public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
			try {
				return endpointClass.getConstructor(SockJsServer.class, String.class, String.class)
						.newInstance(sockJsServer, context.getContextPath(), prefix);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}

		@Override
		public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
				HandshakeResponse response) {
			if (isRaw) {
				// We have no reliable key (like session id) to save
				// headers with for raw websocket requests
				return;
			}
			String path = request.getRequestURI().getPath();
			Matcher matcher = SESSION_PATTERN.matcher(path);
			if (matcher.matches()) {
				String sessionId = matcher.group(1);
				saveHeaders(sessionId, request.getHeaders());
			}
		}
	};
}
 
Example #12
Source File: Configurator.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse(HandshakeResponse response) {
  List<String> cookie = response.getHeaders().get("set-cookie");
  if (cookie != null) {
    cookieHolder.set(cookie);
  }
}
 
Example #13
Source File: SessionConfigurator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse( HandshakeResponse hr ) {
  try {
    if ( loginContext != null ) {
      loginContext.logout();
    }
  } catch ( LoginException e ) {
    e.printStackTrace();
    //work is done just ignore
  }
}
 
Example #14
Source File: RestrictedGuacamoleWebSocketTunnelEndpoint.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request, HandshakeResponse response) {

    super.modifyHandshake(config, request, response);
    
    // Store tunnel request and tunnel request service for retrieval
    // upon WebSocket open
    Map<String, Object> userProperties = config.getUserProperties();
    userProperties.clear();
    userProperties.put(TUNNEL_REQUEST_PROPERTY, new WebSocketTunnelRequest(request));
    userProperties.put(TUNNEL_REQUEST_SERVICE_PROPERTY, tunnelRequestServiceProvider.get());

}
 
Example #15
Source File: GetHttpSessionConfigurator.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config,
		HandshakeRequest request, HandshakeResponse response) {
	HttpSession httpSession = (HttpSession) request.getHttpSession();
	config.getUserProperties()
			.put(HttpSession.class.getName(), httpSession);
}
 
Example #16
Source File: ServerContainerInitializeListener.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
private Configurator createConfigurator() {
    return new Configurator() {
        @Override
        public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
            super.modifyHandshake(sec, request, response);
            final HttpSession httpSession = (HttpSession)request.getHttpSession();
            if (httpSession != null) {
                sec.getUserProperties().put(HTTP_SESSION_ATTRIBUTE, httpSession);
            }
            final SecurityContext securityContext = createSecurityContext(request);
            sec.getUserProperties().put(SECURITY_CONTEXT, securityContext);
        }
    };
}
 
Example #17
Source File: ChatEndpointConfig.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, 
                            HandshakeRequest request, 
                            HandshakeResponse response)
{
    HttpSession httpSession = (HttpSession)request.getHttpSession();
    if (httpSession == null) {
    	return;
    }
    config.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
 
Example #18
Source File: SockJsServlet.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
	return new ServerEndpointConfig.Configurator() {

		@Override
		public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
			try {
				return endpointClass.getConstructor(SockJsServer.class, String.class, String.class)
						.newInstance(sockJsServer, getServletContext().getContextPath(), prefix);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}

		@Override
		public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
				HandshakeResponse response) {

			if (isRaw) {
				// We have no reliable key (like session id) to save
				// headers with for raw websocket requests
				return;
			}

			String path = request.getRequestURI().getPath();
			Matcher matcher = SESSION_PATTERN.matcher(path);
			if (matcher.matches()) {
				String sessionId = matcher.group(1);
				saveHeaders(sessionId, request.getHeaders());
			}
		}
	};
}
 
Example #19
Source File: ClientConfigurator.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse(HandshakeResponse hr) {
    Map<String, List<String>> headers = hr.getHeaders();
    if (headers.containsKey(SEC_WEB_SOCKET_PROTOCOL.toLowerCase(Locale.ENGLISH))) {
        receivedSubProtocol = headers.get(SEC_WEB_SOCKET_PROTOCOL.toLowerCase(Locale.ENGLISH)).get(0);
    } else {
        receivedSubProtocol = null;
    }
    receiveLatch.countDown();
}
 
Example #20
Source File: DefaultServerEndpointConfig.java    From ameba with MIT License 4 votes vote down vote up
/**
 * <p>Constructor for DefaultServerEndpointConfig.</p>
 *
 * @param manager a manager
 * @param endpointClass  a {@link java.lang.Class} endpoint class.
 * @param webSocketConf  a {@link ameba.websocket.WebSocket} object.
 */
public DefaultServerEndpointConfig(final InjectionManager manager,
                                   Class endpointClass,
                                   final WebSocket webSocketConf) {
    path = webSocketConf.path();
    subprotocols = Arrays.asList(webSocketConf.subprotocols());
    encoders = Lists.newArrayList(webSocketConf.encoders());
    decoders = Lists.newArrayList(webSocketConf.decoders());
    for (Class<? extends Extension> extensionClass : webSocketConf.extensions()) {
        extensions.add(Injections.getOrCreate(manager, extensionClass));
    }
    final WebSocketEndpointProvider provider = manager.getInstance(WebSocketEndpointProvider.class);

    final EndpointMeta endpointMeta = provider.parseMeta(endpointClass, webSocketConf);

    final ServerEndpointConfig.Configurator cfgr =
            Injections.getOrCreate(manager, webSocketConf.configurator());
    serverEndpointConfigurator = new ServerEndpointConfig.Configurator() {

        @Override
        public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
            return cfgr.getNegotiatedSubprotocol(supported, requested);
        }

        @Override
        public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
            return cfgr.getNegotiatedExtensions(installed, requested);
        }

        @Override
        public boolean checkOrigin(String originHeaderValue) {
            return cfgr.checkOrigin(originHeaderValue);
        }

        @Override
        public void modifyHandshake(ServerEndpointConfig sec,
                                    HandshakeRequest request, HandshakeResponse response) {
            cfgr.modifyHandshake(sec, request, response);
        }

        @Override
        public <T> T getEndpointInstance(Class<T> eClass) throws InstantiationException {
            if (EndpointDelegate.class.equals(eClass)) {
                return eClass.cast(new EndpointDelegate(endpointMeta));
            }
            return cfgr.getEndpointInstance(eClass);
        }
    };
}
 
Example #21
Source File: ServerEndpointConfig.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public void modifyHandshake(ServerEndpointConfig sec,
        HandshakeRequest request, HandshakeResponse response) {
    fetchContainerDefaultConfigurator().modifyHandshake(sec, request, response);
}
 
Example #22
Source File: WebSocketConfig.java    From mdw with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    List<String> header = new ArrayList<>();
    header.add(ApplicationContext.getHostname());
    response.getHeaders().put("mdw-hostname", header);
}
 
Example #23
Source File: ServerEndpointConfig.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void modifyHandshake(ServerEndpointConfig sec,
        HandshakeRequest request, HandshakeResponse response) {
    fetchContainerDefaultConfigurator().modifyHandshake(sec, request, response);
}
 
Example #24
Source File: DefaultServerEndpointConfigurator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig sec,
        HandshakeRequest request, HandshakeResponse response) {
    // NO-OP
}
 
Example #25
Source File: WsWebSocketContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public HandshakeResponse getHandshakeResponse() {
    return handshakeResponse;
}
 
Example #26
Source File: WsWebSocketContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public HttpResponse(int status, HandshakeResponse handshakeResponse) {
    this.status = status;
    this.handshakeResponse = handshakeResponse;
}
 
Example #27
Source File: ServerEndpointRegistration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
	super.modifyHandshake(this, request, response);
}
 
Example #28
Source File: StandardWebSocketClient.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void afterResponse(HandshakeResponse response) {
	if (logger.isTraceEnabled()) {
		logger.trace("Handshake response headers: " + response.getHeaders());
	}
}
 
Example #29
Source File: WSEndpointConfigurator.java    From diirt with MIT License 4 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config,
                            HandshakeRequest request,
                            HandshakeResponse response) {
    config.getUserProperties().put("session",request.getHttpSession());
}
 
Example #30
Source File: BrokerSessionConfigurator.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
    WebSocketUtil.saveHttpSession(config, request);
}