當前位置: 首頁>>代碼示例>>Java>>正文


Java TextWebSocketHandler類代碼示例

本文整理匯總了Java中org.springframework.web.socket.handler.TextWebSocketHandler的典型用法代碼示例。如果您正苦於以下問題:Java TextWebSocketHandler類的具體用法?Java TextWebSocketHandler怎麽用?Java TextWebSocketHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextWebSocketHandler類屬於org.springframework.web.socket.handler包,在下文中一共展示了TextWebSocketHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openConnection

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:WebSocketConnectionManagerTests.java

示例2: supportedSubProtocols

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void supportedSubProtocols() throws Exception {

	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.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response,
			"STOMP", Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:DefaultHandshakeHandlerTests.java

示例3: supportedExtensions

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void supportedExtensions() throws Exception {

	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(Arrays.asList(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, Arrays.asList(extension1),
			null, handler, attributes);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:DefaultHandshakeHandlerTests.java

示例4: minimal

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void minimal() {
	WebSocketHandler handler = new TextWebSocketHandler();
	this.registration.addHandler(handler, "/foo", "/bar");

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(2, mappings.size());

	Mapping m1 = mappings.get(0);
	assertEquals(handler, m1.webSocketHandler);
	assertEquals("/foo", m1.path);
	assertEquals(1, m1.interceptors.length);
	assertEquals(OriginHandshakeInterceptor.class, m1.interceptors[0].getClass());

	Mapping m2 = mappings.get(1);
	assertEquals(handler, m2.webSocketHandler);
	assertEquals("/bar", m2.path);
	assertEquals(1, m2.interceptors.length);
	assertEquals(OriginHandshakeInterceptor.class, m2.interceptors[0].getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:WebSocketHandlerRegistrationTests.java

示例5: interceptors

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void interceptors() {
	WebSocketHandler handler = new TextWebSocketHandler();
	HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();

	this.registration.addHandler(handler, "/foo").addInterceptors(interceptor);

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(1, mappings.size());

	Mapping mapping = mappings.get(0);
	assertEquals(handler, mapping.webSocketHandler);
	assertEquals("/foo", mapping.path);
	assertEquals(2, mapping.interceptors.length);
	assertEquals(interceptor, mapping.interceptors[0]);
	assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:WebSocketHandlerRegistrationTests.java

示例6: emptyAllowedOrigin

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void emptyAllowedOrigin() {
	WebSocketHandler handler = new TextWebSocketHandler();
	HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();

	this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins();

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(1, mappings.size());

	Mapping mapping = mappings.get(0);
	assertEquals(handler, mapping.webSocketHandler);
	assertEquals("/foo", mapping.path);
	assertEquals(2, mapping.interceptors.length);
	assertEquals(interceptor, mapping.interceptors[0]);
	assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:WebSocketHandlerRegistrationTests.java

示例7: interceptorsWithAllowedOrigins

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void interceptorsWithAllowedOrigins() {
	WebSocketHandler handler = new TextWebSocketHandler();
	HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();

	this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins("http://mydomain1.com");

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(1, mappings.size());

	Mapping mapping = mappings.get(0);
	assertEquals(handler, mapping.webSocketHandler);
	assertEquals("/foo", mapping.path);
	assertEquals(2, mapping.interceptors.length);
	assertEquals(interceptor, mapping.interceptors[0]);
	assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:WebSocketHandlerRegistrationTests.java

示例8: interceptorsPassedToSockJsRegistration

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void interceptorsPassedToSockJsRegistration() {
	WebSocketHandler handler = new TextWebSocketHandler();
	HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();

	this.registration.addHandler(handler, "/foo").addInterceptors(interceptor)
			.setAllowedOrigins("http://mydomain1.com").withSockJS();

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(1, mappings.size());

	Mapping mapping = mappings.get(0);
	assertEquals(handler, mapping.webSocketHandler);
	assertEquals("/foo/**", mapping.path);
	assertNotNull(mapping.sockJsService);
	assertTrue(mapping.sockJsService.getAllowedOrigins().contains("http://mydomain1.com"));
	List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
	assertEquals(interceptor, interceptors.get(0));
	assertEquals(OriginHandshakeInterceptor.class, interceptors.get(1).getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:WebSocketHandlerRegistrationTests.java

示例9: handshakeHandlerPassedToSockJsRegistration

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void handshakeHandlerPassedToSockJsRegistration() {
	WebSocketHandler handler = new TextWebSocketHandler();
	HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();

	this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler).withSockJS();

	List<Mapping> mappings = this.registration.getMappings();
	assertEquals(1, mappings.size());

	Mapping mapping = mappings.get(0);
	assertEquals(handler, mapping.webSocketHandler);
	assertEquals("/foo/**", mapping.path);
	assertNotNull(mapping.sockJsService);

	WebSocketTransportHandler transportHandler =
			(WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET);
	assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:WebSocketHandlerRegistrationTests.java

示例10: subProtocolNegotiation

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@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();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:WebSocketIntegrationTests.java

示例11: clientLifecycle

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void clientLifecycle() throws Exception {
	TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
	WebSocketHandler handler = new TextWebSocketHandler();
	WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a");

	manager.startInternal();
	assertTrue(client.isRunning());

	manager.stopInternal();
	assertFalse(client.isRunning());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:WebSocketConnectionManagerTests.java

示例12: doHandshake

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:JettyWebSocketClientTests.java

示例13: doHandshakeWithTaskExecutor

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:JettyWebSocketClientTests.java

示例14: getSubProtocolsNone

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Test
public void getSubProtocolsNone() throws Exception {
	WebSocketHandler handler = new TextWebSocketHandler();
	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertNull(sockJsHandler.getSubProtocols());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:SockJsWebSocketHandlerTests.java

示例15: setup

import org.springframework.web.socket.handler.TextWebSocketHandler; //導入依賴的package包/類
@Before
public void setup() throws Exception {

	int port = SocketUtils.findAvailableTcpPort();

	this.server = new TestJettyWebSocketServer(port, new TextWebSocketHandler());
	this.server.start();

	this.client = new JettyWebSocketClient();
	this.client.start();

	this.wsUrl = "ws://localhost:" + port + "/test";
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:JettyWebSocketClientTests.java


注:本文中的org.springframework.web.socket.handler.TextWebSocketHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。