-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1348 from daizhenyu/tag-transmission-demo
流量标签透传插件集成测试demo:tomcat demo、jetty demo、jdkhttp demo、httpclientv3 dem…
- Loading branch information
Showing
27 changed files
with
1,031 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
sermant-integration-tests/tag-transmission-test/httpclientv3-demo/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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>tag-transmission-test</artifactId> | ||
<groupId>com.huaweicloud.sermant.tagtransmission</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>httpclientv3-demo</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-httpclient</groupId> | ||
<artifactId>commons-httpclient</artifactId> | ||
<version>${httpclient3x.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...rc/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/HttpClientApplication.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,38 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* 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.huaweicloud.demo.tagtransmission.httpclientv3; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* springboot 启动类 | ||
* | ||
* @author daizhenyu | ||
* @since 2023-10-13 | ||
**/ | ||
@SpringBootApplication | ||
public class HttpClientApplication { | ||
/** | ||
* 启动类 | ||
* | ||
* @param args 进程启动入参 | ||
*/ | ||
public static void main(String[] args) { | ||
SpringApplication.run(HttpClientApplication.class, args); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../com/huaweicloud/demo/tagtransmission/httpclientv3/controller/HttpClientV3Controller.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,63 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* 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.huaweicloud.demo.tagtransmission.httpclientv3.controller; | ||
|
||
import org.apache.commons.httpclient.HttpClient; | ||
import org.apache.commons.httpclient.methods.GetMethod; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* controller,使用httpclient4.x调用http 服务端 | ||
* | ||
* @author daizhenyu | ||
* @since 2023-10-14 | ||
**/ | ||
@RestController | ||
@RequestMapping(value = "httpClientV3") | ||
public class HttpClientV3Controller { | ||
@Value("${common.server.url}") | ||
private String commonServerUrl; | ||
|
||
/** | ||
* 验证httpclient3.x透传流量标签 | ||
* | ||
* @return 流量标签值 | ||
* @throws IOException | ||
*/ | ||
@RequestMapping(value = "testHttpClientV3", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) | ||
public String testHttpClientV3() throws IOException { | ||
return doHttpClientV3Get(commonServerUrl); | ||
} | ||
|
||
private String doHttpClientV3Get(String url) throws IOException { | ||
// 创建 HttpClient 实例 | ||
HttpClient httpClient = new HttpClient(); | ||
GetMethod getMethod = new GetMethod(url); | ||
|
||
// 执行 GET 请求 | ||
httpClient.executeMethod(getMethod); | ||
String responseContext = getMethod.getResponseBodyAsString(); | ||
getMethod.releaseConnection(); | ||
return responseContext; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...n-tests/tag-transmission-test/httpclientv3-demo/src/main/resources/application.properties
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,2 @@ | ||
common.server.url=http://127.0.0.1:9040/common/httpServer | ||
server.port=9048 |
40 changes: 40 additions & 0 deletions
40
sermant-integration-tests/tag-transmission-test/httpclientv4-demo/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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>tag-transmission-test</artifactId> | ||
<groupId>com.huaweicloud.sermant.tagtransmission</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>httpclientv4-demo</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>${httpclient4x.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...rc/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/HttpClientApplication.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,38 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* 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.huaweicloud.demo.tagtransmission.httpclientv4; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* springboot 启动类 | ||
* | ||
* @author daizhenyu | ||
* @since 2023-09-07 | ||
**/ | ||
@SpringBootApplication | ||
public class HttpClientApplication { | ||
/** | ||
* 启动类 | ||
* | ||
* @param args 进程启动入参 | ||
*/ | ||
public static void main(String[] args) { | ||
SpringApplication.run(HttpClientApplication.class, args); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../com/huaweicloud/demo/tagtransmission/httpclientv4/controller/HttpClientV4Controller.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,67 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* 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.huaweicloud.demo.tagtransmission.httpclientv4.controller; | ||
|
||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.util.EntityUtils; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* controller,使用httpclient3.x调用http 服务端 | ||
* | ||
* @author daizhenyu | ||
* @since 2023-10-14 | ||
**/ | ||
@RestController | ||
@RequestMapping(value = "httpClientV4") | ||
public class HttpClientV4Controller { | ||
@Value("${common.server.url}") | ||
private String commonServerUrl; | ||
|
||
/** | ||
* 验证httpclient4.x透传流量标签 | ||
* | ||
* @return 流量标签值 | ||
* @throws IOException | ||
*/ | ||
@RequestMapping(value = "testHttpClientV4", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) | ||
public String testHttpClientV4() throws IOException { | ||
return doHttpClientV4Get(commonServerUrl); | ||
} | ||
|
||
private String doHttpClientV4Get(String url) throws IOException { | ||
// 创建 CloseableHttpClient 实例 | ||
CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
HttpGet httpGet = new HttpGet(url); | ||
|
||
// 执行 GET 请求 | ||
CloseableHttpResponse response = httpClient.execute(httpGet); | ||
String responseContext = EntityUtils.toString(response.getEntity()); | ||
response.close(); | ||
httpClient.close(); | ||
return responseContext; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...n-tests/tag-transmission-test/httpclientv4-demo/src/main/resources/application.properties
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,2 @@ | ||
common.server.url=http://127.0.0.1:9040/common/httpServer | ||
server.port=9049 |
39 changes: 39 additions & 0 deletions
39
sermant-integration-tests/tag-transmission-test/jdkhttp-demo/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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>tag-transmission-test</artifactId> | ||
<groupId>com.huaweicloud.sermant.tagtransmission</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jdkhttp-demo</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.huaweicloud.sermant.tagtransmission</groupId> | ||
<artifactId>tag-transmission-util-demo</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...p-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/JdkHttpApplication.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,38 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* 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.huaweicloud.demo.tagtransmission.jdkhttp; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* springboot 启动类 | ||
* | ||
* @author daizhenyu | ||
* @since 2023-09-07 | ||
**/ | ||
@SpringBootApplication | ||
public class JdkHttpApplication { | ||
/** | ||
* 启动类 | ||
* | ||
* @param args 进程启动入参 | ||
*/ | ||
public static void main(String[] args) { | ||
SpringApplication.run(JdkHttpApplication.class, args); | ||
} | ||
} |
Oops, something went wrong.