gpt4 book ai didi

org.springframework.web.reactive.socket.WebSocketSession.getHandshakeInfo()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 19:49:05 32 4
gpt4 key购买 nike

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

WebSocketSession.getHandshakeInfo介绍

[英]Return information from the handshake request.
[中]从握手请求返回信息。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<Void> handle(WebSocketSession session) {
    infoRef.set(session.getHandshakeInfo());
    return session.receive()
        .map(WebSocketMessage::getPayloadAsText)
        .subscribeWith(output)
        .then();
  }
})

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<Void> handle(WebSocketSession session) {
    String protocol = session.getHandshakeInfo().getSubProtocol();
    WebSocketMessage message = session.textMessage(protocol != null ? protocol : "none");
    return session.send(Mono.just(message));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<Void> handle(WebSocketSession session) {
    HttpHeaders headers = session.getHandshakeInfo().getHeaders();
    String payload = "my-header:" + headers.getFirst("my-header");
    WebSocketMessage message = session.textMessage(payload);
    return session.send(Mono.just(message));
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Override
  public Mono<Void> handle(WebSocketSession session) {
    String protocol = session.getHandshakeInfo().getSubProtocol();
    if (!StringUtils.hasText(protocol)) {
      return Mono.error(new IllegalStateException("Missing protocol"));
    }
    List<String> protocols = session.getHandshakeInfo().getHeaders().get(SEC_WEBSOCKET_PROTOCOL);
    assertThat(protocols).contains("echo-v1,echo-v2");
    WebSocketMessage message = session.textMessage(protocol);
    return doSend(session, Mono.just(message));
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Override
  public Mono<Void> handle(WebSocketSession session) {
    infoRef.set(session.getHandshakeInfo());
    return session.receive()
        .map(WebSocketMessage::getPayloadAsText)
        .subscribeWith(output)
        .then();
  }
})

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Override
  public Mono<Void> handle(WebSocketSession session) {
    HttpHeaders headers = session.getHandshakeInfo().getHeaders();
    if (!headers.containsKey("my-header")) {
      return Mono.error(new IllegalStateException("Missing my-header"));
    }
    String payload = "my-header:" + headers.getFirst("my-header");
    WebSocketMessage message = session.textMessage(payload);
    return doSend(session, Mono.just(message));
  }
}

代码示例来源:origin: hantsy/spring-reactive-sample

@Override
public Mono<Void> handle(WebSocketSession session) {
  String protocol = session.getHandshakeInfo().getSubProtocol();
  WebSocketMessage message = session.textMessage(this.posts.findAll().takeLast(0).toString());
  return doSend(session, Mono.just(message));
}

代码示例来源:origin: ch.rasc/wamp2spring-reactive

String acceptedProtocol = session.getHandshakeInfo().getSubProtocol();
if (acceptedProtocol != null) {
  if (acceptedProtocol.equals(WampWebSocketHandler.MSGPACK_PROTOCOL)) {

代码示例来源:origin: ch.rasc/wamp2spring-reactive

@Override
public Mono<Void> handle(WebSocketSession session) {
  session.receive().doFinally(sig -> {
    Long wampSessionId = this.webSocketId2WampSessionId.get(session.getId());
    if (wampSessionId != null) {
      this.applicationEventPublisher.publishEvent(
          new WampDisconnectEvent(wampSessionId, session.getId(),
              session.getHandshakeInfo().getPrincipal().block()));
      this.webSocketId2WampSessionId.remove(session.getId());
    }
    session.close(); // ?
  }).subscribe(inMsg -> {
    handleIncomingMessage(inMsg, session);
  });
  Publisher<Message<Object>> publisher = MessageChannelReactiveUtils
      .toPublisher(this.clientOutboundChannel);
  return session.send(Flux.from(publisher)
      .filter(msg -> resolveSessionId(msg).equals(session.getId()))
      .map(msg -> handleOutgoingMessage(msg, session)));
}

代码示例来源:origin: ch.rasc/wamp2spring-reactive

ByteBuffer byteBuffer = inMsg.getPayload().asByteBuffer();
  String acceptedProtocol = session.getHandshakeInfo().getSubProtocol();
  if (acceptedProtocol != null) {
    if (acceptedProtocol.equals(WampWebSocketHandler.MSGPACK_PROTOCOL)) {
    session.getId());
wampMessage.setHeader(WampMessageHeader.PRINCIPAL,
    session.getHandshakeInfo().getPrincipal().block());
wampMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID,
    this.webSocketId2WampSessionId.get(session.getId()));

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