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


Java Handshake类代码示例

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


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

示例1: getHandshakeToUse

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
private Handshake getHandshakeToUse(ServletWebSocketHttpExchange exchange, ConfiguredServerEndpoint endpoint) {
	Handshake handshake = new JsrHybi13Handshake(endpoint);
	if (handshake.matches(exchange)) {
		return handshake;
	}
	handshake = new JsrHybi08Handshake(endpoint);
	if (handshake.matches(exchange)) {
		return handshake;
	}
	handshake = new JsrHybi07Handshake(endpoint);
	if (handshake.matches(exchange)) {
		return handshake;
	}
	// Should never occur
	throw new HandshakeFailureException("No matching Undertow Handshake found: " + exchange.getRequestHeaders());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:UndertowRequestUpgradeStrategy.java

示例2: processWebSocketRequest

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
private void processWebSocketRequest(Request request, Response response) {
        HttpServletRequest servletRequest = request.getHttpServletRequest();
        HttpServletResponse servletResponse = response.getHttpServletResponse();

        WebSocketHttpExchange exchange = new ServletWebSocketHttpExchange(servletRequest, servletResponse, peerConnections);
//        exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap());

        Handshake handshake = getHandshake(exchange);

        exchange.upgradeChannel((connection, serverExchange) -> {
            WebSocketChannel channel = handshake.createChannel(exchange, connection, exchange.getBufferPool());
            peerConnections.add(channel);
            createWebSocketAdapter(request).onConnect(exchange, channel);
        });

        handshake.handshake(exchange);
    }
 
开发者ID:decebals,项目名称:pippo,代码行数:18,代码来源:UndertowWebSocketFilter.java

示例3: doGet

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {

    final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections);
    Handshake handshaker = null;
    for (Handshake method : handshakes) {
        if (method.matches(facade)) {
            handshaker = method;
            break;
        }
    }

    if (handshaker == null) {
        UndertowLogger.REQUEST_LOGGER.debug("Could not find hand shaker for web socket request");
        resp.sendError(StatusCodes.BAD_REQUEST);
        return;
    }
    final Handshake selected = handshaker;
    facade.upgradeChannel(new HttpUpgradeListener() {
        @Override
        public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
            WebSocketChannel channel = selected.createChannel(facade, streamConnection, facade.getBufferPool());
            peerConnections.add(channel);
            callback.onConnect(facade, channel);
        }
    });
    handshaker.handshake(facade);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:WebSocketServlet.java

示例4: WebSocketProtocolHandshakeHandler

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
/**
 * Create a new {@link WebSocketProtocolHandshakeHandler}
 *
 * @param callback The {@link WebSocketConnectionCallback} which will be executed once the handshake was
 *                 established
 */
public WebSocketProtocolHandshakeHandler(final WebSocketConnectionCallback callback, final HttpHandler next) {
    this.callback = callback;
    Set<Handshake> handshakes = new HashSet<>();
    handshakes.add(new Hybi13Handshake());
    handshakes.add(new Hybi08Handshake());
    handshakes.add(new Hybi07Handshake());
    this.handshakes = handshakes;
    this.next = next;
    this.upgradeListener = null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:WebSocketProtocolHandshakeHandler.java

示例5: upgradeInternal

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
@Override
protected void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
		String selectedProtocol, List<Extension> selectedExtensions, final Endpoint endpoint)
		throws HandshakeFailureException {

	HttpServletRequest servletRequest = getHttpServletRequest(request);
	HttpServletResponse servletResponse = getHttpServletResponse(response);

	final ServletWebSocketHttpExchange exchange = createHttpExchange(servletRequest, servletResponse);
	exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap());

	ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest);
	final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer);

	final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint(
			selectedProtocol, selectedExtensions, endpoint, servletRequest);

	final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint);

	exchange.upgradeChannel(new HttpUpgradeListener() {
		@Override
		public void handleUpgrade(StreamConnection connection, HttpServerExchange serverExchange) {
			Object bufferPool = ReflectionUtils.invokeMethod(getBufferPoolMethod, exchange);
			WebSocketChannel channel = (WebSocketChannel) ReflectionUtils.invokeMethod(
					createChannelMethod, handshake, exchange, connection, bufferPool);
			if (peerConnections != null) {
				peerConnections.add(channel);
			}
			endpointSessionHandler.onConnect(exchange, channel);
		}
	});

	handshake.handshake(exchange);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:UndertowRequestUpgradeStrategy.java

示例6: getHandshake

import io.undertow.websockets.core.protocol.Handshake; //导入依赖的package包/类
private Handshake getHandshake(WebSocketHttpExchange exchange) {
    for (Handshake handshake : handshakes) {
        if (handshake.matches(exchange)) {
            return handshake;
        }
    }

    throw new PippoRuntimeException("No matching Undertow Handshake found: {}", exchange.getRequestHeaders());
}
 
开发者ID:decebals,项目名称:pippo,代码行数:10,代码来源:UndertowWebSocketFilter.java


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