Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1363] support default load the route header context configuration (#1364) #1371

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
Loading