use MD5Utils replace MD5
This commit is contained in:
parent
aeb14910e7
commit
dcdbaf50ea
@ -23,7 +23,7 @@ import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
||||
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
||||
import com.alibaba.nacos.client.config.listener.impl.AbstractConfigChangeListener;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -242,7 +242,7 @@ public class CacheData {
|
||||
}
|
||||
|
||||
static public String getMd5String(String config) {
|
||||
return (null == config) ? Constants.NULL : MD5.getInstance().getMD5String(config);
|
||||
return (null == config) ? Constants.NULL : MD5Utils.md5Hex(config, Constants.ENCODE);
|
||||
}
|
||||
|
||||
private String loadCacheContentFromDiskLocal(String name, String dataId, String group, String tenant) {
|
||||
|
@ -25,7 +25,7 @@ import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
||||
import com.alibaba.nacos.client.config.http.HttpAgent;
|
||||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
||||
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
@ -279,7 +279,7 @@ public class ClientWorker {
|
||||
// 没有 -> 有
|
||||
if (!cacheData.isUseLocalConfigInfo() && path.exists()) {
|
||||
String content = LocalConfigInfoProcessor.getFailover(agent.getName(), dataId, group, tenant);
|
||||
String md5 = MD5.getInstance().getMD5String(content);
|
||||
String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
cacheData.setUseLocalConfigInfo(true);
|
||||
cacheData.setLocalConfigInfoVersion(path.lastModified());
|
||||
cacheData.setContent(content);
|
||||
@ -301,7 +301,7 @@ public class ClientWorker {
|
||||
if (cacheData.isUseLocalConfigInfo() && path.exists()
|
||||
&& cacheData.getLocalConfigInfoVersion() != path.lastModified()) {
|
||||
String content = LocalConfigInfoProcessor.getFailover(agent.getName(), dataId, group, tenant);
|
||||
String md5 = MD5.getInstance().getMD5String(content);
|
||||
String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
cacheData.setUseLocalConfigInfo(true);
|
||||
cacheData.setLocalConfigInfoVersion(path.lastModified());
|
||||
cacheData.setContent(content);
|
||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.client.config.impl;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
@ -42,8 +42,8 @@ public class HttpSimpleClient {
|
||||
String encoding, long readTimeoutMs, boolean isSSL) throws IOException {
|
||||
String encodedContent = encodingParams(paramValues, encoding);
|
||||
url += (null == encodedContent) ? "" : ("?" + encodedContent);
|
||||
if (Limiter.isLimit(MD5.getInstance().getMD5String(
|
||||
new StringBuilder(url).append(encodedContent).toString()))) {
|
||||
if (Limiter.isLimit(MD5Utils.md5Hex(
|
||||
new StringBuilder(url).append(encodedContent).toString(), Constants.ENCODE))) {
|
||||
return new HttpResult(NacosException.CLIENT_OVER_THRESHOLD,
|
||||
"More than client-side current limit threshold");
|
||||
}
|
||||
@ -98,8 +98,8 @@ public class HttpSimpleClient {
|
||||
String encoding, long readTimeoutMs, boolean isSSL) throws IOException {
|
||||
String encodedContent = encodingParams(paramValues, encoding);
|
||||
encodedContent = (null == encodedContent) ? "" : encodedContent;
|
||||
if (Limiter.isLimit(MD5.getInstance().getMD5String(
|
||||
new StringBuilder(url).append(encodedContent).toString()))) {
|
||||
if (Limiter.isLimit(MD5Utils.md5Hex(
|
||||
new StringBuilder(url).append(encodedContent).toString(), Constants.ENCODE))) {
|
||||
return new HttpResult(NacosException.CLIENT_OVER_THRESHOLD,
|
||||
"More than client-side current limit threshold");
|
||||
}
|
||||
@ -150,8 +150,8 @@ public class HttpSimpleClient {
|
||||
String encoding, long readTimeoutMs, boolean isSSL) throws IOException {
|
||||
String encodedContent = encodingParams(paramValues, encoding);
|
||||
url += (null == encodedContent) ? "" : ("?" + encodedContent);
|
||||
if (Limiter.isLimit(MD5.getInstance().getMD5String(
|
||||
new StringBuilder(url).append(encodedContent).toString()))) {
|
||||
if (Limiter.isLimit(MD5Utils.md5Hex(
|
||||
new StringBuilder(url).append(encodedContent).toString(), Constants.ENCODE))) {
|
||||
return new HttpResult(NacosException.CLIENT_OVER_THRESHOLD,
|
||||
"More than client-side current limit threshold");
|
||||
}
|
||||
@ -197,7 +197,7 @@ public class HttpSimpleClient {
|
||||
conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);
|
||||
|
||||
String ts = String.valueOf(System.currentTimeMillis());
|
||||
String token = MD5.getInstance().getMD5String(ts + ParamUtil.getAppKey());
|
||||
String token = MD5Utils.md5Hex(ts + ParamUtil.getAppKey(), Constants.ENCODE);
|
||||
|
||||
conn.addRequestProperty(Constants.CLIENT_APPNAME_HEADER, ParamUtil.getAppName());
|
||||
conn.addRequestProperty(Constants.CLIENT_REQUEST_TS_HEADER, ts);
|
||||
|
@ -44,11 +44,6 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.alibaba.nacos.common.utils;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* MD5 util
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
|
||||
public class MD5 {
|
||||
private static int DIGITS_SIZE = 16;
|
||||
private static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
private static Map<Character, Integer> rDigits = Maps.newHashMapWithExpectedSize(16);
|
||||
|
||||
static {
|
||||
for (int i = 0; i < digits.length; ++i) {
|
||||
rDigits.put(digits[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
private static MD5 me = new MD5();
|
||||
private MessageDigest mHasher;
|
||||
private ReentrantLock opLock = new ReentrantLock();
|
||||
|
||||
private MD5() {
|
||||
try {
|
||||
mHasher = MessageDigest.getInstance("md5");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static MD5 getInstance() {
|
||||
return me;
|
||||
}
|
||||
|
||||
public String getMD5String(String content) {
|
||||
return bytes2string(hash(content));
|
||||
}
|
||||
|
||||
public String getMD5String(byte[] content) {
|
||||
return bytes2string(hash(content));
|
||||
}
|
||||
|
||||
public byte[] getMD5Bytes(byte[] content) {
|
||||
return hash(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串进行md5
|
||||
*
|
||||
* @param str
|
||||
* @return md5 byte[16]
|
||||
*/
|
||||
public byte[] hash(String str) {
|
||||
opLock.lock();
|
||||
try {
|
||||
byte[] bt = mHasher.digest(str.getBytes(Constants.ENCODE));
|
||||
if (null == bt || bt.length != DIGITS_SIZE) {
|
||||
throw new IllegalArgumentException("md5 need");
|
||||
}
|
||||
return bt;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("unsupported utf-8 encoding", e);
|
||||
} finally {
|
||||
opLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对二进制数据进行md5
|
||||
*
|
||||
* @param data
|
||||
* @return md5 byte[16]
|
||||
*/
|
||||
public byte[] hash(byte[] data) {
|
||||
opLock.lock();
|
||||
try {
|
||||
byte[] bt = mHasher.digest(data);
|
||||
if (null == bt || bt.length != DIGITS_SIZE) {
|
||||
throw new IllegalArgumentException("md5 need");
|
||||
}
|
||||
return bt;
|
||||
} finally {
|
||||
opLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个字节数组转化为可见的字符串
|
||||
*
|
||||
* @param bt
|
||||
* @return
|
||||
*/
|
||||
public String bytes2string(byte[] bt) {
|
||||
int l = bt.length;
|
||||
|
||||
char[] out = new char[l << 1];
|
||||
|
||||
for (int i = 0, j = 0; i < l; i++) {
|
||||
out[j++] = digits[(0xF0 & bt[i]) >>> 4];
|
||||
out[j++] = digits[0x0F & bt[i]];
|
||||
}
|
||||
|
||||
return new String(out);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.alibaba.nacos.common.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* MD5 util
|
||||
*
|
||||
*@author nacos
|
||||
*/
|
||||
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
|
||||
public class MD5Utils {
|
||||
|
||||
private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
private static ThreadLocal<MessageDigest> MESSAGE_DIGEST_LOCAL = new ThreadLocal<MessageDigest>() {
|
||||
@Override
|
||||
protected MessageDigest initialValue() {
|
||||
try {
|
||||
return MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static String md5Hex(byte[] bytes) throws NoSuchAlgorithmException {
|
||||
try {
|
||||
MessageDigest messageDigest = MESSAGE_DIGEST_LOCAL.get();
|
||||
if (messageDigest != null) {
|
||||
return encodeHexString(messageDigest.digest(bytes));
|
||||
}
|
||||
throw new NoSuchAlgorithmException("MessageDigest get MD5 instance error");
|
||||
} finally {
|
||||
MESSAGE_DIGEST_LOCAL.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public static String md5Hex(String value,String encode) {
|
||||
try {
|
||||
return md5Hex(value.getBytes(encode));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个字节数组转化为可见的字符串
|
||||
*/
|
||||
public static String encodeHexString(byte[] bytes) {
|
||||
int l = bytes.length;
|
||||
|
||||
char[] out = new char[l << 1];
|
||||
|
||||
for (int i = 0, j = 0; i < l; i++) {
|
||||
out[j++] = DIGITS_LOWER[(0xF0 & bytes[i]) >>> 4];
|
||||
out[j++] = DIGITS_LOWER[0x0F & bytes[i]];
|
||||
}
|
||||
|
||||
return new String(out);
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.alibaba.nacos.common.utils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MD5Test {
|
||||
|
||||
@Test
|
||||
public void testGetMD5String() {
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5.getInstance().getMD5String(""));
|
||||
Assert.assertEquals("acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
MD5.getInstance().getMD5String("foo"));
|
||||
Assert.assertEquals("02f463eb799797e2a978fb1a2ae2991e",
|
||||
MD5.getInstance().getMD5String("38c5ee9532f037a20b93d0f804cf111fca4003e451d09a692d9dea8032308d9c64eda9047fcd5e850284a49b1a0cfb2ecd45"));
|
||||
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5.getInstance().getMD5String(new byte[0]));
|
||||
Assert.assertEquals("5289df737df57326fcdd22597afb1fac",
|
||||
MD5.getInstance().getMD5String(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMD5Bytes() {
|
||||
byte[] bytes1 = new byte[]{-44, 29, -116, -39, -113, 0, -78,
|
||||
4, -23, -128, 9, -104, -20, -8, 66, 126};
|
||||
byte[] bytes2 = new byte[]{82, -119, -33, 115, 125, -11, 115,
|
||||
38, -4, -35, 34, 89, 122, -5, 31, -84};
|
||||
|
||||
Assert.assertArrayEquals(bytes1,
|
||||
MD5.getInstance().getMD5Bytes(new byte[0]));
|
||||
Assert.assertArrayEquals(bytes2,
|
||||
MD5.getInstance().getMD5Bytes(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHash() {
|
||||
byte[] bytes1 = new byte[]{-44, 29, -116, -39, -113, 0, -78,
|
||||
4, -23, -128, 9, -104, -20, -8, 66, 126};
|
||||
byte[] bytes2 = new byte[]{-84, -67, 24, -37, 76, -62, -8, 92,
|
||||
-19, -17, 101, 79, -52, -60, -92, -40};
|
||||
byte[] bytes3 = new byte[]{82, -119, -33, 115, 125, -11, 115,
|
||||
38, -4, -35, 34, 89, 122, -5, 31, -84};
|
||||
|
||||
Assert.assertArrayEquals(bytes1, MD5.getInstance().hash(""));
|
||||
Assert.assertArrayEquals(bytes2, MD5.getInstance().hash("foo"));
|
||||
Assert.assertArrayEquals(bytes1, MD5.getInstance().hash(new byte[0]));
|
||||
Assert.assertArrayEquals(bytes3,
|
||||
MD5.getInstance().hash(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes2string() {
|
||||
Assert.assertEquals("", MD5.getInstance().bytes2string(new byte[0]));
|
||||
Assert.assertEquals("010203",
|
||||
MD5.getInstance().bytes2string(new byte[]{1, 2, 3}));
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.alibaba.nacos.common.utils;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MD5UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testMd5Hex() throws NoSuchAlgorithmException {
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5Utils.md5Hex("", Constants.ENCODE));
|
||||
Assert.assertEquals("acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
MD5Utils.md5Hex("foo",Constants.ENCODE));
|
||||
Assert.assertEquals("02f463eb799797e2a978fb1a2ae2991e",
|
||||
MD5Utils.md5Hex("38c5ee9532f037a20b93d0f804cf111fca4003e451d09a692d9dea8032308d9c64eda9047fcd5e850284a49b1a0cfb2ecd45",Constants.ENCODE));
|
||||
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5Utils.md5Hex(new byte[0]));
|
||||
Assert.assertEquals("5289df737df57326fcdd22597afb1fac",
|
||||
MD5Utils.md5Hex(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeHexString() {
|
||||
Assert.assertEquals("", MD5Utils.encodeHexString(new byte[0]));
|
||||
Assert.assertEquals("010203",
|
||||
MD5Utils.encodeHexString(new byte[]{1, 2, 3}));
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.aspect;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
@ -66,7 +67,7 @@ public class RequestLogAspect {
|
||||
public Object interfacePublishSingle(ProceedingJoinPoint pjp, HttpServletRequest request,
|
||||
HttpServletResponse response, String dataId, String group, String tenant,
|
||||
String content) throws Throwable {
|
||||
final String md5 = content == null ? null : MD5.getInstance().getMD5String(content);
|
||||
final String md5 = content == null ? null : MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
MetricsMonitor.getPublishMonitor().incrementAndGet();
|
||||
return logClientRequest("publish", pjp, request, response, dataId, group, tenant, md5);
|
||||
}
|
||||
|
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.model;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
@ -46,7 +47,7 @@ public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase>
|
||||
this.group = group;
|
||||
this.content = content;
|
||||
if (this.content != null) {
|
||||
this.md5 = MD5.getInstance().getMD5String(this.content);
|
||||
this.md5 = MD5Utils.md5Hex(this.content, Constants.ENCODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.CacheItem;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
@ -70,7 +70,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
|
||||
if (md5.equals(ConfigService.getContentMd5(groupKey))) {
|
||||
dumpLog.warn(
|
||||
@ -116,7 +116,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
if (md5.equals(ConfigService.getContentBetaMd5(groupKey))) {
|
||||
dumpLog.warn(
|
||||
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
@ -155,7 +155,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
if (md5.equals(ConfigService.getContentTagMd5(groupKey, tag))) {
|
||||
dumpLog.warn(
|
||||
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
@ -192,7 +192,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
|
||||
if (md5.equals(loacalMd5)) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@ -172,7 +172,7 @@ public class DiskUtil {
|
||||
|
||||
static public String getLocalConfigMd5(String dataId, String group, String tenant)
|
||||
throws IOException {
|
||||
return MD5.getInstance().getMD5String(getConfig(dataId, group, tenant));
|
||||
return MD5Utils.md5Hex(getConfig(dataId, group, tenant), Constants.ENCODE);
|
||||
}
|
||||
|
||||
static public File heartBeatFile() {
|
||||
|
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.enums.FileTypeEnum;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
@ -537,7 +538,7 @@ public class PersistService {
|
||||
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
try {
|
||||
String md5 = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
jt.update(
|
||||
"INSERT INTO config_info_beta(data_id,group_id,tenant_id,app_name,content,md5,beta_ips,src_ip,"
|
||||
+ "src_user,gmt_create,gmt_modified) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
|
||||
@ -563,7 +564,7 @@ public class PersistService {
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();
|
||||
try {
|
||||
String md5 = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
jt.update(
|
||||
"INSERT INTO config_info_tag(data_id,group_id,tenant_id,tag_id,app_name,content,md5,src_ip,src_user,"
|
||||
+ "gmt_create,gmt_modified) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
|
||||
@ -627,7 +628,7 @@ public class PersistService {
|
||||
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
try {
|
||||
String md5 = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
jt.update(
|
||||
"UPDATE config_info_beta SET content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?,app_name=? WHERE "
|
||||
+ "data_id=? AND group_id=? AND tenant_id=?",
|
||||
@ -653,7 +654,7 @@ public class PersistService {
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();
|
||||
try {
|
||||
String md5 = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
jt.update(
|
||||
"UPDATE config_info_tag SET content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?,app_name=? WHERE "
|
||||
+ "data_id=? AND group_id=? AND tenant_id=? AND tag_id=?",
|
||||
@ -2694,7 +2695,7 @@ public class PersistService {
|
||||
final String type = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("type");
|
||||
final String schema = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("schema");
|
||||
|
||||
final String md5Tmp = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
|
||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
|
||||
@ -2903,7 +2904,7 @@ public class PersistService {
|
||||
final Timestamp time, Map<String, Object> configAdvanceInfo) {
|
||||
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
final String md5Tmp = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
String desc = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("desc");
|
||||
String use = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("use");
|
||||
String effect = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("effect");
|
||||
@ -3060,7 +3061,7 @@ public class PersistService {
|
||||
final Timestamp time, String ops) {
|
||||
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
|
||||
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
|
||||
final String md5Tmp = MD5.getInstance().getMD5String(configInfo.getContent());
|
||||
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
|
||||
try {
|
||||
jt.update(
|
||||
"INSERT INTO his_config_info (id,data_id,group_id,tenant_id,app_name,content,md5,src_ip,src_user,gmt_modified,op_type) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
|
||||
@ -3354,7 +3355,7 @@ public class PersistService {
|
||||
String md5InDb = cf.getMd5();
|
||||
final String content = cf.getContent();
|
||||
final String tenant = cf.getTenant();
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
if (StringUtils.isBlank(md5InDb)) {
|
||||
try {
|
||||
updateMd5(cf.getDataId(), cf.getGroup(), tenant, md5, new Timestamp(cf.getLastModified()));
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.config.server.service.dump;
|
||||
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.manager.TaskManager;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
@ -67,7 +67,7 @@ public class DumpService {
|
||||
PersistService persistService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
public void init() {
|
||||
LogUtil.defaultLog.warn("DumpService start");
|
||||
DumpProcessor processor = new DumpProcessor(this);
|
||||
DumpAllProcessor dumpAllProcessor = new DumpAllProcessor(this);
|
||||
@ -347,7 +347,7 @@ public class DumpService {
|
||||
ConfigInfo cf = MergeTaskProcessor.merge(dataId, group, tenant, datumList);
|
||||
String aggrContent = cf.getContent();
|
||||
String localContentMD5 = ConfigService.getContentMd5(GroupKey.getKey(dataId, group));
|
||||
String aggrConetentMD5 = MD5.getInstance().getMD5String(aggrContent);
|
||||
String aggrConetentMD5 = MD5Utils.md5Hex(aggrContent, Constants.ENCODE);
|
||||
|
||||
if (!StringUtils.equals(localContentMD5, aggrConetentMD5)) {
|
||||
persistService.insertOrUpdate(null, null, cf, time, null, false);
|
||||
|
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.dump;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.manager.AbstractTask;
|
||||
import com.alibaba.nacos.config.server.manager.TaskProcessor;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
@ -264,7 +265,7 @@ class DumpAllProcessor implements TaskProcessor {
|
||||
cf.getLastModified(), cf.getType());
|
||||
|
||||
final String content = cf.getContent();
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
LogUtil.dumpLog.info("[dump-all-ok] {}, {}, length={}, md5={}",
|
||||
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), content.length(), md5);
|
||||
}
|
||||
@ -409,7 +410,7 @@ class DumpChangeProcessor implements TaskProcessor {
|
||||
boolean result = ConfigService.dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(),
|
||||
cf.getContent(), cf.getLastModified());
|
||||
final String content = cf.getContent();
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
LogUtil.defaultLog.info(
|
||||
"[dump-change-ok] {}, {}, length={}, md5={}",
|
||||
new Object[] {
|
||||
|
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.trace;
|
||||
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -61,7 +62,7 @@ public class ConfigTraceService {
|
||||
}
|
||||
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1] | ext
|
||||
// (md5)
|
||||
String md5 = content == null ? null : MD5.getInstance().getMD5String(content);
|
||||
String md5 = content == null ? null : MD5Utils.md5Hex(content, Constants.ENCODE);
|
||||
|
||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||
requestIpAppName, ts, handleIp, "persist", type, -1, md5);
|
||||
|
@ -17,7 +17,8 @@ package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.naming.pojo.Record;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@ -66,7 +67,7 @@ public class Instances implements Record {
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
return MD5.getInstance().getMD5String(sb.toString());
|
||||
return MD5Utils.md5Hex(sb.toString(), Constants.ENCODE);
|
||||
}
|
||||
|
||||
public String convertMap2String(Map<String, String> map) {
|
||||
|
@ -17,7 +17,8 @@ package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.common.utils.MD5;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.naming.boot.SpringContext;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||
@ -472,7 +473,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
ipsString.append(",");
|
||||
}
|
||||
|
||||
checksum = MD5.getInstance().getMD5String(ipsString.toString());
|
||||
checksum = MD5Utils.md5Hex(ipsString.toString(), Constants.ENCODE);
|
||||
}
|
||||
|
||||
private void updateOrAddCluster(Collection<Cluster> clusters) {
|
||||
|
Loading…
Reference in New Issue
Block a user