當前位置: 首頁>>代碼示例>>Java>>正文


Java HandshakeResponse類代碼示例

本文整理匯總了Java中javax.websocket.HandshakeResponse的典型用法代碼示例。如果您正苦於以下問題:Java HandshakeResponse類的具體用法?Java HandshakeResponse怎麽用?Java HandshakeResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HandshakeResponse類屬於javax.websocket包,在下文中一共展示了HandshakeResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的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.HandshakeResponse; //導入依賴的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.HandshakeResponse; //導入依賴的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.HandshakeResponse; //導入依賴的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: afterResponse

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void afterResponse(HandshakeResponse hr) {
    super.afterResponse(hr);
    if( wsHmac != null ) {
        try {
            Log.log(Level.FINEST, drain, "Validating HMAC supplied for WS");
            wsHmac.wsVerifySignature(new SignedRequestMap.MLS_StringMap(hr.getHeaders()));
            Log.log(Level.FINEST, drain, "Validating HMAC result is {0}", responseValid);
        } catch (Exception e) {
            Log.log(Level.FINEST, drain, "Failed to validate HMAC, unable to establish connection", e);
        }

    } else {
        Log.log(Level.INFO, drain, "No token supplied for room, skipping WS handshake validation");
        responseValid = true;
    }
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:18,代碼來源:WebSocketClientConnection.java

示例6: getEndpointConfigs

import javax.websocket.HandshakeResponse; //導入依賴的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

示例7: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的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

示例8: afterResponse

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void afterResponse(HandshakeResponse hr) {
    Map<String, List<String>> headers = hr.getHeaders();
    if (headers.containsKey(SEC_WEB_SOCKET_PROTOCOL_STRING.toLowerCase(Locale.ENGLISH))) {
        receivedSubProtocol = headers.get(SEC_WEB_SOCKET_PROTOCOL_STRING.toLowerCase(Locale.ENGLISH)).get(0);
    } else {
        receivedSubProtocol = null;
    }
    receiveLatch.countDown();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:11,代碼來源:ClientConfigurator.java

示例9: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void modifyHandshake(ServerEndpointConfig sec,
        HandshakeRequest request, HandshakeResponse response)
{
    HttpSession httpSession = (HttpSession) request.getHttpSession();
    sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:8,代碼來源:HttpSessionConfigurator.java

示例10: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:butter-fly,項目名稱:belling-admin,代碼行數:8,代碼來源:HttpChatSessionConfigurator.java

示例11: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    System.out.println("modifyHandshake() Current thread " + Thread.currentThread().getName());
    String user = request.getParameterMap().get("user").get(0);
    sec.getUserProperties().put(user, request.getHttpSession());
    System.out.println("modifyHandshake() User " + user + " with http session ID " + ((HttpSession) request.getHttpSession()).getId());
}
 
開發者ID:abhirockzz,項目名稱:websocket-http-session,代碼行數:8,代碼來源:HttpSessionConfigurator.java

示例12: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
	final HttpSession httpSession = (HttpSession) request.getHttpSession();
	if (request.getUserPrincipal() == null) {
		return;
	}

	final SecurityContext securityCtx = new WebSocketSecurityContext(request);
	sec.getUserProperties().put(key(httpSession.getId()), securityCtx);
}
 
開發者ID:dansiviter,項目名稱:cito,代碼行數:11,代碼來源:WebSocketConfigurator.java

示例13: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@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());

}
 
開發者ID:apache,項目名稱:guacamole-client,代碼行數:15,代碼來源:RestrictedGuacamoleWebSocketTunnelEndpoint.java

示例14: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@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);
}
 
開發者ID:FangStarNet,項目名稱:symphonyx,代碼行數:8,代碼來源:Channels.java

示例15: modifyHandshake

import javax.websocket.HandshakeResponse; //導入依賴的package包/類
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    final Principal principal = request.getUserPrincipal();
    final Subject subject = SecurityActions.getSubject();
    final Object credential = SecurityActions.getCredential();

    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_PRINCIPAL, principal);
    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_SUBJECT, subject);
    sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_CREDENTIAL, credential);
}
 
開發者ID:panga,項目名稱:jboss-security-extended,代碼行數:11,代碼來源:WebsocketSecurityConfigurator.java


注:本文中的javax.websocket.HandshakeResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。