Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.config;
import java.util.Arrays;
import java.util.List;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import org.springframework.web.socket.server.support.OriginHandshakeInterceptor;
import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService;
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
/**
* Provides utility methods for parsing common WebSocket XML namespace elements.
*
* @author Brian Clozel
* @author Rossen Stoyanchev
* @since 4.0
*/
abstract class WebSocketNamespaceUtils {
public static RuntimeBeanReference registerHandshakeHandler(
Element element, ParserContext context, @Nullable Object source) {
RuntimeBeanReference handlerRef;
Element handlerElem = DomUtils.getChildElementByTagName(element, "handshake-handler");
if (handlerElem != null) {
handlerRef = new RuntimeBeanReference(handlerElem.getAttribute("ref"));
}
else {
RootBeanDefinition defaultHandlerDef = new RootBeanDefinition(DefaultHandshakeHandler.class);
defaultHandlerDef.setSource(source);
defaultHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
String handlerName = context.getReaderContext().registerWithGeneratedName(defaultHandlerDef);
handlerRef = new RuntimeBeanReference(handlerName);
}
return handlerRef;
}
@Nullable
public static RuntimeBeanReference registerSockJsService(
Element element, String schedulerName, ParserContext context, @Nullable Object source) {
Element sockJsElement = DomUtils.getChildElementByTagName(element, "sockjs");
if (sockJsElement != null) {
Element handshakeHandler = DomUtils.getChildElementByTagName(element, "handshake-handler");
RootBeanDefinition sockJsServiceDef = new RootBeanDefinition(DefaultSockJsService.class);
sockJsServiceDef.setSource(source);
Object scheduler;
String customTaskSchedulerName = sockJsElement.getAttribute("scheduler");
if (!customTaskSchedulerName.isEmpty()) {
scheduler = new RuntimeBeanReference(customTaskSchedulerName);
}
else {
scheduler = registerScheduler(schedulerName, context, source);
}
sockJsServiceDef.getConstructorArgumentValues().addIndexedArgumentValue(0, scheduler);
Element transportHandlersElement = DomUtils.getChildElementByTagName(sockJsElement, "transport-handlers");
if (transportHandlersElement != null) {
String registerDefaults = transportHandlersElement.getAttribute("register-defaults");
if (registerDefaults.equals("false")) {
sockJsServiceDef.setBeanClass(TransportHandlingSockJsService.class);
}
ManagedList transportHandlers = parseBeanSubElements(transportHandlersElement, context);
sockJsServiceDef.getConstructorArgumentValues().addIndexedArgumentValue(1, transportHandlers);
}
else if (handshakeHandler != null) {
RuntimeBeanReference handshakeHandlerRef = new RuntimeBeanReference(handshakeHandler.getAttribute("ref"));
RootBeanDefinition transportHandler = new RootBeanDefinition(WebSocketTransportHandler.class);
transportHandler.setSource(source);
transportHandler.getConstructorArgumentValues().addIndexedArgumentValue(0, handshakeHandlerRef);
sockJsServiceDef.getConstructorArgumentValues().addIndexedArgumentValue(1, transportHandler);
}
Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
ManagedList