Search in sources :

Example 51 with BeanDefinitionBuilder

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);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) DefaultRocketMQListenerContainer(org.apache.rocketmq.spring.starter.core.DefaultRocketMQListenerContainer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 52 with BeanDefinitionBuilder

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);
            }
        }
    });
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) SimpleBeanDefinitionParser(org.apache.cxf.configuration.spring.SimpleBeanDefinitionParser) Element(org.w3c.dom.Element) AutomaticWorkQueueImpl(org.apache.cxf.workqueue.AutomaticWorkQueueImpl) ParserContext(org.springframework.beans.factory.xml.ParserContext) FastInfosetFeature(org.apache.cxf.feature.FastInfosetFeature)

Example 53 with BeanDefinitionBuilder

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();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 54 with BeanDefinitionBuilder

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));
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer)

Example 55 with BeanDefinitionBuilder

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());
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) NamedNodeMap(org.w3c.dom.NamedNodeMap) IncludeProtocols(org.apache.cxf.configuration.security.IncludeProtocols) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) TrustManagersType(org.apache.cxf.configuration.security.TrustManagersType) FiltersType(org.apache.cxf.configuration.security.FiltersType) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) Attr(org.w3c.dom.Attr)

Aggregations

BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)524 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)116 Element (org.w3c.dom.Element)96 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)61 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)58 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)53 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 ManagedList (org.springframework.beans.factory.support.ManagedList)33 ManagedMap (org.springframework.beans.factory.support.ManagedMap)26 HashMap (java.util.HashMap)19 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)19 Test (org.junit.jupiter.api.Test)16 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)10 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)10