use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method registerStompHandler.
private RuntimeBeanReference registerStompHandler(Element element, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, ParserContext context, Object source) {
RootBeanDefinition stompHandlerDef = new RootBeanDefinition(StompSubProtocolHandler.class);
registerBeanDef(stompHandlerDef, context, source);
Element errorHandlerElem = DomUtils.getChildElementByTagName(element, "stomp-error-handler");
if (errorHandlerElem != null) {
RuntimeBeanReference errorHandlerRef = new RuntimeBeanReference(errorHandlerElem.getAttribute("ref"));
stompHandlerDef.getPropertyValues().add("errorHandler", errorHandlerRef);
}
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addIndexedArgumentValue(0, inChannel);
cavs.addIndexedArgumentValue(1, outChannel);
RootBeanDefinition handlerDef = new RootBeanDefinition(SubProtocolWebSocketHandler.class, cavs, null);
handlerDef.getPropertyValues().addPropertyValue("protocolHandlers", stompHandlerDef);
registerBeanDefByName(WEB_SOCKET_HANDLER_BEAN_NAME, handlerDef, context, source);
RuntimeBeanReference result = new RuntimeBeanReference(WEB_SOCKET_HANDLER_BEAN_NAME);
Element transportElem = DomUtils.getChildElementByTagName(element, "transport");
if (transportElem != null) {
if (transportElem.hasAttribute("message-size")) {
stompHandlerDef.getPropertyValues().add("messageSizeLimit", transportElem.getAttribute("message-size"));
}
if (transportElem.hasAttribute("send-timeout")) {
handlerDef.getPropertyValues().add("sendTimeLimit", transportElem.getAttribute("send-timeout"));
}
if (transportElem.hasAttribute("send-buffer-size")) {
handlerDef.getPropertyValues().add("sendBufferSizeLimit", transportElem.getAttribute("send-buffer-size"));
}
Element factoriesElement = DomUtils.getChildElementByTagName(transportElem, "decorator-factories");
if (factoriesElement != null) {
ManagedList<Object> factories = extractBeanSubElements(factoriesElement, context);
RootBeanDefinition factoryBean = new RootBeanDefinition(DecoratingFactoryBean.class);
factoryBean.getConstructorArgumentValues().addIndexedArgumentValue(0, result);
factoryBean.getConstructorArgumentValues().addIndexedArgumentValue(1, factories);
result = new RuntimeBeanReference(registerBeanDef(factoryBean, context, source));
}
}
return result;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method registerMessageBroker.
private RootBeanDefinition registerMessageBroker(Element brokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference brokerChannel, Object userDestHandler, RuntimeBeanReference brokerTemplate, RuntimeBeanReference userRegistry, ParserContext context, Object source) {
Element simpleBrokerElem = DomUtils.getChildElementByTagName(brokerElement, "simple-broker");
Element brokerRelayElem = DomUtils.getChildElementByTagName(brokerElement, "stomp-broker-relay");
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addIndexedArgumentValue(0, inChannel);
cavs.addIndexedArgumentValue(1, outChannel);
cavs.addIndexedArgumentValue(2, brokerChannel);
RootBeanDefinition brokerDef;
if (simpleBrokerElem != null) {
String prefix = simpleBrokerElem.getAttribute("prefix");
cavs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
brokerDef = new RootBeanDefinition(SimpleBrokerMessageHandler.class, cavs, null);
if (brokerElement.hasAttribute("path-matcher")) {
String pathMatcherRef = brokerElement.getAttribute("path-matcher");
brokerDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
}
if (simpleBrokerElem.hasAttribute("scheduler")) {
String scheduler = simpleBrokerElem.getAttribute("scheduler");
brokerDef.getPropertyValues().add("taskScheduler", new RuntimeBeanReference(scheduler));
}
if (simpleBrokerElem.hasAttribute("heartbeat")) {
String heartbeatValue = simpleBrokerElem.getAttribute("heartbeat");
brokerDef.getPropertyValues().add("heartbeatValue", heartbeatValue);
}
} else if (brokerRelayElem != null) {
String prefix = brokerRelayElem.getAttribute("prefix");
cavs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
MutablePropertyValues values = new MutablePropertyValues();
if (brokerRelayElem.hasAttribute("relay-host")) {
values.add("relayHost", brokerRelayElem.getAttribute("relay-host"));
}
if (brokerRelayElem.hasAttribute("relay-port")) {
values.add("relayPort", brokerRelayElem.getAttribute("relay-port"));
}
if (brokerRelayElem.hasAttribute("client-login")) {
values.add("clientLogin", brokerRelayElem.getAttribute("client-login"));
}
if (brokerRelayElem.hasAttribute("client-passcode")) {
values.add("clientPasscode", brokerRelayElem.getAttribute("client-passcode"));
}
if (brokerRelayElem.hasAttribute("system-login")) {
values.add("systemLogin", brokerRelayElem.getAttribute("system-login"));
}
if (brokerRelayElem.hasAttribute("system-passcode")) {
values.add("systemPasscode", brokerRelayElem.getAttribute("system-passcode"));
}
if (brokerRelayElem.hasAttribute("heartbeat-send-interval")) {
values.add("systemHeartbeatSendInterval", brokerRelayElem.getAttribute("heartbeat-send-interval"));
}
if (brokerRelayElem.hasAttribute("heartbeat-receive-interval")) {
values.add("systemHeartbeatReceiveInterval", brokerRelayElem.getAttribute("heartbeat-receive-interval"));
}
if (brokerRelayElem.hasAttribute("virtual-host")) {
values.add("virtualHost", brokerRelayElem.getAttribute("virtual-host"));
}
ManagedMap<String, Object> map = new ManagedMap<>();
map.setSource(source);
if (brokerRelayElem.hasAttribute("user-destination-broadcast")) {
String destination = brokerRelayElem.getAttribute("user-destination-broadcast");
map.put(destination, userDestHandler);
}
if (brokerRelayElem.hasAttribute("user-registry-broadcast")) {
String destination = brokerRelayElem.getAttribute("user-registry-broadcast");
map.put(destination, registerUserRegistryMessageHandler(userRegistry, brokerTemplate, destination, context, source));
}
if (!map.isEmpty()) {
values.add("systemSubscriptions", map);
}
Class<?> handlerType = StompBrokerRelayMessageHandler.class;
brokerDef = new RootBeanDefinition(handlerType, cavs, values);
} else {
// Should not happen
throw new IllegalStateException("Neither <simple-broker> nor <stomp-broker-relay> elements found.");
}
registerBeanDef(brokerDef, context, source);
return brokerDef;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method parse.
@Override
public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
context.pushContainingComponent(compDefinition);
Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);
channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);
channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);
RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);
RuntimeBeanReference converter = registerMessageConverter(element, context, source);
RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
registerAnnotationMethodMessageHandler(element, inChannel, outChannel, converter, template, context, source);
RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel, userDestHandler, template, userRegistry, context, source);
// WebSocket and sub-protocol handling
ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
String pathAttribute = endpointElem.getAttribute("path");
Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
for (String path : paths) {
path = path.trim();
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
path = path.endsWith("/") ? path + "**" : path + "/**";
}
urlMap.put(path, requestHandler);
}
}
Map<String, Object> scopeMap = Collections.<String, Object>singletonMap("websocket", new SimpSessionScope());
RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);
registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);
context.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method registerUserRegistry.
private RuntimeBeanReference registerUserRegistry(Element element, ParserContext context, Object source) {
Element relayElement = DomUtils.getChildElementByTagName(element, "stomp-broker-relay");
boolean multiServer = (relayElement != null && relayElement.hasAttribute("user-registry-broadcast"));
if (multiServer) {
RootBeanDefinition localRegistryBeanDef = new RootBeanDefinition(DefaultSimpUserRegistry.class);
RootBeanDefinition beanDef = new RootBeanDefinition(MultiServerUserRegistry.class);
beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, localRegistryBeanDef);
String beanName = registerBeanDef(beanDef, context, source);
return new RuntimeBeanReference(beanName);
} else {
RootBeanDefinition beanDef = new RootBeanDefinition(DefaultSimpUserRegistry.class);
String beanName = registerBeanDef(beanDef, context, source);
return new RuntimeBeanReference(beanName);
}
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method registerMessageConverter.
private RuntimeBeanReference registerMessageConverter(Element element, ParserContext context, Object source) {
Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
ManagedList<? super Object> converters = new ManagedList<>();
if (convertersElement != null) {
converters.setSource(source);
for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
converters.add(object);
}
}
if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
converters.setSource(source);
converters.add(new RootBeanDefinition(StringMessageConverter.class));
converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
if (jackson2Present) {
RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
// Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
jacksonFactoryDef.setSource(source);
jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
converters.add(jacksonConverterDef);
}
}
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addIndexedArgumentValue(0, converters);
RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
String name = MESSAGE_CONVERTER_BEAN_NAME;
registerBeanDefByName(name, messageConverterDef, context, source);
return new RuntimeBeanReference(name);
}
Aggregations