-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support lossless online/offline. (#1338)
- Loading branch information
Showing
43 changed files
with
1,728 additions
and
20 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
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
78 changes: 78 additions & 0 deletions
78
spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/UrlUtils.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,78 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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.tencent.cloud.common.util; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
import static com.tencent.cloud.common.constant.ContextConstant.UTF_8; | ||
|
||
/** | ||
* Utils for URLDecoder/URLEncoder. | ||
* | ||
* @author Shedfree Wu | ||
*/ | ||
public final class UrlUtils { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(UrlUtils.class); | ||
|
||
private UrlUtils() { | ||
} | ||
|
||
public static String decode(String s) { | ||
return decode(s, UTF_8); | ||
} | ||
|
||
public static String decode(String s, String enc) { | ||
if (!StringUtils.hasText(s)) { | ||
return s; | ||
} | ||
try { | ||
return URLDecoder.decode(s, enc); | ||
} | ||
catch (UnsupportedEncodingException e) { | ||
LOG.warn("Runtime system does not support {} coding. s:{}, msg:{}", enc, s, e.getMessage()); | ||
// return original string | ||
return s; | ||
} | ||
} | ||
|
||
public static String encode(String s) { | ||
return encode(s, UTF_8); | ||
} | ||
|
||
public static String encode(String s, String enc) { | ||
if (!StringUtils.hasText(s)) { | ||
return s; | ||
} | ||
try { | ||
return URLEncoder.encode(s, enc); | ||
} | ||
catch (UnsupportedEncodingException e) { | ||
LOG.warn("Runtime system does not support {} coding. s:{}, msg:{}", enc, s, e.getMessage()); | ||
// return original string | ||
return s; | ||
} | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/util/UrlUtilsTest.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,68 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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.tencent.cloud.common.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Utils for {@link UrlUtils}. | ||
* | ||
* @author Shedfree Wu | ||
*/ | ||
public class UrlUtilsTest { | ||
|
||
@Test | ||
public void testEncodeDecode1() { | ||
String expectEncodeValue = "a%2Fb"; | ||
String origin = "a/b"; | ||
String encode1 = UrlUtils.encode(origin); | ||
assertThat(expectEncodeValue).isEqualTo(encode1); | ||
// encode twice is different | ||
String encode2 = UrlUtils.encode(encode1); | ||
assertThat(encode1).isNotEqualTo(encode2); | ||
// test decode | ||
assertThat(origin).isEqualTo(UrlUtils.decode(encode1)); | ||
} | ||
|
||
@Test | ||
public void testEncodeDecode2() { | ||
|
||
String origin = null; | ||
String encode1 = UrlUtils.encode(origin); | ||
assertThat(encode1).isNull(); | ||
|
||
origin = ""; | ||
encode1 = UrlUtils.encode(origin); | ||
assertThat(encode1).isEqualTo(origin); | ||
} | ||
|
||
@Test | ||
public void testError() { | ||
String origin = "a/b"; | ||
String encode = UrlUtils.encode(origin, "error-enc"); | ||
assertThat(encode).isEqualTo(origin); | ||
|
||
encode = "a%2Fb"; | ||
String decode = UrlUtils.decode(encode, "error-enc"); | ||
assertThat(decode).isEqualTo(encode); | ||
} | ||
|
||
} |
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
63 changes: 63 additions & 0 deletions
63
spring-cloud-tencent-examples/lossless-example/lossless-callee-service/pom.xml
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,63 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>lossless-example</artifactId> | ||
<groupId>com.tencent.cloud</groupId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>lossless-callee-service</artifactId> | ||
<name>Spring Cloud Starter Tencent Lossless Callee Service Example</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.tencent.cloud</groupId> | ||
<artifactId>spring-cloud-starter-tencent-all</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.tencent.cloud</groupId> | ||
<artifactId>spring-cloud-tencent-lossless-plugin</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.