Skip to content

Commit

Permalink
[#1363] support default load the route header context configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling authored Aug 16, 2024
1 parent e5d3926 commit 117cd6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ NacosPropertySource build(String dataId, String group, String fileExtension,
}

NacosPropertySource buildWithContext(String dataId, String group, String fileExtension, String context) {
List<PropertySource<?>> propertySources;
List<PropertySource<?>> propertySources = Collections.emptyList();
try {
propertySources = NacosDataParserHandler.getInstance().parseNacosData(dataId, context, fileExtension);
} catch (Exception e) {
log.error("build config error, dataId: {}, group: {}, context: {}", dataId, group, context, e);
return null;
}
NacosPropertySource nacosPropertySource = new NacosPropertySource(propertySources,
group, dataId, new Date(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,22 @@ private void loadLabelRouterConfigs(CompositePropertySource composite, Environme
NacosPropertiesFuzzyQueryService blurQueryService = NacosPropertiesFuzzyQueryService.getInstance();
blurQueryService.setConfigProperties(nacosConfigProperties);
List<PropertyConfigItem> routerProperties = blurQueryService.loadRouterProperties();
if (CollectionUtils.isEmpty(routerProperties)) {
return;
}
for (PropertyConfigItem item: routerProperties) {
NacosPropertySource propertySource = nacosPropertySourceBuilder.buildWithContext(item.getDataId(),
item.getGroup(), item.getType(), item.getContent());
if (propertySource == null) {
continue;
if (!CollectionUtils.isEmpty(routerProperties)) {
for (PropertyConfigItem item: routerProperties) {
NacosPropertySource propertySource = nacosPropertySourceBuilder.buildWithContext(item.getDataId(),
item.getGroup(), item.getType(), item.getContent());
this.addFirstPropertySource(composite, propertySource, false);
}
this.addFirstPropertySource(composite, propertySource, false);
}

// load header context configuration
loadRouterHeaderContextConfigs(composite);
}

private void loadRouterHeaderContextConfigs(CompositePropertySource composite) {
String group = nacosConfigProperties.getGroup();
String dataId = NacosConfigConst.ROUTER_HEADER_CONTEXT_CONFIG_DATA_ID;
loadNacosDataIfPresent(composite, dataId, group, NacosConfigConst.DEFAULT_CONFIG_FILE_EXTENSION, true);
}

private void loadSecurityConfigs(CompositePropertySource composite, Environment env) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public class NacosConfigConst {

public static final String SECURITY_CONFIG_DEFAULT_LOAD_ENABLED
= "spring.cloud.nacos.config.securityConfigDefaultLoadEnabled";

public static final String ROUTER_HEADER_CONTEXT_CONFIG_DATA_ID = "cse-router-header-context-mapper.yaml";
}

0 comments on commit 117cd6f

Please sign in to comment.