use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project rocketmq-externals by apache.
the class RocketMQAutoConfigurationTests method listenerContainer.
@Test
public void listenerContainer() {
load(false, "spring.rocketmq.nameServer=127.0.0.1:9876");
BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(MyListener.class);
this.context.registerBeanDefinition("myListener", beanBuilder.getBeanDefinition());
this.context.refresh();
assertThat(this.context.getBeansOfType(DefaultRocketMQListenerContainer.class)).isNotEmpty();
assertThat(this.context.containsBean(DefaultRocketMQListenerContainer.class.getName() + "_1")).isTrue();
DefaultRocketMQListenerContainer listenerContainer = this.context.getBean(DefaultRocketMQListenerContainer.class.getName() + "_1", DefaultRocketMQListenerContainer.class);
ObjectMapper objectMapper = this.context.getBean("rocketMQMessageObjectMapper", ObjectMapper.class);
assertThat(listenerContainer.getObjectMapper()).isEqualTo(objectMapper);
assertThat(listenerContainer.getConsumeMode()).isEqualTo(ConsumeMode.CONCURRENTLY);
assertThat(listenerContainer.getSelectorType()).isEqualTo(SelectorType.TAG);
assertThat(listenerContainer.getSelectorExpress()).isEqualTo("*");
assertThat(listenerContainer.getConsumerGroup()).isEqualTo(TEST_CONSUMER_GROUP);
assertThat(listenerContainer.getTopic()).isEqualTo(TEST_TOPIC);
assertThat(listenerContainer.getNameServer()).isEqualTo("127.0.0.1:9876");
assertThat(listenerContainer.getMessageModel()).isEqualTo(MessageModel.CLUSTERING);
assertThat(listenerContainer.getConsumeThreadMax()).isEqualTo(1);
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project cxf by apache.
the class NamespaceHandler method init.
@SuppressWarnings("deprecation")
public void init() {
registerBeanDefinitionParser("bus", new BusDefinitionParser());
registerBeanDefinitionParser("logging", new SimpleBeanDefinitionParser(org.apache.cxf.feature.LoggingFeature.class));
registerBeanDefinitionParser("fastinfoset", new SimpleBeanDefinitionParser(FastInfosetFeature.class));
registerBeanDefinitionParser("workqueue", new SimpleBeanDefinitionParser(AutomaticWorkQueueImpl.class) {
protected void processNameAttribute(Element element, ParserContext ctx, BeanDefinitionBuilder bean, String val) {
bean.addPropertyValue("name", val);
element.removeAttribute("name");
if (!element.hasAttribute("id")) {
val = "cxf.workqueue." + val;
element.setAttribute("id", val);
}
}
});
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project cxf by apache.
the class AbstractBeanDefinitionParser method mapElementToJaxbBean.
public AbstractBeanDefinition mapElementToJaxbBean(Element data, Class<?> cls, Class<?> factory, Class<?> jaxbClass, String method, Object... args) {
StringWriter writer = new StringWriter();
XMLStreamWriter xmlWriter = StaxUtils.createXMLStreamWriter(writer);
try {
StaxUtils.copy(data, xmlWriter);
xmlWriter.flush();
} catch (XMLStreamException e) {
throw new RuntimeException(e);
} finally {
StaxUtils.close(xmlWriter);
}
BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(cls);
if (factory != null) {
jaxbbean.getRawBeanDefinition().setFactoryBeanName(factory.getName());
}
jaxbbean.getRawBeanDefinition().setFactoryMethodName(method);
jaxbbean.addConstructorArgValue(writer.toString());
jaxbbean.addConstructorArgValue(getContext(jaxbClass));
if (args != null) {
for (Object o : args) {
jaxbbean.addConstructorArgValue(o);
}
}
return jaxbbean.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project paascloud-master by paascloud.
the class MqProducerBeanFactory method buildProducerBean.
/**
* Build producer bean.
*
* @param producerDto the producer dto
*/
public static void buildProducerBean(ReliableMessageRegisterDto producerDto) {
String pid = producerDto.getProducerGroup();
DefaultMQProducer mQProducer = DEFAULT_MQ_PRODUCER_MAP.get(pid);
if (mQProducer == null) {
String simpleName = producerDto.getProducerGroup();
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMQProducer.class);
beanDefinitionBuilder.setScope(BeanDefinition.SCOPE_SINGLETON);
beanDefinitionBuilder.addPropertyValue("producerGroup", producerDto.getProducerGroup());
beanDefinitionBuilder.addPropertyValue("namesrvAddr", producerDto.getNamesrvAddr());
beanDefinitionBuilder.setInitMethodName("start");
beanDefinitionBuilder.setDestroyMethodName("shutdown");
SpringContextHolder.getDefaultListableBeanFactory().registerBeanDefinition(simpleName, beanDefinitionBuilder.getBeanDefinition());
DEFAULT_MQ_PRODUCER_MAP.put(simpleName, SpringContextHolder.getBean(simpleName));
}
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project cxf by apache.
the class JettyHTTPServerEngineBeanDefinitionParser method mapTLSServerParameters.
private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) {
BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class);
// read the attributes
NamedNodeMap as = e.getAttributes();
for (int i = 0; i < as.getLength(); i++) {
Attr a = (Attr) as.item(i);
if (a.getNamespaceURI() == null) {
String aname = a.getLocalName();
if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) {
paramsbean.addPropertyValue(aname, a.getValue());
}
}
}
// read the child elements
Node n = e.getFirstChild();
while (n != null) {
if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) {
n = n.getNextSibling();
continue;
}
String ename = n.getLocalName();
// Schema should require that no more than one each of these exist.
String ref = ((Element) n).getAttribute("ref");
if ("keyManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("keyManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, KeyManagersType.class);
}
} else if ("trustManagers".equals(ename)) {
if (ref != null && ref.length() > 0) {
paramsbean.addPropertyReference("trustManagersRef", ref);
} else {
mapElementToJaxbProperty((Element) n, paramsbean, ename, TrustManagersType.class);
}
} else if ("cipherSuites".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CipherSuites.class);
} else if ("cipherSuitesFilter".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, FiltersType.class);
} else if ("excludeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ExcludeProtocols.class);
} else if ("includeProtocols".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, IncludeProtocols.class);
} else if ("secureRandomParameters".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, SecureRandomParameters.class);
} else if ("clientAuthentication".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, ClientAuthentication.class);
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element) n, paramsbean, ename, CertificateConstraintsType.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
n = n.getNextSibling();
}
BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class);
jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition());
bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition());
}
Aggregations