org.springframework.web.socket.WebSocketHttpHeaders.<init>()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(184)

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

WebSocketHttpHeaders.<init>介绍

[英]Create a new instance.
[中]创建一个新实例。

代码示例

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

/**
 * Returns {@code WebSocketHttpHeaders} object that can only be read, not written to.
 */
public static WebSocketHttpHeaders readOnlyWebSocketHttpHeaders(WebSocketHttpHeaders headers) {
  return new WebSocketHttpHeaders(headers, true);
}

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

@Before
public void setUp() {
  headers = new WebSocketHttpHeaders();
}

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

@Before
public void setup() {
  this.headers = new WebSocketHttpHeaders();
  this.wsHandler = new AbstractWebSocketHandler() {
  };
  this.wsContainer = mock(WebSocketContainer.class);
  this.wsClient = new StandardWebSocketClient(this.wsContainer);
}

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

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
  final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<>();
  WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
  handler = new ClientSockJsWebSocketHandler(session);
  request.addTimeoutTask(session.getTimeoutTask());
  URI url = request.getTransportUrl();
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
  if (logger.isDebugEnabled()) {
    logger.debug("Starting WebSocket session on " + url);
  }
  this.webSocketClient.doHandshake(handler, headers, url).addCallback(
      new ListenableFutureCallback<WebSocketSession>() {
        @Override
        public void onSuccess(@Nullable WebSocketSession webSocketSession) {
          // WebSocket session ready, SockJS Session not yet
        }
        @Override
        public void onFailure(Throwable ex) {
          future.setException(ex);
        }
      });
  return future;
}

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

@Test
public void echoXhrWithHeaders() throws Exception {
  AbstractXhrTransport xhrTransport = createXhrTransport();
  xhrTransport.setXhrStreamingDisabled(true);
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.add("auth", "123");
  testEcho(10, xhrTransport, headers);
  for (Map.Entry<String, HttpHeaders> entry : this.testFilter.requests.entrySet()) {
    HttpHeaders httpHeaders = entry.getValue();
    assertEquals("No auth header for: " + entry.getKey(), "123", httpHeaders.getFirst("auth"));
  }
}

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

@Test
public void doHandshake() throws Exception {
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.setSecWebSocketProtocol(Arrays.asList("echo"));
  this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
  assertEquals(this.wsUrl, this.wsSession.getUri().toString());
  assertEquals("echo", this.wsSession.getAcceptedProtocol());
}

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

WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHeaders());
if (logger.isTraceEnabled()) {
  logger.trace("Processing request " + request.getURI() + " with headers=" + headers);

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

@Test
public void doHandshakeWithTaskExecutor() throws Exception {
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.setSecWebSocketProtocol(Arrays.asList("echo"));
  this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
  this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
  assertEquals(this.wsUrl, this.wsSession.getUri().toString());
  assertEquals("echo", this.wsSession.getAcceptedProtocol());
}

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

@Test
public void openConnection() throws Exception {
  List<String> subprotocols = Arrays.asList("abc");
  TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
  WebSocketHandler handler = new TextWebSocketHandler();
  WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123");
  manager.setSubProtocols(subprotocols);
  manager.openConnection();
  WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
  expectedHeaders.setSecWebSocketProtocol(subprotocols);
  assertEquals(expectedHeaders, client.headers);
  assertEquals(new URI("/path/123"), client.uri);
  WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
  assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());
  assertSame(handler, loggingHandler.getDelegate());
}

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

@Test
public void subProtocolNegotiation() throws Exception {
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.setSecWebSocketProtocol("foo");
  URI url = new URI(getWsBaseUrl() + "/ws");
  WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
  assertEquals("foo", session.getAcceptedProtocol());
  session.close();
}

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

@Test
public void supportedExtensions() {
  WebSocketExtension extension1 = new WebSocketExtension("ext1");
  WebSocketExtension extension2 = new WebSocketExtension("ext2");
  given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
  given(this.upgradeStrategy.getSupportedExtensions(this.request)).willReturn(Collections.singletonList(extension1));
  this.servletRequest.setMethod("GET");
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
  headers.setUpgrade("WebSocket");
  headers.setConnection("Upgrade");
  headers.setSecWebSocketVersion("13");
  headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
  headers.setSecWebSocketExtensions(Arrays.asList(extension1, extension2));
  WebSocketHandler handler = new TextWebSocketHandler();
  Map<String, Object> attributes = Collections.<String, Object>emptyMap();
  this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
  verify(this.upgradeStrategy).upgrade(this.request, this.response, null,
      Collections.singletonList(extension1), null, handler, attributes);
}

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

@Test
public void subProtocolCapableHandler() {
  given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
  this.servletRequest.setMethod("GET");
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
  headers.setUpgrade("WebSocket");
  headers.setConnection("Upgrade");
  headers.setSecWebSocketVersion("13");
  headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
  headers.setSecWebSocketProtocol("v11.stomp");
  WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
  Map<String, Object> attributes = Collections.<String, Object>emptyMap();
  this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
  verify(this.upgradeStrategy).upgrade(this.request, this.response, "v11.stomp",
      Collections.emptyList(), null, handler, attributes);
}

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

@Test
public void subProtocolCapableHandlerNoMatch() {
  given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
  this.servletRequest.setMethod("GET");
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
  headers.setUpgrade("WebSocket");
  headers.setConnection("Upgrade");
  headers.setSecWebSocketVersion("13");
  headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
  headers.setSecWebSocketProtocol("v10.stomp");
  WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
  Map<String, Object> attributes = Collections.<String, Object>emptyMap();
  this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
  verify(this.upgradeStrategy).upgrade(this.request, this.response, null,
      Collections.emptyList(), null, handler, attributes);
}

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

@Test
public void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception {
  ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
  this.xhrTransport.setStreamingDisabled(true);
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.set("foo", "bar");
  headers.set("auth", "123");
  this.sockJsClient.setHttpHeaderNames("auth");
  this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
  assertEquals(1, headersCaptor.getValue().size());
  assertEquals("123", headersCaptor.getValue().getFirst("auth"));
  assertEquals(1, this.xhrTransport.getRequest().getHttpRequestHeaders().size());
  assertEquals("123", this.xhrTransport.getRequest().getHttpRequestHeaders().getFirst("auth"));
}

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

@Test
public void supportedSubProtocols() {
  this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");
  given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
  this.servletRequest.setMethod("GET");
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
  headers.setUpgrade("WebSocket");
  headers.setConnection("Upgrade");
  headers.setSecWebSocketVersion("13");
  headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
  headers.setSecWebSocketProtocol("STOMP");
  WebSocketHandler handler = new TextWebSocketHandler();
  Map<String, Object> attributes = Collections.emptyMap();
  this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
  verify(this.upgradeStrategy).upgrade(this.request, this.response, "STOMP",
      Collections.emptyList(), null, handler, attributes);
}

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

@Test
public void connectWithHandshakeHeaders() throws Exception {
  ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
  this.xhrTransport.setStreamingDisabled(true);
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.set("foo", "bar");
  headers.set("auth", "123");
  this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
  HttpHeaders httpHeaders = headersCaptor.getValue();
  assertEquals(2, httpHeaders.size());
  assertEquals("bar", httpHeaders.getFirst("foo"));
  assertEquals("123", httpHeaders.getFirst("auth"));
  httpHeaders = this.xhrTransport.getRequest().getHttpRequestHeaders();
  assertEquals(2, httpHeaders.size());
  assertEquals("bar", httpHeaders.getFirst("foo"));
  assertEquals("123", httpHeaders.getFirst("auth"));
}

代码示例来源:origin: org.springframework/spring-websocket

/**
 * Returns {@code WebSocketHttpHeaders} object that can only be read, not written to.
 */
public static WebSocketHttpHeaders readOnlyWebSocketHttpHeaders(WebSocketHttpHeaders headers) {
  return new WebSocketHttpHeaders(headers, true);
}

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

@Bean
public StompSessionManager stompSessionManager(WebSocketStompClient stompClient) {
  WebSocketStompSessionManager webSocketStompSessionManager =
      new WebSocketStompSessionManager(stompClient, server().getWsBaseUrl() + "/ws");
  webSocketStompSessionManager.setAutoReceipt(true);
  webSocketStompSessionManager.setRecoveryInterval(1000);
  WebSocketHttpHeaders handshakeHeaders = new WebSocketHttpHeaders();
  handshakeHeaders.setOrigin("http://foo.com");
  webSocketStompSessionManager.setHandshakeHeaders(handshakeHeaders);
  StompHeaders stompHeaders = new StompHeaders();
  stompHeaders.setHeartbeat(new long[] { 10000, 10000 });
  webSocketStompSessionManager.setConnectHeaders(stompHeaders);
  return webSocketStompSessionManager;
}

代码示例来源:origin: stackoverflow.com

WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
String auth = "user" + ":" + "password";
headers.add("Authorization", "Basic " + new String(Base64.getEncoder().encode(auth.getBytes())));
stompClient.connect(url, headers, new MyStompSessionHandler());

代码示例来源:origin: stackoverflow.com

WebSocketHttpHeaders handshakeHeaders = new WebSocketHttpHeaders();
StompHeaders connectHeaders = new StompHeaders();
connectHeaders.add("tokenGroup", "192:168:99:3::DEMO");
stompClient.connect(stompUrlEndpoint.toString(), handshakeHeaders, connectHeaders, stompSessionHandlerImp, new Object[0]);

相关文章