本文整理匯總了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());
}
示例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());
}
}
}
示例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);
}
示例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"));
}
示例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;
}
}
示例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());
}};
}
示例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());
}
示例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);
}
示例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);
}
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}