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


Java HandshakeInterceptor类代码示例

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


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

示例1: applyBeforeHandshake

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
public boolean applyBeforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
		Map<String, Object> attributes) throws Exception {

	for (int i = 0; i < this.interceptors.size(); i++) {
		HandshakeInterceptor interceptor = this.interceptors.get(i);
		if (!interceptor.beforeHandshake(request, response, this.wsHandler, attributes)) {
			if (logger.isDebugEnabled()) {
				logger.debug(interceptor + " returns false from beforeHandshake - precluding handshake");
			}
			applyAfterHandshake(request, response, null);
			return false;
		}
		this.interceptorIndex = i;
	}
	return true;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:HandshakeInterceptorChain.java

示例2: withSockJS

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
public SockJsServiceRegistration withSockJS() {
	this.registration = new StompSockJsServiceRegistration(this.sockJsTaskScheduler);
	HandshakeInterceptor[] interceptors = getInterceptors();
	if (interceptors.length > 0) {
		this.registration.setInterceptors(interceptors);
	}
	if (this.handshakeHandler != null) {
		WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
		this.registration.setTransportHandlerOverrides(transportHandler);
	}
	if (!this.allowedOrigins.isEmpty()) {
		this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
	}
	return this.registration;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:WebMvcStompWebSocketEndpointRegistration.java

示例3: withSockJS

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
public SockJsServiceRegistration withSockJS() {
	this.sockJsServiceRegistration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
	HandshakeInterceptor[] interceptors = getInterceptors();
	if (interceptors.length > 0) {
		this.sockJsServiceRegistration.setInterceptors(interceptors);
	}
	if (this.handshakeHandler != null) {
		WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
		this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler);
	}
	if (!this.allowedOrigins.isEmpty()) {
		this.sockJsServiceRegistration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
	}
	return this.sockJsServiceRegistration;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AbstractWebSocketHandlerRegistration.java

示例4: interceptorsPassedToSockJsRegistration

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的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

示例5: withSockJS

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
public SockJsServiceRegistration withSockJS() {
	this.registration = new WampSockJsServiceRegistration(this.sockJsTaskScheduler);
	HandshakeInterceptor[] handshakeInterceptors = getInterceptors();
	if (handshakeInterceptors.length > 0) {
		this.registration.setInterceptors(handshakeInterceptors);
	}
	if (this.handshakeHandler != null) {
		WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(
				this.handshakeHandler);
		this.registration.setTransportHandlerOverrides(transportHandler);
	}
	if (!this.allowedOrigins.isEmpty()) {
		this.registration.setAllowedOrigins(
				this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
	}
	return this.registration;
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:19,代码来源:WebMvcWampWebSocketEndpointRegistration.java

示例6: wampWebSocketHandlerMapping

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Bean
public HandlerMapping wampWebSocketHandlerMapping() {
	WebSocketHandler handler = subProtocolWebSocketHandler();
	handler = decorateWebSocketHandler(handler);

	WebMvcWampEndpointRegistry registry = new WebMvcWampEndpointRegistry(handler,
			getTransportRegistration(), messageBrokerSockJsTaskScheduler(),
			new MappingJsonFactory(lookupObjectMapper()));

	List<HandshakeInterceptor> handshakeInterceptors = new ArrayList<>();
	addHandshakeInterceptors(handshakeInterceptors);
	registry.addHandshakeInterceptors(handshakeInterceptors);

	registerWampEndpoints(registry);

	return registry.getHandlerMapping();
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:18,代码来源:DefaultWampConfiguration.java

示例7: applyAfterHandshake

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
public void applyAfterHandshake(ServerHttpRequest request, ServerHttpResponse response, Exception failure) {
	for (int i = this.interceptorIndex; i >= 0; i--) {
		HandshakeInterceptor interceptor = this.interceptors.get(i);
		try {
			interceptor.afterHandshake(request, response, this.wsHandler, failure);
		}
		catch (Throwable ex) {
			if (logger.isWarnEnabled()) {
				logger.warn(interceptor + " threw exception in afterHandshake: " + ex);
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:HandshakeInterceptorChain.java

示例8: setHandshakeInterceptors

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
/**
 * Configure one or more WebSocket handshake request interceptors.
 */
public void setHandshakeInterceptors(List<HandshakeInterceptor> interceptors) {
	this.interceptors.clear();
	if (interceptors != null) {
		this.interceptors.addAll(interceptors);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:WebSocketHttpRequestHandler.java

示例9: addWebSocketHandlerMapping

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings,
		WebSocketHandler wsHandler, HandshakeHandler handshakeHandler,
		HandshakeInterceptor[] interceptors, String path) {

	WebSocketHttpRequestHandler httpHandler = new WebSocketHttpRequestHandler(wsHandler, handshakeHandler);
	if (!ObjectUtils.isEmpty(interceptors)) {
		httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors));
	}
	mappings.add(httpHandler, path);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:ServletWebSocketHandlerRegistration.java

示例10: addInterceptors

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
public StompWebSocketEndpointRegistration addInterceptors(HandshakeInterceptor... interceptors) {
	if (!ObjectUtils.isEmpty(interceptors)) {
		this.interceptors.addAll(Arrays.asList(interceptors));
	}
	return this;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:WebMvcStompWebSocketEndpointRegistration.java

示例11: setInterceptors

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
public SockJsServiceRegistration setInterceptors(HandshakeInterceptor... interceptors) {
	this.interceptors.clear();
	if (!ObjectUtils.isEmpty(interceptors)) {
		this.interceptors.addAll(Arrays.asList(interceptors));
	}
	return this;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SockJsServiceRegistration.java

示例12: addInterceptors

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Override
public WebSocketHandlerRegistration addInterceptors(HandshakeInterceptor... interceptors) {
	if (!ObjectUtils.isEmpty(interceptors)) {
		this.interceptors.addAll(Arrays.asList(interceptors));
	}
	return this;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:AbstractWebSocketHandlerRegistration.java

示例13: setup

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Before
public void setup() {
	i1 = mock(HandshakeInterceptor.class);
	i2 = mock(HandshakeInterceptor.class);
	i3 = mock(HandshakeInterceptor.class);
	interceptors = Arrays.asList(i1, i2, i3);
	wsHandler = mock(WebSocketHandler.class);
	attributes = new HashMap<String, Object>();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:HandshakeInterceptorChainTests.java

示例14: Mapping

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
public Mapping(WebSocketHandler h, String path, HandshakeHandler hh, HandshakeInterceptor[] interceptors) {
	this.webSocketHandler = h;
	this.path = path;
	this.handshakeHandler = hh;
	this.interceptors = interceptors;
	this.sockJsService = null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:WebSocketHandlerRegistrationTests.java

示例15: webSocketHandlersAttributes

import org.springframework.web.socket.server.HandshakeInterceptor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void webSocketHandlersAttributes() {
	loadBeanDefinitions("websocket-config-handlers-attributes.xml");

	HandlerMapping handlerMapping = this.appContext.getBean(HandlerMapping.class);
	assertNotNull(handlerMapping);
	assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);

	SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
	assertEquals(2, urlHandlerMapping.getOrder());

	WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/foo");
	assertNotNull(handler);
	unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
	HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
	assertNotNull(handshakeHandler);
	assertTrue(handshakeHandler instanceof TestHandshakeHandler);
	List<HandshakeInterceptor> interceptors = handler.getHandshakeInterceptors();
	assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
			instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));

	handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
	assertNotNull(handler);
	unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
	handshakeHandler = handler.getHandshakeHandler();
	assertNotNull(handshakeHandler);
	assertTrue(handshakeHandler instanceof TestHandshakeHandler);
	interceptors = handler.getHandshakeInterceptors();
	assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
			instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:HandlersBeanDefinitionParserTests.java


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