This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Consul registry support (#126) * consul registry support * fix cr * Support nacos converter (#130) * Upgrade version * Support nacos address converter * Hystrix switcher (#137) * support enableHystrix * support enableHystrix * hystrix enable * Add nacos client dependency support. (#148) * Zk auth support. (#156) * Server config for rest cors. (#155) * server config for rest cors * add test case for cors
- Loading branch information
1 parent
64635b8
commit 682e0ca
Showing
19 changed files
with
515 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/common/RegistryParseUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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.alipay.sofa.rpc.boot.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.alipay.sofa.rpc.common.utils.StringUtils; | ||
|
||
/** | ||
* | ||
* @author JervyShi | ||
* @version $Id: RegistryParseUtil.java, v 0.1 2018-12-03 17:18 JervyShi Exp $$ | ||
*/ | ||
public class RegistryParseUtil { | ||
|
||
/** | ||
* Parse address string. | ||
* | ||
* @param config the config | ||
* @param protocol the protocol | ||
* @return the string | ||
*/ | ||
public static String parseAddress(String config, String protocol) { | ||
String address = null; | ||
|
||
if (StringUtils.isNotEmpty(config) && config.startsWith(protocol)) { | ||
final String nacosProtocol = protocol + "://"; | ||
String value = config.substring(nacosProtocol.length()); | ||
if (!value.contains("?")) { | ||
address = value; | ||
} else { | ||
int index = value.lastIndexOf('?'); | ||
address = value.substring(0, index); | ||
} | ||
} | ||
|
||
return address; | ||
} | ||
|
||
/** | ||
* Parse param map. | ||
* | ||
* @param address the address | ||
* @param protocol the protocol | ||
* @return the map | ||
*/ | ||
public static Map<String, String> parseParam(String address, String protocol) { | ||
|
||
String host = parseAddress(address, protocol); | ||
|
||
//for config ? | ||
String paramString = address.substring(address.indexOf(host) + host.length()); | ||
|
||
if (StringUtils.isNotEmpty(paramString) && paramString.startsWith("?")) { | ||
paramString = paramString.substring(1); | ||
} | ||
|
||
Map<String, String> map = new HashMap<String, String>(); | ||
if (paramString.contains("&")) { | ||
String[] paramSplit = paramString.split("&"); | ||
for (String param : paramSplit) { | ||
Map<String, String> tempMap = parseKeyValue(param); | ||
map.putAll(tempMap); | ||
} | ||
} else { | ||
Map<String, String> tempMap = parseKeyValue(paramString); | ||
map.putAll(tempMap); | ||
} | ||
|
||
return map; | ||
} | ||
|
||
/** | ||
* Parse key value map. | ||
* | ||
* @param kv the kv | ||
* @return the map | ||
*/ | ||
public static Map<String, String> parseKeyValue(String kv) { | ||
Map<String, String> map = new HashMap<String, String>(); | ||
if (StringUtils.isNotEmpty(kv)) { | ||
String[] kvSplit = kv.split("="); | ||
String key = kvSplit[0]; | ||
String value = kvSplit[1]; | ||
map.put(key, value); | ||
} | ||
return map; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/ConsulConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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.alipay.sofa.rpc.boot.config; | ||
|
||
import com.alipay.sofa.rpc.common.utils.StringUtils; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Consul 配置 | ||
* <p> | ||
* 配置格式: com.alipay.sofa.rpc.registry.address=consul://xxx:8500 | ||
* | ||
* @author <a href="mailto:[email protected]">zhiyuan.lzy</a> | ||
*/ | ||
public class ConsulConfigurator implements RegistryConfigureProcessor { | ||
|
||
public ConsulConfigurator() { | ||
} | ||
|
||
/** | ||
* 解析配置 value | ||
* | ||
* @param config 配置 value | ||
*/ | ||
String parseAddress(String config) { | ||
String address = null; | ||
|
||
if (StringUtils.isNotEmpty(config) && config.startsWith(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_CONSUL)) { | ||
final String consulProtocol = SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_CONSUL + "://"; | ||
String value = config.substring(consulProtocol.length()); | ||
if (!value.contains("?")) { | ||
address = value; | ||
} else { | ||
int index = value.lastIndexOf('?'); | ||
address = value.substring(0, index); | ||
} | ||
} | ||
|
||
return address; | ||
} | ||
|
||
/** | ||
* 传递原始 url | ||
* | ||
* @param address | ||
* @return | ||
*/ | ||
public Map<String, String> parseParam(String address) { | ||
|
||
String host = parseAddress(address); | ||
|
||
//for config ? | ||
String paramString = address.substring(address.indexOf(host) + host.length()); | ||
|
||
if (StringUtils.isNotEmpty(paramString) && paramString.startsWith("?")) { | ||
paramString = paramString.substring(1); | ||
} | ||
|
||
Map<String, String> map = new HashMap<String, String>(); | ||
if (paramString.contains("&")) { | ||
String[] paramSplit = paramString.split("&"); | ||
for (String param : paramSplit) { | ||
Map<String, String> tempMap = parseKeyValue(param); | ||
map.putAll(tempMap); | ||
} | ||
} else { | ||
Map<String, String> tempMap = parseKeyValue(paramString); | ||
map.putAll(tempMap); | ||
} | ||
|
||
return map; | ||
} | ||
|
||
private Map<String, String> parseKeyValue(String kv) { | ||
Map<String, String> map = new HashMap<String, String>(); | ||
if (StringUtils.isNotEmpty(kv)) { | ||
String[] kvSplit = kv.split("="); | ||
String key = kvSplit[0]; | ||
String value = kvSplit[1]; | ||
map.put(key, value); | ||
} | ||
return map; | ||
} | ||
|
||
@Override | ||
public RegistryConfig buildFromAddress(String address) { | ||
String consulAddress = parseAddress(address); | ||
Map<String, String> map = parseParam(address); | ||
return new RegistryConfig() | ||
.setAddress(consulAddress) | ||
.setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_CONSUL) | ||
.setParameters(map); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/NacosConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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.alipay.sofa.rpc.boot.config; | ||
|
||
import java.util.Map; | ||
|
||
import com.alipay.sofa.rpc.boot.common.RegistryParseUtil; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
|
||
/** | ||
* Nacos 配置 | ||
* <p> | ||
* 配置格式: com.alipay.sofa.rpc.registry.address=nacos://xxx:8848?k1=v1 | ||
* </p> | ||
* | ||
* @author jervyshi | ||
* @version $Id: NacosConfigurator.java, v 0.1 2018-12-03 15:43 jervyshi Exp $$ | ||
*/ | ||
public class NacosConfigurator implements RegistryConfigureProcessor { | ||
|
||
public NacosConfigurator() { | ||
} | ||
|
||
@Override | ||
public RegistryConfig buildFromAddress(String address) { | ||
String nacosAddress = RegistryParseUtil.parseAddress(address, | ||
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS); | ||
Map<String, String> map = RegistryParseUtil.parseParam(address, | ||
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS); | ||
|
||
return new RegistryConfig().setAddress(nacosAddress).setParameters(map) | ||
.setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.