1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge pull request #1531 from zkzlx/config

[fix & enhance issue #1492 #1506 #1257 #1578 ]Improved nacos configuration parsing,
This commit is contained in:
TheoneFx 2021-01-06 14:39:25 +08:00 committed by GitHub
commit 4dd45a4709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 604 additions and 453 deletions

View File

@ -18,6 +18,7 @@ package com.alibaba.cloud.examples;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -34,7 +35,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -62,8 +65,12 @@ class UserConfig {
private String name; private String name;
private String hr;
private Map<String, Object> map; private Map<String, Object> map;
private List<User> users;
public int getAge() { public int getAge() {
return age; return age;
} }
@ -88,10 +95,65 @@ class UserConfig {
this.map = map; this.map = map;
} }
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public String getHr() {
return hr;
}
public void setHr(String hr) {
this.hr = hr;
}
@Override @Override
public String toString() { public String toString() {
return "UserConfig{" + "age=" + age + ", name='" + name + '\'' + ", map=" + map return "UserConfig{" + "age=" + age + ", name='" + name + '\'' + ", map=" + map
+ '}'; + ", hr='" + hr + '\'' + ", users=" + users + '}';
}
public static class User {
private String name;
private String hr;
private String avg;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHr() {
return hr;
}
public void setHr(String hr) {
this.hr = hr;
}
public String getAvg() {
return avg;
}
public void setAvg(String avg) {
this.avg = avg;
}
@Override
public String toString() {
return "User{" + "name='" + name + '\'' + ", hr=" + hr + ", avg=" + avg + '}';
}
} }
} }
@ -99,7 +161,7 @@ class UserConfig {
@Component @Component
class SampleRunner implements ApplicationRunner { class SampleRunner implements ApplicationRunner {
@Value("${user.name}") @Value("${user.name:zz}")
String userName; String userName;
@Value("${user.age:25}") @Value("${user.age:25}")
@ -156,7 +218,10 @@ class SampleController {
@Autowired @Autowired
private NacosConfigManager nacosConfigManager; private NacosConfigManager nacosConfigManager;
@Value("${user.name}") @Autowired
private Environment environment;
@Value("${user.name:zz}")
String userName; String userName;
@Value("${user.age:25}") @Value("${user.age:25}")
@ -168,6 +233,11 @@ class SampleController {
+ userConfig + "!" + nacosConfigManager.getConfigService(); + userConfig + "!" + nacosConfigManager.getConfigService();
} }
@RequestMapping("/get/{name}")
public String getValue(@PathVariable String name) {
return String.valueOf(environment.getProperty(name));
}
@RequestMapping("/bool") @RequestMapping("/bool")
public boolean bool() { public boolean bool() {
return (Boolean) (userConfig.getMap().get("2")); return (Boolean) (userConfig.getMap().get("2"));

View File

@ -5,19 +5,26 @@ spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.username=nacos spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos spring.cloud.nacos.password=nacos
#spring.cloud.nacos.config.namespace=public
spring.cloud.nacos.config.name=test-aaa
spring.cloud.nacos.config.file-extension=yaml
#spring.cloud.nacos.config.refreshable-dataids=common.properties #spring.cloud.nacos.config.refreshable-dataids=common.properties
#spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties #spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties
spring.cloud.nacos.config.shared-configs[0]= common333.properties #spring.cloud.nacos.config.shared-configs[0]= common333.properties
spring.cloud.nacos.config.shared-configs[1].data-id= common111.properties #spring.cloud.nacos.config.shared-configs[1].data-id= common111.properties
spring.cloud.nacos.config.shared-configs[1].group= GROUP_APP1 #spring.cloud.nacos.config.shared-configs[1].group= GROUP_APP1
spring.cloud.nacos.config.shared-configs[1].refresh= true #spring.cloud.nacos.config.shared-configs[1].refresh= true
spring.cloud.nacos.config.shared-configs[2]= common222.properties #spring.cloud.nacos.config.shared-configs[2]= common222.properties
spring.cloud.nacos.config.shared-configs[0].data-id= test2.yaml
spring.cloud.nacos.config.shared-configs[0].refresh=true
#spring.cloud.nacos.config.ext-config[0]=ext.properties #spring.cloud.nacos.config.ext-config[0]=ext.properties
spring.cloud.nacos.config.extension-configs[0].data-id= extension1.properties spring.cloud.nacos.config.extension-configs[0].data-id= extension1.properties
spring.cloud.nacos.config.extension-configs[0].refresh= true spring.cloud.nacos.config.extension-configs[0].refresh=true
spring.cloud.nacos.config.extension-configs[1]= extension2.properties spring.cloud.nacos.config.extension-configs[1].data-id= test1.yml
spring.cloud.nacos.config.extension-configs[2].data-id= extension3.json spring.cloud.nacos.config.extension-configs[1].refresh= true

View File

@ -20,7 +20,6 @@ import com.alibaba.cloud.examples.service.EchoService;
/** /**
* @author lengleng * @author lengleng
* @date 2019-08-01
* <p> * <p>
* sentinel 降级处理 * sentinel 降级处理
*/ */
@ -35,7 +34,7 @@ public class EchoServiceFallback implements EchoService {
/** /**
* 调用服务提供方的输出接口. * 调用服务提供方的输出接口.
* @param str 用户输入 * @param str 用户输入
* @return * @return String
*/ */
@Override @Override
public String echo(String str) { public String echo(String str) {

View File

@ -22,7 +22,6 @@ import org.springframework.stereotype.Component;
/** /**
* @author lengleng * @author lengleng
* @date 2019-08-01
*/ */
@Component @Component
public class EchoServiceFallbackFactory implements FallbackFactory<EchoServiceFallback> { public class EchoServiceFallbackFactory implements FallbackFactory<EchoServiceFallback> {

View File

@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.PathVariable;
/** /**
* @author lengleng * @author lengleng
* @date 2019-08-01
* <p> * <p>
* example feign client * example feign client
*/ */

View File

@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RestController;
/** /**
* @author lengleng * @author lengleng
* @date 2019-08-01
*/ */
@RestController @RestController
public class EchoController { public class EchoController {

View File

@ -16,12 +16,16 @@
package com.alibaba.cloud.nacos.client; package com.alibaba.cloud.nacos.client;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.cloud.nacos.NacosConfigProperties; import com.alibaba.cloud.nacos.NacosConfigProperties;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.util.CollectionUtils;
/** /**
* @author xiaojing * @author xiaojing
@ -58,6 +62,32 @@ public class NacosPropertySource extends MapPropertySource {
this.isRefreshable = isRefreshable; this.isRefreshable = isRefreshable;
} }
NacosPropertySource(List<PropertySource<?>> propertySources, String group,
String dataId, Date timestamp, boolean isRefreshable) {
this(group, dataId, getSourceMap(group, dataId, propertySources), timestamp,
isRefreshable);
}
private static Map<String, Object> getSourceMap(String group, String dataId,
List<PropertySource<?>> propertySources) {
if (CollectionUtils.isEmpty(propertySources)) {
return Collections.emptyMap();
}
// If only one, return the internal element, otherwise wrap it.
if (propertySources.size() == 1) {
PropertySource propertySource = propertySources.get(0);
if (propertySource != null && propertySource.getSource() instanceof Map) {
return (Map<String, Object>) propertySource.getSource();
}
}
// If it is multiple, it will be returned as it is, and the internal elements
// cannot be directly retrieved, so the user needs to implement the retrieval
// logic by himself
return Collections.singletonMap(
String.join(NacosConfigProperties.COMMAS, dataId, group),
propertySources);
}
public String getGroup() { public String getGroup() {
return this.group; return this.group;
} }

View File

@ -16,9 +16,9 @@
package com.alibaba.cloud.nacos.client; package com.alibaba.cloud.nacos.client;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.List;
import java.util.Map;
import com.alibaba.cloud.nacos.NacosPropertySourceRepository; import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
@ -27,6 +27,7 @@ import com.alibaba.nacos.api.exception.NacosException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -38,8 +39,6 @@ public class NacosPropertySourceBuilder {
private static final Logger log = LoggerFactory private static final Logger log = LoggerFactory
.getLogger(NacosPropertySourceBuilder.class); .getLogger(NacosPropertySourceBuilder.class);
private static final Map<String, Object> EMPTY_MAP = new LinkedHashMap();
private ConfigService configService; private ConfigService configService;
private long timeout; private long timeout;
@ -71,14 +70,15 @@ public class NacosPropertySourceBuilder {
*/ */
NacosPropertySource build(String dataId, String group, String fileExtension, NacosPropertySource build(String dataId, String group, String fileExtension,
boolean isRefreshable) { boolean isRefreshable) {
Map<String, Object> p = loadNacosData(dataId, group, fileExtension); List<PropertySource<?>> propertySources = loadNacosData(dataId, group,
NacosPropertySource nacosPropertySource = new NacosPropertySource(group, dataId, fileExtension);
p, new Date(), isRefreshable); NacosPropertySource nacosPropertySource = new NacosPropertySource(propertySources,
group, dataId, new Date(), isRefreshable);
NacosPropertySourceRepository.collectNacosPropertySource(nacosPropertySource); NacosPropertySourceRepository.collectNacosPropertySource(nacosPropertySource);
return nacosPropertySource; return nacosPropertySource;
} }
private Map<String, Object> loadNacosData(String dataId, String group, private List<PropertySource<?>> loadNacosData(String dataId, String group,
String fileExtension) { String fileExtension) {
String data = null; String data = null;
try { try {
@ -87,24 +87,23 @@ public class NacosPropertySourceBuilder {
log.warn( log.warn(
"Ignore the empty nacos configuration and get it based on dataId[{}] & group[{}]", "Ignore the empty nacos configuration and get it based on dataId[{}] & group[{}]",
dataId, group); dataId, group);
return EMPTY_MAP; return Collections.emptyList();
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(String.format( log.debug(String.format(
"Loading nacos data, dataId: '%s', group: '%s', data: %s", dataId, "Loading nacos data, dataId: '%s', group: '%s', data: %s", dataId,
group, data)); group, data));
} }
Map<String, Object> dataMap = NacosDataParserHandler.getInstance() return NacosDataParserHandler.getInstance().parseNacosData(dataId, data,
.parseNacosData(data, fileExtension); fileExtension);
return dataMap == null ? EMPTY_MAP : dataMap;
} }
catch (NacosException e) { catch (NacosException e) {
log.error("get data from Nacos error,dataId:{}, ", dataId, e); log.error("get data from Nacos error,dataId:{} ", dataId, e);
} }
catch (Exception e) { catch (Exception e) {
log.error("parse data from Nacos error,dataId:{},data:{},", dataId, data, e); log.error("parse data from Nacos error,dataId:{},data:{}", dataId, data, e);
} }
return EMPTY_MAP; return Collections.emptyList();
} }
} }

View File

@ -101,7 +101,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
loadSharedConfiguration(composite); loadSharedConfiguration(composite);
loadExtConfiguration(composite); loadExtConfiguration(composite);
loadApplicationConfiguration(composite, dataIdPrefix, nacosConfigProperties, env); loadApplicationConfiguration(composite, dataIdPrefix, nacosConfigProperties, env);
return composite; return composite;
} }
@ -156,16 +155,15 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
private void loadNacosConfiguration(final CompositePropertySource composite, private void loadNacosConfiguration(final CompositePropertySource composite,
List<NacosConfigProperties.Config> configs) { List<NacosConfigProperties.Config> configs) {
for (NacosConfigProperties.Config config : configs) { for (NacosConfigProperties.Config config : configs) {
String dataId = config.getDataId(); loadNacosDataIfPresent(composite, config.getDataId(), config.getGroup(),
String fileExtension = dataId.substring(dataId.lastIndexOf(DOT) + 1); NacosDataParserHandler.getInstance()
loadNacosDataIfPresent(composite, dataId, config.getGroup(), fileExtension, .getFileExtension(config.getDataId()),
config.isRefresh()); config.isRefresh());
} }
} }
private void checkConfiguration(List<NacosConfigProperties.Config> configs, private void checkConfiguration(List<NacosConfigProperties.Config> configs,
String tips) { String tips) {
String[] dataIds = new String[configs.size()];
for (int i = 0; i < configs.size(); i++) { for (int i = 0; i < configs.size(); i++) {
String dataId = configs.get(i).getDataId(); String dataId = configs.get(i).getDataId();
if (dataId == null || dataId.trim().length() == 0) { if (dataId == null || dataId.trim().length() == 0) {
@ -173,10 +171,7 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
"the [ spring.cloud.nacos.config.%s[%s] ] must give a dataId", "the [ spring.cloud.nacos.config.%s[%s] ] must give a dataId",
tips, i)); tips, i));
} }
dataIds[i] = dataId;
} }
// Just decide that the current dataId must have a suffix
NacosDataParserHandler.getInstance().checkDataId(dataIds);
} }
private void loadNacosDataIfPresent(final CompositePropertySource composite, private void loadNacosDataIfPresent(final CompositePropertySource composite,

View File

@ -1,175 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.util.StringUtils;
/**
* @author zkz
*/
public abstract class AbstractNacosDataParser {
protected static final String DOT = ".";
protected static final String VALUE = "value";
protected static final String EMPTY_STRING = "";
private String extension;
private AbstractNacosDataParser nextParser;
protected AbstractNacosDataParser(String extension) {
if (StringUtils.isEmpty(extension)) {
throw new IllegalArgumentException("extension cannot be empty");
}
this.extension = extension.toLowerCase();
}
/**
* Verify dataId extensions.
* @param extension file extension. json or xml or yml or yaml or properties
* @return valid or not
*/
public final boolean checkFileExtension(String extension) {
if (this.isLegal(extension.toLowerCase())) {
return true;
}
if (this.nextParser == null) {
return false;
}
return this.nextParser.checkFileExtension(extension);
}
/**
* Parsing nacos configuration content.
* @param data config data from Nacos
* @param extension file extension. json or xml or yml or yaml or properties
* @return result of Properties
* @throws IOException thrown if there is a problem parsing config.
*/
public final Map<String, Object> parseNacosData(String data, String extension)
throws IOException {
if (extension == null || extension.length() < 1) {
throw new IllegalStateException("The file extension cannot be empty");
}
if (this.isLegal(extension.toLowerCase())) {
return this.doParse(data);
}
if (this.nextParser == null) {
throw new IllegalStateException(getTips(extension));
}
return this.nextParser.parseNacosData(data, extension);
}
/**
* Core logic for parsing.
* @param data config from Nacos
* @return result of Properties
* @throws IOException thrown if there is a problem parsing config.
*/
protected abstract Map<String, Object> doParse(String data) throws IOException;
protected AbstractNacosDataParser setNextParser(AbstractNacosDataParser nextParser) {
this.nextParser = nextParser;
return this;
}
public AbstractNacosDataParser addNextParser(AbstractNacosDataParser nextParser) {
if (this.nextParser == null) {
this.nextParser = nextParser;
}
else {
this.nextParser.addNextParser(nextParser);
}
return this;
}
protected boolean isLegal(String extension) {
return this.extension.equalsIgnoreCase(extension)
|| this.extension.contains(extension);
}
protected void flattenedMap(Map<String, Object> result, Map<String, Object> dataMap,
String parentKey) {
Set<Map.Entry<String, Object>> entries = dataMap.entrySet();
for (Iterator<Map.Entry<String, Object>> iterator = entries.iterator(); iterator
.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String key = entry.getKey();
Object value = entry.getValue();
String fullKey = StringUtils.isEmpty(parentKey) ? key : key.startsWith("[")
? parentKey.concat(key) : parentKey.concat(DOT).concat(key);
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
flattenedMap(result, map, fullKey);
continue;
}
else if (value instanceof Collection) {
int count = 0;
Collection<Object> collection = (Collection<Object>) value;
for (Object object : collection) {
flattenedMap(result,
Collections.singletonMap("[" + (count++) + "]", object),
fullKey);
}
continue;
}
result.put(fullKey, value);
}
}
/**
* Reload the key ending in `value` if need.
*/
protected Map<String, Object> reloadMap(Map<String, Object> map) {
if (map == null || map.isEmpty()) {
return null;
}
Map<String, Object> result = new LinkedHashMap<>(map);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
if (key.contains(DOT)) {
int idx = key.lastIndexOf(DOT);
String suffix = key.substring(idx + 1);
if (VALUE.equalsIgnoreCase(suffix)) {
result.put(key.substring(0, idx), entry.getValue());
}
}
}
return result;
}
public static String getTips(String fileName) {
return String.format(
"[%s] must contains file extension with properties|yaml|yml|xml|json",
fileName);
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.DOT;
/**
* Nacos-specific loader, If need to support other methods of parsing,you need to do the
* following steps:
* <p>
* 1.inherit {@link AbstractPropertySourceLoader} ;<br/>
* 2. define the file{@code spring.factories} and append
* {@code org.springframework.boot.env.PropertySourceLoader=..}; <br/>
* 3.the last step validate.
* </p>
* Notice the use of {@link NacosByteArrayResource} .
*
* @author zkz
*/
public abstract class AbstractPropertySourceLoader implements PropertySourceLoader {
/**
* Prevent interference with other loaders.Nacos-specific loader, unless the reload
* changes it.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return if the resource can be loaded
*/
protected boolean canLoad(String name, Resource resource) {
return resource instanceof NacosByteArrayResource;
}
/**
* Load the resource into one or more property sources. Implementations may either
* return a list containing a single source, or in the case of a multi-document format
* such as yaml a source for each document in the resource.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return a list property sources
* @throws IOException if the source cannot be loaded
*/
@Override
public List<PropertySource<?>> load(String name, Resource resource)
throws IOException {
if (!canLoad(name, resource)) {
return Collections.emptyList();
}
return this.doLoad(name, resource);
}
/**
* Load the resource into one or more property sources. Implementations may either
* return a list containing a single source, or in the case of a multi-document format
* such as yaml a source for each document in the resource.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return a list property sources
* @throws IOException if the source cannot be loaded
*/
protected abstract List<PropertySource<?>> doLoad(String name, Resource resource)
throws IOException;
protected void flattenedMap(Map<String, Object> result, Map<String, Object> dataMap,
String parentKey) {
if (dataMap == null || dataMap.isEmpty()) {
return;
}
Set<Entry<String, Object>> entries = dataMap.entrySet();
for (Iterator<Entry<String, Object>> iterator = entries.iterator(); iterator
.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String key = entry.getKey();
Object value = entry.getValue();
String fullKey = StringUtils.isEmpty(parentKey) ? key : key.startsWith("[")
? parentKey.concat(key) : parentKey.concat(DOT).concat(key);
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
flattenedMap(result, map, fullKey);
continue;
}
else if (value instanceof Collection) {
int count = 0;
Collection<Object> collection = (Collection<Object>) value;
for (Object object : collection) {
flattenedMap(result,
Collections.singletonMap("[" + (count++) + "]", object),
fullKey);
}
continue;
}
result.put(fullKey, value);
}
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import org.springframework.core.io.ByteArrayResource;
/**
* Nacos-specific resource.
*
* @author zkz
*/
public class NacosByteArrayResource extends ByteArrayResource {
private String filename;
/**
* Create a new {@code ByteArrayResource}.
* @param byteArray the byte array to wrap
*/
public NacosByteArrayResource(byte[] byteArray) {
super(byteArray);
}
/**
* Create a new {@code ByteArrayResource} with a description.
* @param byteArray the byte array to wrap
* @param description where the byte array comes from
*/
public NacosByteArrayResource(byte[] byteArray, String description) {
super(byteArray, description);
}
public void setFilename(String filename) {
this.filename = filename;
}
/**
* This implementation always returns {@code null}, assuming that this resource type
* does not have a filename.
*/
@Override
public String getFilename() {
return null == this.filename ? this.getDescription() : this.filename;
}
}

View File

@ -1,66 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* @author zkz
* @author yuhuangbin
*/
public class NacosDataJsonParser extends AbstractNacosDataParser {
protected NacosDataJsonParser() {
super("json");
}
@Override
protected Map<String, Object> doParse(String data) throws IOException {
if (StringUtils.isEmpty(data)) {
return null;
}
Map<String, Object> map = parseJSON2Map(data);
return this.reloadMap(map);
}
/**
* JSON to Map.
* @param json json data
* @return the map convert by json string
* @throws IOException thrown if there is a problem parsing config.
*/
private Map<String, Object> parseJSON2Map(String json) throws IOException {
Map<String, Object> result = new LinkedHashMap<>(32);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> nacosDataMap = mapper.readValue(json, LinkedHashMap.class);
if (CollectionUtils.isEmpty(nacosDataMap)) {
return result;
}
flattenedMap(result, nacosDataMap, EMPTY_STRING);
return result;
}
}

View File

@ -17,63 +17,139 @@
package com.alibaba.cloud.nacos.parser; package com.alibaba.cloud.nacos.parser;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/** /**
* @author zkz * @author zkz
*/ */
public final class NacosDataParserHandler { public final class NacosDataParserHandler {
private AbstractNacosDataParser parser; /**
* symbol: dot.
*/
public static final String DOT = ".";
/**
* constant.
*/
public static final String VALUE = "value";
/**
* default extension.
*/
public static final String DEFAULT_EXTENSION = "properties";
private static List<PropertySourceLoader> propertySourceLoaders;
private NacosDataParserHandler() { private NacosDataParserHandler() {
parser = this.createParser(); propertySourceLoaders = SpringFactoriesLoader
.loadFactories(PropertySourceLoader.class, getClass().getClassLoader());
} }
/** /**
* Parsing nacos configuration content. * Parsing nacos configuration content.
* @param data config from Nacos * @param configName name of nacos-config
* @param extension file extension. json or xml or yml or yaml or properties * @param configValue value from nacos-config
* @return result of LinkedHashMap * @param extension identifies the type of configValue
* @return result of Map
* @throws IOException thrown if there is a problem parsing config. * @throws IOException thrown if there is a problem parsing config.
*/ */
public Map<String, Object> parseNacosData(String data, String extension) public List<PropertySource<?>> parseNacosData(String configName, String configValue,
throws IOException { String extension) throws IOException {
if (null == parser) { if (StringUtils.isEmpty(configValue)) {
parser = this.createParser(); return Collections.emptyList();
} }
return parser.parseNacosData(data, extension); if (StringUtils.isEmpty(extension)) {
extension = this.getFileExtension(configName);
}
for (PropertySourceLoader propertySourceLoader : propertySourceLoaders) {
if (!canLoadFileExtension(propertySourceLoader, extension)) {
continue;
}
NacosByteArrayResource nacosByteArrayResource = new NacosByteArrayResource(
configValue.getBytes(), configName);
nacosByteArrayResource.setFilename(getFileName(configName , extension));
List<PropertySource<?>> propertySourceList = propertySourceLoader
.load(configName, nacosByteArrayResource);
if (CollectionUtils.isEmpty(propertySourceList)) {
return Collections.emptyList();
}
return propertySourceList.stream().filter(Objects::nonNull)
.map(propertySource -> {
if (propertySource instanceof EnumerablePropertySource) {
String[] propertyNames = ((EnumerablePropertySource) propertySource)
.getPropertyNames();
if (propertyNames != null && propertyNames.length > 0) {
Map<String, Object> map = new LinkedHashMap<>();
Arrays.stream(propertyNames).forEach(name -> {
map.put(name, propertySource.getProperty(name));
});
return new OriginTrackedMapPropertySource(
propertySource.getName(), map, true);
}
}
return propertySource;
}).collect(Collectors.toList());
}
return Collections.emptyList();
} }
/** /**
* check the validity of file extensions in dataid. * check the current extension can be processed.
* @param dataIdAry array of dataId * @param loader the propertySourceLoader
* @return dataId handle success or not * @param extension file extension
* @return if can match extension
*/ */
public boolean checkDataId(String... dataIdAry) { private boolean canLoadFileExtension(PropertySourceLoader loader, String extension) {
StringBuilder stringBuilder = new StringBuilder(); return Arrays.stream(loader.getFileExtensions())
for (String dataId : dataIdAry) { .anyMatch((fileExtension) -> StringUtils.endsWithIgnoreCase(extension,
int idx = dataId.lastIndexOf(AbstractNacosDataParser.DOT); fileExtension));
if (idx > 0 && idx < dataId.length() - 1) {
String extension = dataId.substring(idx + 1);
if (parser.checkFileExtension(extension)) {
break;
}
}
// add tips
stringBuilder.append(dataId).append(",");
}
if (stringBuilder.length() > 0) {
String result = stringBuilder.substring(0, stringBuilder.length() - 1);
throw new IllegalStateException(AbstractNacosDataParser.getTips(result));
}
return true;
} }
private AbstractNacosDataParser createParser() { /**
return new NacosDataPropertiesParser().addNextParser(new NacosDataYamlParser()) * @param name filename
.addNextParser(new NacosDataXmlParser()) * @return file extension, default {@code DEFAULT_EXTENSION} if don't get
.addNextParser(new NacosDataJsonParser()); */
public String getFileExtension(String name) {
if (StringUtils.isEmpty(name)) {
return DEFAULT_EXTENSION;
}
int idx = name.lastIndexOf(DOT);
if (idx > 0 && idx < name.length() - 1) {
return name.substring(idx + 1);
}
return DEFAULT_EXTENSION;
}
private String getFileName(String name,String extension){
if(StringUtils.isEmpty(extension)){
return name;
}
if (StringUtils.isEmpty(name)) {
return extension;
}
int idx = name.lastIndexOf(DOT);
if (idx > 0 && idx < name.length() - 1) {
String ext = name.substring(idx + 1);
if(extension.equalsIgnoreCase(ext)){
return name;
}
}
return name + DOT + extension;
} }
public static NacosDataParserHandler getInstance() { public static NacosDataParserHandler getInstance() {

View File

@ -1,66 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.LinkedHashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
* @author zkz
*/
public class NacosDataPropertiesParser extends AbstractNacosDataParser {
private static final Logger log = LoggerFactory
.getLogger(NacosDataPropertiesParser.class);
public NacosDataPropertiesParser() {
super("properties");
}
@Override
protected Map<String, Object> doParse(String data) throws IOException {
Map<String, Object> result = new LinkedHashMap<>();
try (BufferedReader reader = new BufferedReader(new StringReader(data))) {
for (String line = reader.readLine(); line != null; line = reader
.readLine()) {
String dataLine = line.trim();
if (StringUtils.isEmpty(dataLine) || dataLine.startsWith("#")) {
continue;
}
int index = dataLine.indexOf("=");
if (index == -1) {
log.warn("the config data is invalid {}", dataLine);
continue;
}
String key = dataLine.substring(0, index);
String value = dataLine.substring(index + 1);
result.put(key.trim(), value.trim());
}
}
return result;
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.factory.config.YamlMapFactoryBean;
import org.springframework.core.io.ByteArrayResource;
/**
* @author zkz
*/
public class NacosDataYamlParser extends AbstractNacosDataParser {
public NacosDataYamlParser() {
super(",yml,yaml,");
}
@Override
protected Map<String, Object> doParse(String data) {
YamlMapFactoryBean yamlFactory = new YamlMapFactoryBean();
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
Map<String, Object> result = new LinkedHashMap<>();
flattenedMap(result, yamlFactory.getObject(), EMPTY_STRING);
return result;
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.parser;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.DOT;
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.VALUE;
/**
* @author zkz
*/
public class NacosJsonPropertySourceLoader extends AbstractPropertySourceLoader {
/**
* Returns the file extensions that the loader supports (excluding the '.').
* @return the file extensions
*/
@Override
public String[] getFileExtensions() {
return new String[] { "json" };
}
/**
* Load the resource into one or more property sources. Implementations may either
* return a list containing a single source, or in the case of a multi-document format
* such as yaml a source for each document in the resource.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return a list property sources
* @throws IOException if the source cannot be loaded
*/
@Override
protected List<PropertySource<?>> doLoad(String name, Resource resource)
throws IOException {
Map<String, Object> result = new LinkedHashMap<>(32);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> nacosDataMap = mapper.readValue(resource.getInputStream(),
LinkedHashMap.class);
flattenedMap(result, nacosDataMap, null);
return Collections.singletonList(
new OriginTrackedMapPropertySource(name, this.reloadMap(result), true));
}
/**
* Reload the key ending in `value` if need.
*/
protected Map<String, Object> reloadMap(Map<String, Object> map) {
if (map == null || map.isEmpty()) {
return null;
}
Map<String, Object> result = new LinkedHashMap<>(map);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
if (key.contains(DOT)) {
int idx = key.lastIndexOf(DOT);
String suffix = key.substring(idx + 1);
if (VALUE.equalsIgnoreCase(suffix)) {
result.put(key.substring(0, idx), entry.getValue());
}
}
}
return result;
}
}

View File

@ -17,8 +17,9 @@
package com.alibaba.cloud.nacos.parser; package com.alibaba.cloud.nacos.parser;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -28,39 +29,76 @@ import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* With relatively few usage scenarios, only simple parsing is performed to reduce jar * Parsing for XML requires overwriting the default
* dependencies. * {@link PropertiesPropertySourceLoader}, because it internally rigorously validates
* ({@conde DOCTYPE}) THE XML in a way that makes it difficult to customize the
* configuration; at finally, make sure it's in the first place.
* *
* @author zkz * @author zkz
*/ */
public class NacosDataXmlParser extends AbstractNacosDataParser { public class NacosXmlPropertySourceLoader extends AbstractPropertySourceLoader
implements Ordered {
public NacosDataXmlParser() {
super("xml");
}
/**
* Get the order value of this object.
* <p>
* Higher values are interpreted as lower priority. As a consequence, the object with
* the lowest value has the highest priority (somewhat analogous to Servlet
* {@code load-on-startup} values).
* <p>
* Same order values will result in arbitrary sort positions for the affected objects.
* @return the order value
* @see #HIGHEST_PRECEDENCE
* @see #LOWEST_PRECEDENCE
*/
@Override @Override
protected Map<String, Object> doParse(String data) throws IOException { public int getOrder() {
if (StringUtils.isEmpty(data)) { return Integer.MIN_VALUE;
return null;
}
Map<String, Object> map = parseXml2Map(data);
return this.reloadMap(map);
} }
private Map<String, Object> parseXml2Map(String xml) throws IOException { /**
xml = xml.replaceAll("\\r", "").replaceAll("\\n", "").replaceAll("\\t", ""); * Returns the file extensions that the loader supports (excluding the '.').
* @return the file extensions
*/
@Override
public String[] getFileExtensions() {
return new String[] { "xml" };
}
/**
* Load the resource into one or more property sources. Implementations may either
* return a list containing a single source, or in the case of a multi-document format
* such as yaml a source for each document in the resource.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return a list property sources
* @throws IOException if the source cannot be loaded
*/
@Override
protected List<PropertySource<?>> doLoad(String name, Resource resource)
throws IOException {
Map<String, Object> nacosDataMap = parseXml2Map(resource);
return Collections.singletonList(
new OriginTrackedMapPropertySource(name, nacosDataMap, true));
}
private Map<String, Object> parseXml2Map(Resource resource) throws IOException {
Map<String, Object> map = new LinkedHashMap<>(32); Map<String, Object> map = new LinkedHashMap<>(32);
try { try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance() DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder(); .newDocumentBuilder();
Document document = documentBuilder Document document = documentBuilder.parse(resource.getInputStream());
.parse(new InputSource(new StringReader(xml)));
if (null == document) { if (null == document) {
return null; return null;
} }
@ -89,7 +127,8 @@ public class NacosDataXmlParser extends AbstractNacosDataParser {
continue; continue;
} }
String key = StringUtils.isEmpty(parentKey) ? name : parentKey + DOT + name; String key = StringUtils.isEmpty(parentKey) ? name
: parentKey + NacosDataParserHandler.DOT + name;
NamedNodeMap nodeMap = node.getAttributes(); NamedNodeMap nodeMap = node.getAttributes();
parseNodeAttr(nodeMap, map, key); parseNodeAttr(nodeMap, map, key);
if (node.getNodeType() == Node.ELEMENT_NODE && node.hasChildNodes()) { if (node.getNodeType() == Node.ELEMENT_NODE && node.hasChildNodes()) {
@ -120,8 +159,8 @@ public class NacosDataXmlParser extends AbstractNacosDataParser {
if (StringUtils.isEmpty(node.getNodeValue())) { if (StringUtils.isEmpty(node.getNodeValue())) {
continue; continue;
} }
map.put(String.join(DOT, parentKey, node.getNodeName()), map.put(String.join(NacosDataParserHandler.DOT, parentKey,
node.getNodeValue()); node.getNodeName()), node.getNodeValue());
} }
} }
} }

View File

@ -5,3 +5,6 @@ com.alibaba.cloud.nacos.NacosConfigAutoConfiguration,\
com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration
org.springframework.boot.diagnostics.FailureAnalyzer=\ org.springframework.boot.diagnostics.FailureAnalyzer=\
com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureAnalyzer com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureAnalyzer
org.springframework.boot.env.PropertySourceLoader=\
com.alibaba.cloud.nacos.parser.NacosJsonPropertySourceLoader,\
com.alibaba.cloud.nacos.parser.NacosXmlPropertySourceLoader

View File

@ -50,7 +50,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*") @PowerMockIgnore({ "javax.management.*", "javax.xml.parsers.*",
"com.sun.org.apache.xerces.internal.jaxp.*", "org.w3c.dom.*" })
@PowerMockRunnerDelegate(SpringRunner.class) @PowerMockRunnerDelegate(SpringRunner.class)
@PrepareForTest({ NacosConfigService.class }) @PrepareForTest({ NacosConfigService.class })
@SpringBootTest(classes = NacosConfigurationNoSuffixTest.TestConfig.class, properties = { @SpringBootTest(classes = NacosConfigurationNoSuffixTest.TestConfig.class, properties = {

View File

@ -49,7 +49,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author zkz * @author zkz
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*") @PowerMockIgnore({ "javax.management.*", "javax.xml.parsers.*",
"com.sun.org.apache.xerces.internal.jaxp.*", "org.w3c.dom.*" })
@PowerMockRunnerDelegate(SpringRunner.class) @PowerMockRunnerDelegate(SpringRunner.class)
@PrepareForTest({ NacosConfigService.class }) @PrepareForTest({ NacosConfigService.class })
@SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class, properties = { @SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class, properties = {
@ -83,13 +84,15 @@ public class NacosConfigurationXmlJsonTest {
throws Throwable { throws Throwable {
if ("xmlApp.xml".equals(args[0]) && "test-group".equals(args[1])) { if ("xmlApp.xml".equals(args[0]) && "test-group".equals(args[1])) {
return "<top>\n" + " <first>one</first>\n" return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<top>\n"
+ " <first>one</first>\n"
+ " <sencond value=\"two\">\n" + " <sencond value=\"two\">\n"
+ " <third>three</third>\n" + " </sencond>\n" + " <third>three</third>\n" + " </sencond>\n"
+ "</top>"; + "</top>";
} }
if ("test-name.xml".equals(args[0]) && "test-group".equals(args[1])) { if ("test-name.xml".equals(args[0]) && "test-group".equals(args[1])) {
return "<Server port=\"8005\" shutdown=\"SHUTDOWN\"> \n" return "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<Server port=\"8005\" shutdown=\"SHUTDOWN\"> \n"
+ " <Service name=\"Catalina\"> \n" + " <Service name=\"Catalina\"> \n"
+ " <Connector value=\"第二个连接器\"> \n" + " <Connector value=\"第二个连接器\"> \n"
+ " <open>开启服务</open> \n" + " <open>开启服务</open> \n"
@ -108,7 +111,8 @@ public class NacosConfigurationXmlJsonTest {
if ("test-name-dev.xml".equals(args[0]) if ("test-name-dev.xml".equals(args[0])
&& "test-group".equals(args[1])) { && "test-group".equals(args[1])) {
return "<application android:label=\"@string/app_name\" android:icon=\"@drawable/osg\">\n" return "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<application android:label=\"@string/app_name\" android:icon=\"@drawable/osg\">\n"
+ " <activity android:name=\".osgViewer\"\n" + " <activity android:name=\".osgViewer\"\n"
+ " android:label=\"@string/app_name\" android:screenOrientation=\"landscape\">\n" + " android:label=\"@string/app_name\" android:screenOrientation=\"landscape\">\n"
+ " <intent-filter>\n" + " <intent-filter>\n"

View File

@ -40,6 +40,7 @@ public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher {
* <p> * <p>
* For example {@code " || "} for URL patterns or {@code " && "} for param * For example {@code " || "} for URL patterns or {@code " && "} for param
* expressions. * expressions.
* @return str
*/ */
protected abstract String getToStringInfix(); protected abstract String getToStringInfix();