当前位置: 首页>>代码示例>>Java>>正文


Java HandshakeRequest类代码示例

本文整理汇总了Java中javax.websocket.server.HandshakeRequest的典型用法代码示例。如果您正苦于以下问题:Java HandshakeRequest类的具体用法?Java HandshakeRequest怎么用?Java HandshakeRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HandshakeRequest类属于javax.websocket.server包,在下文中一共展示了HandshakeRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: modifyHandshake

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request, HandshakeResponse response) {

    HttpSession httpSession = (HttpSession) request.getHttpSession();

    super.modifyHandshake(config, request, response);

    if (httpSession == null) {
        LOGGER.info("httpSession == null after modifyHandshake");
        httpSession = (HttpSession) request.getHttpSession();
    }

    if (httpSession == null) {
        LOGGER.info("httpSession == null");
        return;
    }

    config.getUserProperties().put("httpSession", httpSession);

    httpSession = (HttpSession) request.getHttpSession();
    LOGGER.info("modifyHandshake " + httpSession.getId());

}
 
开发者ID:webfirmframework,项目名称:tomcat-8-wffweb-demo-apps,代码行数:25,代码来源:WSServerForIndexPage.java

示例2: modifyHandshake

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    super.modifyHandshake(sec, request, response);

    if ( token == null || token.isEmpty() ) {
        Log.log(Level.FINEST, this, "No token set for room, skipping validation");
    } else {
        Log.log(Level.FINEST, this, "Validating WS handshake");
        SignedRequestHmac wsHmac = new SignedRequestHmac("", token, "", request.getRequestURI().getRawPath());

        try {
            wsHmac.checkHeaders(new SignedRequestMap.MLS_StringMap(request.getHeaders()))
                    .verifyFullSignature()
                    .wsResignRequest(new SignedRequestMap.MLS_StringMap(response.getHeaders()));

            Log.log(Level.INFO, this, "validated and resigned", wsHmac);
        } catch(Exception e) {
            Log.log(Level.WARNING, this, "Failed to validate HMAC, unable to establish connection", e);

            response.getHeaders().replace(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, Collections.emptyList());
        }
    }
}
 
开发者ID:gameontext,项目名称:gameon-room,代码行数:24,代码来源:LifecycleManager.java

示例3: modifyHandshake

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request, HandshakeResponse response) {

  Map<String, List<String>> headers = request.getHeaders();
  if (headers != null && headers.containsKey(WatcherSecurityKey.HTTP_HEADER)) {
    List<String> header = headers.get(WatcherSecurityKey.HTTP_HEADER);
    if (header.size() > 0) {
      config.getUserProperties().put(WatcherSecurityKey.HTTP_HEADER, header.
              get(0));
    }
  }
  HttpSession httpSession = (HttpSession) request.getHttpSession();
  String user = request.getUserPrincipal().getName();
  config.getUserProperties().put("httpSession", httpSession);
  config.getUserProperties().put("user", user);
  logger.log(Level.INFO, "Hand shake for upgrade to websocket by: {0}", user);
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:19,代码来源:ZeppelinEndpointConfig.java

示例4: modifyHandshake

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Intercept the handshake operation so that we can take a hold of the
 * ServletContext instance to be able to retrieve attributes stored to it
 * such as the database object and other similar class instances
 * <p/>
 * @param config
 * @param request
 * @param response
 */
@Override
public void modifyHandshake(ServerEndpointConfig config,
        HandshakeRequest request, HandshakeResponse response) {

  HttpSession httpSession = (HttpSession) request.getHttpSession();
  ServletContext context = (ServletContext) httpSession.getServletContext();

  config.getUserProperties().put("httpSession", httpSession);
  config.getUserProperties().put("user", request.getUserPrincipal().getName());

  /*
   * store these attributes to servletContext so that they are available to
   * every created user socket session
   */
  config.getUserProperties().put("protocol", context.getAttribute("protocol"));
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:26,代码来源:ServletAwareConfig.java

示例5: testHandleOpenConnexion

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Test of handleOpenConnexion method, of class IWSControllerMonitor.
 * @throws java.lang.Exception
 */
@Test
public void testHandleOpenConnexion() throws Exception {
	System.out.println("handleOpenConnexion");
	Session session = mock(Session.class);
	EndpointConfig config = mock(EndpointConfig.class);
	HandshakeRequest handshakeRequest = mock(HandshakeRequest.class);
	HttpSession httpSession = mock(HttpSession.class);
	Map<String, Object> configProperties = mock(Map.class);
	
	when(config.getUserProperties()).thenReturn(configProperties);
	when(handshakeRequest.getHttpSession()).thenReturn(httpSession);
	when(httpSession.getId()).thenReturn("SESSIONID");
	when(configProperties.get(eq(Constants.HANDSHAKEREQUEST))).thenReturn(handshakeRequest);
	
	instance.handleOpenConnexion(session, config);
	
	verify(httpSessionManager).addSession(eq(session), eq("SESSIONID"));
	verify(iwse).handleOpenConnexion(eq(session), eq(config));
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:24,代码来源:IWSControllerMonitorTest.java

示例6: getLocale

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Return locale of client
 *
 * @param request
 * @return
 */
Locale getLocale(HandshakeRequest request) {
	if(null != request) {
		Map<String, List<String>> headers = request.getHeaders();
		if(null != headers) {
			List<String> accepts = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
			logger.debug("Get accept-language from client headers : {}", accepts);
			if (null != accepts) {
				for (String accept : accepts) {
					try {
						return localeExtractor.extractFromAccept(accept);
					} catch (LocaleNotFoundException ex) {
					}
				}
			}
		}
	}
	return Locale.US;
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:25,代码来源:WSController.java

示例7: testHandleOpenConnexionFromBrowser

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Test of handleOpenConnexion method, of class WSEndpoint.
 *
 * @throws java.io.IOException
 */
@Test
public void testHandleOpenConnexionFromBrowser() throws IOException {
	System.out.println("handleOpenConnexion");
	HandshakeRequest request = mock(HandshakeRequest.class);
	EndpointConfig config = mock(EndpointConfig.class);
	Map<String, Object> map = new HashMap<>();
	map.put(Constants.HANDSHAKEREQUEST, request);
	Session session = mock(Session.class);

	when(config.getUserProperties()).thenReturn(map);
	when(session.getId()).thenReturn("WSSESSIONID");
	doNothing().when(instance).setContext(eq(request));

	instance.handleOpenConnexion(session, config);

	verify(userContextFactory).createUserContext(any(HandshakeRequest.class), eq("WSSESSIONID"));
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:23,代码来源:WSControllerTest.java

示例8: testHandleOpenConnexion

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Test of handleOpenConnexion method, of class IWSDecorator.
 * @throws java.lang.Exception
 */
@Test
public void testHandleOpenConnexion() throws Exception {
	System.out.println("handleOpenConnexion");
	Session session = mock(Session.class);
	EndpointConfig config = mock(EndpointConfig.class);
	Map map = mock(Map.class);
	HandshakeRequest request = mock(HandshakeRequest.class);
	HttpSession httpSession = mock(HttpSession.class);
	when(session.getId()).thenReturn("WSID");
	when(config.getUserProperties()).thenReturn(map);
	when(map.get(eq(Constants.HANDSHAKEREQUEST))).thenReturn(request);
	when(request.getHttpSession()).thenReturn(httpSession);
	when(httpSession.getId()).thenReturn("HTTPID");
	instance.handleOpenConnexion(session, config);
	verify(sessionManager).linkWsToHttp(eq(session), eq("HTTPID"));
	verify(iwse).handleOpenConnexion(eq(session), eq(config));
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:22,代码来源:IWSDecoratorTest.java

示例9: testGetPrincipal_HandshakeRequest

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Test of getPrincipal method, of class PrincipalTools.
 */
@Test
public void testGetPrincipal_HandshakeRequest() {
	System.out.println("getPrincipal");
	HandshakeRequest handshakeRequest = mock(HandshakeRequest.class);
	Principal principal = mock(Principal.class);
	when(principal.getName()).thenReturn("FOO");
	when(handshakeRequest.getUserPrincipal()).thenReturn(null).thenReturn(principal);
	Principal result = instance.getPrincipal(handshakeRequest);
	assertThat(result).isNotNull();
	assertThat(result.getName()).isEqualTo(Constants.ANONYMOUS);

	result = instance.getPrincipal(handshakeRequest);
	assertThat(result).isEqualTo(principal);
	assertThat(result.getName()).isEqualTo("FOO");
	
	handshakeRequest = null;
	result = instance.getPrincipal(handshakeRequest);
	assertThat(result).isNotNull();
	assertThat(result.getName()).isEqualTo(Constants.ANONYMOUS);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:24,代码来源:PrincipalToolsTest.java

示例10: testGetPrincipal

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
/**
 * Test of getPrincipal method, of class WsUserContext.
 */
@Test
public void testGetPrincipal() {
	System.out.println("getPrincipal");
	Principal principal = mock(Principal.class);
	PrincipalTools principalTools = mock(PrincipalTools.class);
	HandshakeRequest handshakeRequest = mock(HandshakeRequest.class);
	when(principalTools.getPrincipal(eq(handshakeRequest))).thenReturn(principal);

	WsUserContext instance = new WsUserContext(handshakeRequest);
	instance.principalTools = principalTools;

	Principal result = instance.getPrincipal();

	assertThat(result).isNotNull();
	assertThat(result).isEqualTo(principal);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:20,代码来源:WsUserContextTest.java

示例11: getEndpointConfigs

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set) {
    return new HashSet<ServerEndpointConfig>() {{
        add(ServerEndpointConfig.Builder
                .create(MyEndpoint.class, "/websocket")
                .configurator(new ServerEndpointConfig.Configurator() {

                    @Override
                    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
                        HttpSession session = (HttpSession)request.getHttpSession();
                        System.out.println("HttpSession id: " + session.getId());
                        System.out.println("HttpSession creation time: " + session.getCreationTime());
                        super.modifyHandshake(sec, request, response);
                    }

                })
                .build());
    }};
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:20,代码来源:MyApplicationConfig.java

示例12: modifyHandshake

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
	HttpServletRequest _request = (HttpServletRequest) GenericReflection.NoThrow.getValue(_HandshakeRequest, request);
	Request _requestFaced = (Request) GenericReflection.NoThrow.getValue(Core.requestField, _request);
	
	MimeHeaders mime = new MimeHeaders();
	
	Enumeration<String> enuns = _requestFaced.getHeaderNames();
	while(enuns.hasMoreElements()){
		String param = (String) enuns.nextElement();		
		mime.addValue(param).setString(_requestFaced.getHeader(param));
	}
	
	Map<String, Object> properties = config.getUserProperties();
	
	properties.put("httpRequest", _request);
	properties.put("httpResponse", _request.getAttribute("httpResponse"));
	properties.put("httpSession", _request.getSession());
	properties.put("context", _requestFaced.getContext());
	properties.put("headers", mime);
	properties.put("remoteHost", _request.getRemoteHost());
	properties.put("localPort", _request.getLocalPort());		
	properties.put("remoteAddr", _request.getRemoteAddr());
}
 
开发者ID:mehah,项目名称:jRender,代码行数:24,代码来源:WebSocketConfigurator.java

示例13: authenticate

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public String authenticate(HandshakeRequest request) throws AuthenticationException {
    SecurityContext context = SecurityContextHolder.getContext();
    if (context == null) {
        throw new AuthenticationException("User not authenticateded", "Anonymous");
    }

    Authentication authentication = context.getAuthentication();
    if (authentication == null) {
        throw new AuthenticationException("User not authenticateded", "Anonymous");
    }
    if (authentication.isAuthenticated()) {
        return authentication.getName();
    } else {
        throw new AuthenticationException("User not authenticateded", authentication.getName());
    }
}
 
开发者ID:wigforss,项目名称:Ka-Websocket,代码行数:18,代码来源:SpringSecurityAuthenticationProvider.java

示例14: authenticate

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public String authenticate(AuthenticationProvider provider, HandshakeRequest request) throws AuthenticationException {
    AuthenticationProvider auth = resolveAuthenticationProvider(provider);
    if (auth != null) {
        try {
            String username = auth.authenticate(request);
            fireAuthentication(username, request, null);
            return username;
        } catch(AuthenticationException ae) {
            LOG.warn("Unauthorized access by " + ae.getUsername() + " : " +ae.getMessage());
            fireAuthentication(ae.getUsername(), request, ae);
            throw ae;
        }    
        
    }
    return null;
   
}
 
开发者ID:wigforss,项目名称:Ka-Websocket,代码行数:19,代码来源:ClientChannelImpl.java

示例15: getId

import javax.websocket.server.HandshakeRequest; //导入依赖的package包/类
@Override
public String getId(HandshakeRequest request,
                    ClientChannel manager) {
    String clientId = getIdValue(request);
   
    if (manager.hasClient(clientId)) {
        clientId = clientId + "-" + getUuid();
    }
    if (clientId == null) {
        clientId = getUuid();
    }
    
   
    
    return clientId;
}
 
开发者ID:wigforss,项目名称:Ka-Websocket,代码行数:17,代码来源:ClientIdGeneratorImpl.java


注:本文中的javax.websocket.server.HandshakeRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。