Skip to content

Commit 10d4ff9

Browse files
committed
feat:新增自测代码
1 parent 672a304 commit 10d4ff9

29 files changed

Lines changed: 934 additions & 7 deletions

File tree

‎01jvm/jvm/jvm-test/pom.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.huangfu</groupId>
8+
<artifactId>jvm-test</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
</properties>
15+
16+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.huangfu.jvm;
2+
3+
/**
4+
* @Author: HuangFu
5+
* @Date: 2021/9/23 8:42
6+
* @Description:
7+
*/
8+
public class CusClassLoader extends ClassLoader{
9+
10+
11+
12+
}

‎02nio/nio01-work/pom.xml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.huangfujs</groupId>
8+
<artifactId>nio01-work</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<app.main.class>Main</app.main.class>
13+
<maven.compile.source>8</maven.compile.source>
14+
<maven.compile.target>8</maven.compile.target>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<configuration>
23+
<source>${maven.compile.source}</source>
24+
<target>${maven.compile.target}</target>
25+
</configuration>
26+
</plugin>
27+
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-shade-plugin</artifactId>
31+
<version>3.2.0</version>
32+
<executions>
33+
<execution>
34+
<goals>
35+
<goal>shade</goal>
36+
</goals>
37+
<configuration>
38+
<transformers>
39+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40+
<manifestEntries>
41+
<Main-Class>${app.main.class}</Main-Class>
42+
<X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
43+
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
44+
</manifestEntries>
45+
</transformer>
46+
</transformers>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
54+
55+
56+
<dependencies>
57+
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
58+
<dependency>
59+
<groupId>com.squareup.okhttp3</groupId>
60+
<artifactId>okhttp</artifactId>
61+
<version>4.9.1</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.apache.httpcomponents</groupId>
65+
<artifactId>httpclient</artifactId>
66+
<version>4.5.6</version>
67+
<scope>compile</scope>
68+
</dependency>
69+
<!-- <dependency>-->
70+
<!-- <groupId>com.squareup.okhttp3</groupId>-->
71+
<!-- <artifactId>okhttp</artifactId>-->
72+
<!-- <version>3.12.2</version>-->
73+
<!-- <scope>compile</scope>-->
74+
<!-- </dependency>-->
75+
</dependencies>
76+
77+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.huangjs.nio.netty.httpClient;
2+
3+
import org.apache.http.HttpEntity;
4+
import org.apache.http.client.methods.CloseableHttpResponse;
5+
import org.apache.http.client.methods.HttpGet;
6+
import org.apache.http.impl.client.CloseableHttpClient;
7+
import org.apache.http.impl.client.HttpClients;
8+
import org.apache.http.util.EntityUtils;
9+
10+
import java.io.IOException;
11+
12+
/**
13+
* @Author: HuangFu
14+
* @Date: 2021/9/7 22:57
15+
* @Description:
16+
*/
17+
public class HttpClientUtils {
18+
19+
private static HttpClientUtils instance;
20+
21+
public static CloseableHttpClient httpclient = HttpClients.createDefault();
22+
23+
private static class SingletonHolder {
24+
private static HttpClientUtils instance = new HttpClientUtils();
25+
}
26+
27+
public static HttpClientUtils getInstance(){ return SingletonHolder.instance;}
28+
29+
private HttpClientUtils() {
30+
31+
}
32+
33+
// GET 调用
34+
public String getAsString(String url) throws IOException {
35+
HttpGet httpGet = new HttpGet(url);
36+
CloseableHttpResponse response1 = null;
37+
try {
38+
response1 = httpclient.execute(httpGet);
39+
System.out.println(response1.getStatusLine());
40+
HttpEntity entity1 = response1.getEntity();
41+
return EntityUtils.toString(entity1, "UTF-8");
42+
} finally {
43+
if (null != response1) {
44+
response1.close();
45+
}
46+
}
47+
}
48+
49+
public static void main(String[] args) throws Exception {
50+
51+
String url = "https://square.github.io/okhttp/";
52+
String text = HttpClientUtils.getInstance().getAsString(url);
53+
System.out.println("url: " + url + " ; response: \n" + text);
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.huangjs.nio.netty.okhttp;
2+
3+
import okhttp3.OkHttpClient;
4+
import okhttp3.Request;
5+
import okhttp3.Response;
6+
7+
import java.io.IOException;
8+
import java.util.concurrent.TimeUnit;
9+
10+
/**
11+
* @Author: HuangFu
12+
* @Date: 2021/9/7 22:30
13+
* @Description:
14+
*/
15+
public class OkHttpUtils {
16+
// 缓存客户端实例
17+
public OkHttpClient client;
18+
19+
private static class SingletonHolder {
20+
private static OkHttpUtils instance = new OkHttpUtils();
21+
}
22+
23+
private OkHttpUtils(){
24+
OkHttpClient.Builder builder = new OkHttpClient.Builder();
25+
client = builder.connectTimeout(5L, TimeUnit.SECONDS)
26+
.writeTimeout(5L, TimeUnit.SECONDS)
27+
.readTimeout(5L, TimeUnit.SECONDS)
28+
// .sslSocketFactory(sslSocketFactory, trustManager)
29+
.hostnameVerifier((s, sslSession) -> true)
30+
.build();
31+
}
32+
33+
public static OkHttpUtils getInstance() {
34+
return SingletonHolder.instance;
35+
}
36+
37+
// GET 调用
38+
public String getAsString(String url) throws IOException {
39+
Request request = new Request.Builder()
40+
.url(url)
41+
.build();
42+
try (Response response = client.newCall(request).execute()) {
43+
return response.body().string();
44+
}
45+
}
46+
47+
48+
49+
public static void main(String[] args) throws Exception {
50+
51+
String url = "https://square.github.io/okhttp/";
52+
String text = OkHttpUtils.getInstance().getAsString(url);
53+
System.out.println("url: " + url + " ; response: \n" + text);
54+
}
55+
}

‎02nio/nio01/src/main/java/java0/nio01/HttpServer01.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.net.Socket;
77

88
// 单线程的socket程序
9-
public class HttpServer01 {
9+
public class HttpServer01 {
1010
public static void main(String[] args) throws IOException{
1111
ServerSocket serverSocket = new ServerSocket(8801);
1212
while (true) {

‎02nio/nio01/src/main/java/java0/nio01/HttpServer03.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// 创建了一个固定大小的线程池处理请求
1111
public class HttpServer03 {
1212
public static void main(String[] args) throws IOException{
13+
// Runtime.getRuntime().availableProcessors() 获取CPU的核心线程数,存在CPU超核问题?
1314

1415
ExecutorService executorService = Executors.newFixedThreadPool(
1516
Runtime.getRuntime().availableProcessors() + 2);

‎02nio/nio02-work/pom.xml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>nio02-work</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<packaging>jar</packaging>
12+
13+
<name>netty-gateway</name>
14+
<description>Demo project for Spring Boot</description>
15+
16+
<parent>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter-parent</artifactId>
19+
<version>2.0.4.RELEASE</version>
20+
<relativePath/>
21+
</parent>
22+
23+
<properties>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
26+
<java.version>1.8</java.version>
27+
</properties>
28+
29+
<dependencies>
30+
31+
<dependency>
32+
<groupId>io.netty</groupId>
33+
<artifactId>netty-all</artifactId>
34+
<version>4.1.45.Final</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>commons-logging</groupId>
39+
<artifactId>commons-logging</artifactId>
40+
<version>1.2</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.slf4j</groupId>
44+
<artifactId>slf4j-api</artifactId>
45+
<version>1.7.25</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.slf4j</groupId>
49+
<artifactId>slf4j-log4j12</artifactId>
50+
<version>1.7.25</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.httpcomponents</groupId>
54+
<artifactId>httpasyncclient</artifactId>
55+
<version>4.1.4</version>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.projectlombok</groupId>
60+
<artifactId>lombok</artifactId>
61+
</dependency>
62+
63+
<!--
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-web</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-test</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
-->
75+
76+
</dependencies>
77+
78+
<build>
79+
<plugins>
80+
<plugin>
81+
<groupId>org.springframework.boot</groupId>
82+
<artifactId>spring-boot-maven-plugin</artifactId>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
87+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.huangjs.gateway;
2+
3+
import com.huangjs.gateway.inbound.HttpInboundServer;
4+
import lombok.Data;
5+
6+
import java.util.Arrays;
7+
8+
/**
9+
* @Author: HuangFu
10+
* @Date: 2021/9/8 8:23
11+
* @Description:
12+
*/
13+
@Data
14+
public class NettyServerApplication {
15+
16+
17+
public static void main(String[] args) {
18+
19+
String proxyPort = System.getProperty("proxyPort","8888");
20+
String proxyServers = System.getProperty("proxyServers","http://localhost:8801,http://localhost:8802");
21+
22+
int port = Integer.parseInt(proxyPort);
23+
HttpInboundServer httpInboundServer = new HttpInboundServer(port, Arrays.asList(proxyServers));
24+
try {
25+
httpInboundServer.run();
26+
} catch (Exception e) {
27+
e.printStackTrace();
28+
}
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.huangjs.gateway.filter;
2+
3+
import io.netty.channel.ChannelHandlerContext;
4+
import io.netty.handler.codec.http.FullHttpRequest;
5+
6+
public class HeaderHttpRequestFilter implements HttpRequestFilter {
7+
8+
@Override
9+
public void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx) {
10+
fullRequest.headers().set("mao", "soul");
11+
}
12+
}

0 commit comments

Comments
 (0)