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();
}
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()));
}
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);
}
}
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());
}
}
}
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;
}
Aggregations