Search in sources :

Example 26 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig in project dubbo by alibaba.

the class DubboNamespaceHandlerTest method testCustomParameter.

@Test
public void testCustomParameter() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/customize-parameter.xml");
    ctx.start();
    ProtocolConfig protocolConfig = ctx.getBean(ProtocolConfig.class);
    assertThat(protocolConfig.getParameters().size(), is(1));
    assertThat(protocolConfig.getParameters().get("protocol-paramA"), is("protocol-paramA"));
    ServiceBean serviceBean = ctx.getBean(ServiceBean.class);
    assertThat(serviceBean.getParameters().size(), is(1));
    assertThat(serviceBean.getParameters().get("service-paramA"), is("service-paramA"));
    ctx.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ServiceBean(org.apache.dubbo.config.spring.ServiceBean) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test) ConfigTest(org.apache.dubbo.config.spring.ConfigTest)

Example 27 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig in project dubbo by alibaba.

the class DubboNamespaceHandlerTest method testProviderXml.

private void testProviderXml(ApplicationContext context) {
    ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
    assertThat(protocolConfig, not(nullValue()));
    assertThat(protocolConfig.getName(), is("dubbo"));
    assertThat(protocolConfig.getPort(), is(20813));
    ApplicationConfig applicationConfig = context.getBean(ApplicationConfig.class);
    assertThat(applicationConfig, not(nullValue()));
    assertThat(applicationConfig.getName(), is("demo-provider"));
    DemoService service = context.getBean(DemoService.class);
    assertThat(service, not(nullValue()));
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 28 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig in project dubbo by alibaba.

the class ConfigValidationUtils method validateServiceConfig.

public static void validateServiceConfig(ServiceConfig config) {
    checkKey(VERSION_KEY, config.getVersion());
    checkKey(GROUP_KEY, config.getGroup());
    checkName(TOKEN_KEY, config.getToken());
    checkPathName(PATH_KEY, config.getPath());
    checkMultiExtension(ExporterListener.class, LISTENER_KEY, config.getListener());
    validateAbstractInterfaceConfig(config);
    List<RegistryConfig> registries = config.getRegistries();
    if (registries != null) {
        for (RegistryConfig registry : registries) {
            validateRegistryConfig(registry);
        }
    }
    List<ProtocolConfig> protocols = config.getProtocols();
    if (protocols != null) {
        for (ProtocolConfig protocol : protocols) {
            validateProtocolConfig(protocol);
        }
    }
    ProviderConfig providerConfig = config.getProvider();
    if (providerConfig != null) {
        validateProviderConfig(providerConfig);
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 29 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig in project dubbo by alibaba.

the class ServiceInstancePortCustomizer method customize.

@Override
public void customize(ServiceInstance serviceInstance) {
    if (serviceInstance.getPort() != null) {
        return;
    }
    Collection<ProtocolConfig> protocols = ApplicationModel.getConfigManager().getProtocols();
    if (CollectionUtils.isEmpty(protocols)) {
        throw new IllegalStateException("We should have at least one protocol configured at this point.");
    }
    Stream<ProtocolConfig> protocolStream = protocols.stream();
    ProtocolConfig protocolConfig = protocolStream.filter(protocol -> "rest".equals(protocol.getName())).findFirst().orElseGet(() -> protocolStream.findFirst().get());
    if (serviceInstance instanceof DefaultServiceInstance) {
        DefaultServiceInstance instance = (DefaultServiceInstance) serviceInstance;
        if (protocolConfig.getPort() != null) {
            instance.setPort(protocolConfig.getPort());
        }
    }
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 30 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig in project dubbo by alibaba.

the class ProtocolBuilder method build.

public ProtocolConfig build() {
    ProtocolConfig protocolConfig = new ProtocolConfig();
    super.build(protocolConfig);
    protocolConfig.setAccepts(accepts);
    protocolConfig.setAccesslog(accesslog);
    protocolConfig.setBuffer(buffer);
    protocolConfig.setCharset(charset);
    protocolConfig.setClient(client);
    protocolConfig.setCodec(codec);
    protocolConfig.setContextpath(contextpath);
    protocolConfig.setCorethreads(corethreads);
    protocolConfig.setDefault(isDefault);
    protocolConfig.setDispatcher(dispatcher);
    protocolConfig.setExchanger(exchanger);
    protocolConfig.setExtension(extension);
    protocolConfig.setHeartbeat(heartbeat);
    protocolConfig.setHost(host);
    protocolConfig.setIothreads(iothreads);
    protocolConfig.setKeepAlive(keepAlive);
    protocolConfig.setName(name);
    protocolConfig.setNetworker(networker);
    protocolConfig.setOptimizer(optimizer);
    protocolConfig.setParameters(parameters);
    protocolConfig.setPayload(payload);
    protocolConfig.setPort(port);
    protocolConfig.setPrompt(prompt);
    protocolConfig.setQueues(queues);
    protocolConfig.setRegister(register);
    protocolConfig.setSerialization(serialization);
    protocolConfig.setServer(server);
    protocolConfig.setStatus(status);
    protocolConfig.setTelnet(telnet);
    protocolConfig.setThreadpool(threadpool);
    protocolConfig.setThreads(threads);
    protocolConfig.setTransporter(transporter);
    return protocolConfig;
}
Also used : ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Aggregations

ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)52 Test (org.junit.jupiter.api.Test)30 RegistryConfig (org.apache.dubbo.config.RegistryConfig)29 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)27 ServiceConfig (org.apache.dubbo.config.ServiceConfig)14 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)8 DemoService (org.apache.dubbo.config.spring.api.DemoService)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 ProviderConfig (org.apache.dubbo.config.ProviderConfig)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 GenericService (org.apache.dubbo.rpc.service.GenericService)5 Map (java.util.Map)4 URL (org.apache.dubbo.common.URL)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)3 ConfigTest (org.apache.dubbo.config.spring.ConfigTest)3 Test (org.junit.Test)3