gpt4 book ai didi

io.netty.handler.codec.http.websocketx.WebSocketHandshakeException类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 08:55:05 25 4
gpt4 key购买 nike

本文整理了Java中io.netty.handler.codec.http.websocketx.WebSocketHandshakeException类的一些代码示例,展示了WebSocketHandshakeException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocketHandshakeException类的具体详情如下:
包路径:io.netty.handler.codec.http.websocketx.WebSocketHandshakeException
类名称:WebSocketHandshakeException

WebSocketHandshakeException介绍

[英]Exception during handshaking process
[中]握手过程中出现异常

代码示例

代码示例来源:origin: wildfly/wildfly

FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.SWITCHING_PROTOCOLS);
  res.headers().add(headers);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
  throw new WebSocketHandshakeException("not a WebSocket request: missing key");
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
  String selectedSubprotocol = selectSubprotocol(subprotocols);

代码示例来源:origin: wildfly/wildfly

protected void verify(FullHttpResponse response) {
  final HttpResponseStatus status = HttpResponseStatus.SWITCHING_PROTOCOLS;
  final HttpHeaders headers = response.headers();
  if (!response.status().equals(status)) {
    throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
  CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
  if (!HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(upgrade)) {
    throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
  if (!headers.containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {
    throw new WebSocketHandshakeException("Invalid handshake response connection: "
        + headers.get(HttpHeaderNames.CONNECTION));
  CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
  if (accept == null || !accept.equals(expectedChallengeResponseString)) {
    throw new WebSocketHandshakeException(String.format(
        "Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

代码示例来源:origin: wildfly/wildfly

if (!req.headers().containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)
    || !HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
          req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);

代码示例来源:origin: org.jboss.aerogear/aerogear-netty-codec-sockjs

if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, req.headers().get(CONNECTION))
    || !HttpHeaders.equalsIgnoreCase(WEBSOCKET, req.headers().get(Names.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(CONNECTION, Values.UPGRADE);
    String selectedSubprotocol = selectSubprotocol(subprotocols);
    if (selectedSubprotocol == null) {
      throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
    } else {
      res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

代码示例来源:origin: wildfly/wildfly

String receivedProtocol = response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
receivedProtocol = receivedProtocol != null ? receivedProtocol.trim() : null;
String expectedProtocol = expectedSubprotocol != null ? expectedSubprotocol : "";
  throw new WebSocketHandshakeException(String.format(
      "Invalid subprotocol. Actual: %s. Expected one of: %s",
      receivedProtocol, expectedSubprotocol));

代码示例来源:origin: bitrich-info/xchange-stream

LOG.error("WebSocket Client failed to connect. {}", e.getMessage());
  handshakeFuture.setFailure(e);
throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
 super.channelInactive(ctx);
 // if still handshaking this means we not got any response back from the server and so need to notify the client
 // about it as otherwise the client would never been notified.
 if (handshaking) {
  handleException(new WebSocketHandshakeException("Connection closed while handshake in process"));
 }
}

代码示例来源:origin: wildfly/wildfly

protected void verify(FullHttpResponse response) {
  final HttpResponseStatus status = HttpResponseStatus.SWITCHING_PROTOCOLS;
  final HttpHeaders headers = response.headers();
  if (!response.status().equals(status)) {
    throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
  CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
  if (!HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(upgrade)) {
    throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
  if (!headers.containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {
    throw new WebSocketHandshakeException("Invalid handshake response connection: "
        + headers.get(HttpHeaderNames.CONNECTION));
  CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
  if (accept == null || !accept.equals(expectedChallengeResponseString)) {
    throw new WebSocketHandshakeException(String.format(
        "Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

代码示例来源:origin: io.netty/netty-codec-http

if (!req.headers().containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)
    || !HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
          req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);

代码示例来源:origin: aerogear/aerogear-simplepush-server

if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, req.headers().get(CONNECTION))
    || !HttpHeaders.equalsIgnoreCase(WEBSOCKET, req.headers().get(Names.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(CONNECTION, Values.UPGRADE);
    String selectedSubprotocol = selectSubprotocol(subprotocols);
    if (selectedSubprotocol == null) {
      throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
    } else {
      res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

代码示例来源:origin: io.netty/netty-codec-http

String receivedProtocol = response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
receivedProtocol = receivedProtocol != null ? receivedProtocol.trim() : null;
String expectedProtocol = expectedSubprotocol != null ? expectedSubprotocol : "";
  throw new WebSocketHandshakeException(String.format(
      "Invalid subprotocol. Actual: %s. Expected one of: %s",
      receivedProtocol, expectedSubprotocol));

代码示例来源:origin: wildfly/wildfly

throw new WebSocketHandshakeException("Protocol version " + version + " not supported.");

代码示例来源:origin: wildfly/wildfly

FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.SWITCHING_PROTOCOLS);
if (headers != null) {
  res.headers().add(headers);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
  throw new WebSocketHandshakeException("not a WebSocket request: missing key");
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
  String selectedSubprotocol = selectSubprotocol(subprotocols);

代码示例来源:origin: wildfly/wildfly

protected void verify(FullHttpResponse response) {
  final HttpResponseStatus status = HttpResponseStatus.SWITCHING_PROTOCOLS;
  final HttpHeaders headers = response.headers();
  if (!response.status().equals(status)) {
    throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
  CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
  if (!HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(upgrade)) {
    throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
  if (!headers.containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {
    throw new WebSocketHandshakeException("Invalid handshake response connection: "
        + headers.get(HttpHeaderNames.CONNECTION));
  CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
  if (accept == null || !accept.equals(expectedChallengeResponseString)) {
    throw new WebSocketHandshakeException(String.format(
        "Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

代码示例来源:origin: apache/activemq-artemis

if (!req.headers().containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)
    || !HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
          req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);

代码示例来源:origin: apache/activemq-artemis

String receivedProtocol = response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
receivedProtocol = receivedProtocol != null ? receivedProtocol.trim() : null;
String expectedProtocol = expectedSubprotocol != null ? expectedSubprotocol : "";
  throw new WebSocketHandshakeException(String.format(
      "Invalid subprotocol. Actual: %s. Expected one of: %s",
      receivedProtocol, expectedSubprotocol));

代码示例来源:origin: io.vertx/vertx-core

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
 super.channelInactive(ctx);
 // if still handshaking this means we not got any response back from the server and so need to notify the client
 // about it as otherwise the client would never been notified.
 if (handshaking) {
  handleException(new WebSocketHandshakeException("Connection closed while handshake in process"));
 }
}

代码示例来源:origin: wildfly/wildfly

new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.SWITCHING_PROTOCOLS);
  res.headers().add(headers);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
  throw new WebSocketHandshakeException("not a WebSocket request: missing key");
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
  String selectedSubprotocol = selectSubprotocol(subprotocols);

代码示例来源:origin: wildfly/wildfly

if (!response.status().equals(HttpResponseStatus.SWITCHING_PROTOCOLS)) {
  throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
HttpHeaders headers = response.headers();
CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
if (!WEBSOCKET.contentEqualsIgnoreCase(upgrade)) {
  throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
      + upgrade);
if (!headers.containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {
  throw new WebSocketHandshakeException("Invalid handshake response connection: "
      + headers.get(HttpHeaderNames.CONNECTION));
ByteBuf challenge = response.content();
if (!challenge.equals(expectedChallengeResponseBytes)) {
  throw new WebSocketHandshakeException("Invalid challenge");

代码示例来源:origin: org.jboss.eap/wildfly-client-all

if (!req.headers().containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)
    || !HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) {
  throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
          req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
    isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
if (headers != null) {
  res.headers().add(headers);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com