org.springframework.web.socket.server.support.WebSocketHandlerMapping Java Examples

The following examples show how to use org.springframework.web.socket.server.support.WebSocketHandlerMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletWebSocketHandlerRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (ServletWebSocketHandlerRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		mappings.forEach((httpHandler, patterns) -> {
			for (String pattern : patterns) {
				urlMap.put(pattern, httpHandler);
			}
		});
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #2
Source File: WebMvcStompEndpointRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return a handler mapping with the mapped ViewControllers.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		mappings.forEach((httpHandler, patterns) -> {
			for (String pattern : patterns) {
				urlMap.put(pattern, httpHandler);
			}
		});
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #3
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(
		Element element, ParserContext context, @Nullable Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #4
Source File: ServletWebSocketHandlerRegistry.java    From java-technology-stack with MIT License 6 votes vote down vote up
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (ServletWebSocketHandlerRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		mappings.forEach((httpHandler, patterns) -> {
			for (String pattern : patterns) {
				urlMap.put(pattern, httpHandler);
			}
		});
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #5
Source File: WebMvcStompEndpointRegistry.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return a handler mapping with the mapped ViewControllers.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		mappings.forEach((httpHandler, patterns) -> {
			for (String pattern : patterns) {
				urlMap.put(pattern, httpHandler);
			}
		});
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #6
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(
		Element element, ParserContext context, @Nullable Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #7
Source File: ServletWebSocketHandlerRegistry.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return a {@link HandlerMapping} with mapped {@link HttpRequestHandler}s.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (ServletWebSocketHandlerRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #8
Source File: WebMvcStompEndpointRegistry.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return a handler mapping with the mapped ViewControllers; or {@code null}
 * in case of no registrations.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
Example #9
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(Element element,
		ParserContext context, Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #10
Source File: HandlersBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("order", order);
	String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef);

	RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(
			element, SOCK_JS_SCHEDULER_NAME, context, source);

	HandlerMappingStrategy strategy;
	if (sockJsService != null) {
		strategy = new SockJsHandlerMappingStrategy(sockJsService);
	}
	else {
		RuntimeBeanReference handler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source);
		Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
		ManagedList<Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptElem, context);
		String allowedOrigins = element.getAttribute("allowed-origins");
		List<String> origins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOrigins, ","));
		interceptors.add(new OriginHandshakeInterceptor(origins));
		strategy = new WebSocketHandlerMappingStrategy(handler, interceptors);
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) {
		strategy.addMapping(mappingElement, urlMap, context);
	}
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName));
	context.popAndRegisterContainingComponent();
	return null;
}
 
Example #11
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("order", order);
	String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef);

	RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(
			element, SOCK_JS_SCHEDULER_NAME, context, source);

	HandlerMappingStrategy strategy;
	if (sockJsService != null) {
		strategy = new SockJsHandlerMappingStrategy(sockJsService);
	}
	else {
		RuntimeBeanReference handler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source);
		Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
		ManagedList<Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptElem, context);
		String allowedOrigins = element.getAttribute("allowed-origins");
		List<String> origins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOrigins, ","));
		interceptors.add(new OriginHandshakeInterceptor(origins));
		strategy = new WebSocketHandlerMappingStrategy(handler, interceptors);
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) {
		strategy.addMapping(mappingElement, urlMap, context);
	}
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName));
	context.popAndRegisterContainingComponent();
	return null;
}
 
Example #12
Source File: HandlersBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("order", order);
	String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef);

	RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(
			element, SOCK_JS_SCHEDULER_NAME, context, source);

	HandlerMappingStrategy strategy;
	if (sockJsService != null) {
		strategy = new SockJsHandlerMappingStrategy(sockJsService);
	}
	else {
		RuntimeBeanReference handshakeHandler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source);
		Element interceptorsElement = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
		ManagedList<? super Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptorsElement, context);
		String allowedOriginsAttribute = element.getAttribute("allowed-origins");
		List<String> allowedOrigins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOriginsAttribute, ","));
		interceptors.add(new OriginHandshakeInterceptor(allowedOrigins));
		strategy = new WebSocketHandlerMappingStrategy(handshakeHandler, interceptors);
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
	urlMap.setSource(source);
	for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) {
		strategy.addMapping(mappingElement, urlMap, context);
	}
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName));
	context.popAndRegisterContainingComponent();
	return null;
}