-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring Fury Serialization Integration
- Loading branch information
liujianjun.ljj
committed
Jan 2, 2024
1 parent
03ee605
commit f2d8a83
Showing
26 changed files
with
402 additions
and
880 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
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.codec.sofahessian; | ||
package com.alipay.sofa.rpc.codec.common; | ||
|
||
import com.alipay.sofa.rpc.common.SofaConfigs; | ||
import com.alipay.sofa.rpc.common.SofaOptions; | ||
|
@@ -37,17 +37,20 @@ | |
* | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class BlackListFileLoader { | ||
public class BlackAndWhiteListFileLoader { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(BlackListFileLoader.class); | ||
private static final Logger LOGGER = LoggerFactory | ||
.getLogger(BlackAndWhiteListFileLoader.class); | ||
|
||
public static final List<String> SOFA_SERIALIZE_BLACK_LIST = loadFile("/sofa-rpc/serialize_blacklist.txt"); | ||
public static final List<String> SOFA_SERIALIZE_BLACK_LIST = loadBlackListFile("/sofa-rpc/serialize_blacklist.txt"); | ||
|
||
static List<String> loadFile(String path) { | ||
List<String> blackPrefixList = new ArrayList<String>(); | ||
public static final List<String> SOFA_SERIALIZER_WHITE_LIST = loadWhiteListFile("/sofa-rpc/serialize_whitelist.txt"); | ||
|
||
public static List<String> loadBlackListFile(String path) { | ||
List<String> blackPrefixList = new ArrayList<>(); | ||
InputStream input = null; | ||
try { | ||
input = BlackListFileLoader.class.getResourceAsStream(path); | ||
input = BlackAndWhiteListFileLoader.class.getResourceAsStream(path); | ||
if (input != null) { | ||
readToList(input, "UTF-8", blackPrefixList); | ||
} | ||
|
@@ -68,6 +71,31 @@ static List<String> loadFile(String path) { | |
return blackPrefixList; | ||
} | ||
|
||
public static List<String> loadWhiteListFile(String path) { | ||
List<String> whitePrefixList = new ArrayList<>(); | ||
InputStream input = null; | ||
try { | ||
input = BlackAndWhiteListFileLoader.class.getResourceAsStream(path); | ||
if (input != null) { | ||
readToList(input, "UTF-8", whitePrefixList); | ||
} | ||
String overStr = SofaConfigs.getStringValue(SofaOptions.CONFIG_SERIALIZE_WHITELIST_OVERRIDE, ""); | ||
if (StringUtils.isNotBlank(overStr)) { | ||
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info("Serialize whitelist will override with configuration: {}", overStr); | ||
} | ||
overrideWhiteList(whitePrefixList, overStr); | ||
} | ||
} catch (Exception e) { | ||
if (LOGGER.isErrorEnabled()) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
} finally { | ||
closeQuietly(input); | ||
} | ||
return whitePrefixList; | ||
} | ||
|
||
/** | ||
* 读文件,将结果丢入List | ||
* | ||
|
@@ -100,12 +128,12 @@ private static void readToList(InputStream input, String encoding, List<String> | |
|
||
/** | ||
* Override blacklist with override string. | ||
* | ||
* @param originList Origin black list | ||
* | ||
* @param originList Origin black list | ||
* @param overrideStr The override string | ||
*/ | ||
static void overrideBlackList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<String>(); | ||
public static void overrideBlackList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<>(); | ||
String[] overrideItems = StringUtils.splitWithCommaOrSemicolon(overrideStr); | ||
for (String overrideItem : overrideItems) { | ||
if (StringUtils.isNotBlank(overrideItem)) { | ||
|
@@ -127,4 +155,19 @@ static void overrideBlackList(List<String> originList, String overrideStr) { | |
originList.addAll(adds); | ||
} | ||
} | ||
|
||
public static void overrideWhiteList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<>(); | ||
String[] overrideItems = StringUtils.splitWithCommaOrSemicolon(overrideStr); | ||
for (String overrideItem : overrideItems) { | ||
if (StringUtils.isNotBlank(overrideItem)) { | ||
if (!originList.contains(overrideItem)) { | ||
adds.add(overrideItem); | ||
} | ||
} | ||
} | ||
if (adds.size() > 0) { | ||
originList.addAll(adds); | ||
} | ||
} | ||
} |
File renamed without changes.
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
107 changes: 0 additions & 107 deletions
107
codec/codec-fury/src/main/java/com/alipay/sofa/rpc/codec/fury/FuryHelper.java
This file was deleted.
Oops, something went wrong.
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.