From 67a60cd6f8cfca919c715f87fa25c1308da37cda Mon Sep 17 00:00:00 2001 From: jiashunx Date: Thu, 7 Nov 2024 14:40:17 +0800 Subject: [PATCH 01/10] =?UTF-8?q?perf:=20=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=A7=A3=E6=9E=90Decoder=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/MRestServerChannelHandler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelHandler.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelHandler.java index 1e1f143..0e3cedc 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelHandler.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelHandler.java @@ -325,6 +325,19 @@ private MRestRequest parseHttpRequest(ChannelHandlerContext ctx, FullHttpRequest } } decoder.destroy(); + // HttpPostMultipartRequestDecoder decoder = new HttpPostMultipartRequestDecoder(httpRequest); + // List httpDataList = decoder.getBodyHttpDatas(); + // for (InterfaceHttpData httpData : httpDataList) { + // if (httpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { + // Attribute attribute = (Attribute) httpData; + // fileUploadRequest.addAttribute(attribute); + // } + // if (httpData.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload) { + // FileUpload fileUpload = (FileUpload) httpData; + // fileUploadRequest.addFileUploadObj(fileUpload); + // } + // } + // decoder.destroy(); restRequest = fileUploadRequest; } else { byte[] bodyBytes = null; From 2b0928d68e558c3e566214d6cd9e5126ee4fc416 Mon Sep 17 00:00:00 2001 From: jiashunx Date: Thu, 7 Nov 2024 16:35:05 +0800 Subject: [PATCH 02/10] docs: update Version.md --- docs/Version.md | 166 ++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/docs/Version.md b/docs/Version.md index 5bc3a94..cbf1ed0 100644 --- a/docs/Version.md +++ b/docs/Version.md @@ -1,48 +1,48 @@ -

masker-rest版本清单

- -- [V2.2.2.RELEASE](#2.2.2) -- [V2.2.1.RELEASE](#2.2.1) -- [V2.2.0.RELEASE](#2.2.0) -- [V2.1.4.RELEASE](#2.1.4) -- [V2.1.3.RELEASE](#2.1.3) -- [V2.1.2.RELEASE](#2.1.2) -- [V2.1.1.RELEASE](#2.1.1) -- [V2.1.0.RELEASE](#2.1.0) -- [V2.0.0](#2.0.0) -- [V1.7.2](#V1.7.2) -- [V1.7.1.1](#V1.7.1.1) -- [V1.7.1](#V1.7.1) -- [V1.7.0](#V1.7.0) -- [V1.6.8](#V1.6.8) -- [V1.6.7](#V1.6.7) -- [V1.6.6](#V1.6.6) -- [V1.6.5](#V1.6.5) -- [V1.6.4](#V1.6.4) -- [V1.6.3](#V1.6.3) -- [V1.6.2](#V1.6.2) -- [V1.6.1](#V1.6.1) -- [V1.6.0](#V1.6.0) -- [V1.5.0](#V1.5.0) -- [V1.4.10](#V1.4.10) -- [V1.4.9](#V1.4.9) -- [V1.4.8](#V1.4.8) -- [V1.4.7](#V1.4.7) -- [V1.4.6](#V1.4.6) -- [V1.4.5](#V1.4.5) -- [V1.4.4](#V1.4.4) -- [V1.4.3](#V1.4.3) -- [V1.4.2](#V1.4.2) -- [V1.4.1](#V1.4.1) -- [V1.4.0](#V1.4.0) -- [V1.3.0](#V1.3.0) -- [V1.2.1](#V1.2.1) -- [V1.2.0](#V1.2.0) -- [V1.1.1](#V1.1.1) -- [V1.1.0](#V1.1.0) -- [V1.0.0](#V1.0.0) - -

V2.2.2.RELEASE

+

masker-rest版本清单

+ +- [20240824 - 2.2.2.RELEASE](#2.2.2.RELEASE) +- [20240823 - 2.2.1.RELEASE](#2.2.1.RELEASE) +- [20240120 - 2.2.0.RELEASE](#2.2.0.RELEASE) +- [20240113 - 2.1.4.RELEASE](#2.1.4.RELEASE) +- [20240111 - 2.1.3.RELEASE](#2.1.3.RELEASE) +- [20240111 - 2.1.2.RELEASE](#2.1.2.RELEASE) +- [20240111 - 2.1.1.RELEASE](#2.1.1.RELEASE) +- [20231119 - 2.1.0.RELEASE](#2.1.0.RELEASE) +- [20220610 - 2.0.0](#2.0.0) +- [20220510 - 1.7.2](#1.7.2) +- [20220426 - 1.7.1.1](#1.7.1.1) +- [20220115 - 1.7.1](#1.7.1) +- [20211224 - 1.7.0](#1.7.0) +- [20210316 - 1.6.8](#1.6.8) +- [20210315 - 1.6.7](#1.6.7) +- [20210308 - 1.6.6](#1.6.6) +- [20210227 - 1.6.5](#1.6.5) +- [20210108 - 1.6.4](#1.6.4) +- [20210107 - 1.6.3](#1.6.3) +- [20210106 - 1.6.2](#1.6.2) +- [20201229 - 1.6.1](#1.6.1) +- [20201227 - 1.6.0](#1.6.0) +- [20201223 - 1.5.0](#1.5.0) +- [20201223 - 1.4.10](#1.4.10) +- [20201221 - 1.4.9](#1.4.9) +- [20201221 - 1.4.8](#1.4.8) +- [20201218 - 1.4.7](#1.4.7) +- [20201218 - 1.4.6](#1.4.6) +- [20201205 - 1.4.5](#1.4.5) +- [20201205 - 1.4.4](#1.4.4) +- [20201201 - 1.4.3](#1.4.3) +- [20201130 - 1.4.2](#1.4.2) +- [20201127 - 1.4.1](#1.4.1) +- [20201127 - 1.4.0](#1.4.0) +- [20201126 - 1.3.0](#1.3.0) +- [20201120 - 1.2.1](#1.2.1) +- [20201120 - 1.2.0](#1.2.0) +- [20201115 - 1.1.1](#1.1.1) +- [20201115 - 1.1.0](#1.1.0) +- [20201115 - 1.0.0](#1.0.0) + +

20240824 - 2.2.2.RELEASE

- fix: 修正application/x-www-form-urlencoded请求报文解析处理 @@ -50,7 +50,7 @@ - refactor: 请求报错日志输出完整方法调用栈 -

V2.2.1.RELEASE

+

20240823 - 2.2.1.RELEASE

- fix: 修复header方法处理逻辑(移除错误方法) @@ -58,7 +58,7 @@ - refactor: 优化构建配置 -

V2.2.0.RELEASE

+

20240120 - 2.2.0.RELEASE

- fix: 修复查找classpath静态资源文件目录返回所有文件名的缺陷 @@ -70,25 +70,25 @@ - refactor: 优化输出日志 -

V2.1.4.RELEASE

+

20240113 - 2.1.4.RELEASE

- feat: Server支持添加启动成功后的自定义回调 - refactor: 优化Server启动输出日志 -

V2.1.3.RELEASE

+

20240111 - 2.1.3.RELEASE

- fix: Server默认添加context-path为"/"的Context实现 - fix: Context实例初始化时移除添加默认WebsocketContext实例的处理(调整为在初始化Context时添加) -

V2.1.2.RELEASE

+

20240111 - 2.1.2.RELEASE

- fix: Server实例初始化时移除添加默认Context实例的处理(调整为在启动Server时添加) - docs: 样例代码修正 -

V2.1.1.RELEASE

+

20240111 - 2.1.1.RELEASE

- feature: Context增加标记以支持静态资源缓存(默认不缓存静态资源) @@ -100,7 +100,7 @@ - docs: JDK11升级记录内容修正 -

V2.1.0.RELEASE

+

20231119 - 2.1.0.RELEASE

- fix: 增加相关API控制http请求报文体大小(支持设置byte、kb、mb等单位) @@ -110,7 +110,7 @@ - refactor: 优化工程版本依赖控制(依赖版本由父pom定义) -

V2.0.0

+

20220610 - 2.0.0

- feature: 编译构建环境由JDK8升级至JDK11 @@ -118,7 +118,7 @@ - optimizing: 增加MRestFilterChainAdapter用于过滤器调用链自定义处理 -

V1.7.2

+

20220510 - 1.7.2

- fixbug: 修正解压文件后未关闭输入流导致文件占用的缺陷 @@ -128,11 +128,11 @@ - optimizing: 优化及补充部分工具类公共代码 -

V1.7.1.1

+

20220426 - 1.7.1.1

- fixbug: 修正header属性覆盖的缺陷(1.7.0引入) -

V1.7.1

+

20220115 - 1.7.1

- fixbug: 修正filter拦截url不能出现空格的缺陷 @@ -146,7 +146,7 @@ - optimizing: 优化及补充部分工具类公共代码 -

V1.7.0

+

20211224 - 1.7.0

- fixbug: 请求url与context-path相同时应重置请求url为"/" @@ -164,11 +164,11 @@ - optimizing: 文档结构及描述优化, 增加可读性 -

V1.6.8

+

20210316 - 1.6.8

- fixbug: 文件压缩时对文件夹下文件压缩处理修正(仅关闭Entry输出流不关闭整个zip文件输出流) -

V1.6.7

+

20210315 - 1.6.7

- fixbug: 动态Servlet实例缓存实现代码修正 @@ -180,13 +180,13 @@ - optimizing: 路径匹配与精确匹配(带占位符)情况兼容处理(根据url匹配度进行映射优先级选择) -

V1.6.6

+

20210308 - 1.6.6

- feature: servlet映射处理url支持占位符匹配与解析处理,可从MRestRquest对象中获取占位符对应path参数 - feature: 添加 [MRestServletAdapter][8] 类用于servlet请求处理分发 -

V1.6.5

+

20210227 - 1.6.5

- feature: context支持指定默认"/"请求重定向地址 @@ -198,7 +198,7 @@ - feature:使用asm生成字节码(取代反射调用,提高执行效率,参见[ServletHandlerClassGenerator][7])配合 [AbstractRestServlet][3] 实现servlet分发处理 -

V1.6.4

+

20210108 - 1.6.4

- feature: 实现自定义Servlet的注册、分发及处理 @@ -206,7 +206,7 @@ - optimizing: 原有的基于Filter的请求分发处理调整为使用Servlet实现(底层仍然使用Filter进行链式调用) -

V1.6.3

+

20210107 - 1.6.3

- feature: 静态资源Content-Type根据文件名与Content-Type的映射表进行取值及返回 @@ -224,11 +224,11 @@ - fixbug: IOUtils中提供的数据流拷贝方法在执行完成执行数据流关闭操作(修正文件上传时无法删除临时文件的缺陷) -

V1.6.2

+

20210106 - 1.6.2

- fixbug: 修正文件上传处理代码中的文件拷贝逻辑 -

V1.6.1

+

20201229 - 1.6.1

- feature: 静态资源访问支持自定义前缀 @@ -238,13 +238,13 @@ - optimizing: rest server支持设置http content的最大值 -

V1.6.0

+

20201227 - 1.6.0

- feature: 支持发布WebSocket服务及注册相应回调 - feature: 基于自定义WebSocket服务,实现简易聊天室 -

V1.5.0

+

20201223 - 1.5.0

- feature: 单个server支持发布多个context-path的服务 @@ -254,17 +254,17 @@ - optimizing: 补充样例代码 -

V1.4.10

+

20201223 - 1.4.10

- optimizing: 优化补充IOUtils工具类中相应方法. -

V1.4.9

+

20201221 - 1.4.9

- optimizing: 优化序列化相应代码 - optimizing: 补充IOUtils工具类中写文件方法 -

V1.4.8

+

20201221 - 1.4.8

- feature: 对于未指定 "/" 或 "/index.html" 路径映射的服务,输出默认masker-rest主页面 @@ -272,13 +272,13 @@ - optimizing: 优化文件操作代码,增加运行时异常类:FileOperateException -

V1.4.7

+

20201218 - 1.4.7

- feature: 下载文件支持回调(文件下载完成时执行) - fixbug: 修正同一url映射处理对象分别进行映射时报冲突的缺陷 -

V1.4.6

+

20201218 - 1.4.6

- feature: 添加默认的请求异常处理 @@ -288,25 +288,25 @@ - optimizing: jwt处理取消抛出异常 -

V1.4.5

+

20201205 - 1.4.5

- optimizing: 添加IOUtils工具类 - optimizing: response补充write方法 -

V1.4.4

+

20201205 - 1.4.4

- optimizing: jwt默认实现合并至framework工程 - fixbug: 修正未指定context-path时对url的截取异常缺陷 -

V1.4.3

+

20201201 - 1.4.3

- feature: 支持文件下载 - optimizing: 调整server接收的请求body最大size为50MB -

V1.4.2

+

20201130 - 1.4.2

- feature: 支持文件上传(单文件or多文件) @@ -314,17 +314,17 @@ - fixbug: 修正各类handler的分发处理逻辑 -

V1.4.1

+

20201127 - 1.4.1

- optimizing: jwt默认实现调整至独立的masker-rest-jwt工程 - optimizing: 移除冗余maven依赖(commons-codec, commons-lang, commons-io) -

V1.4.0

+

20201127 - 1.4.0

- feature: 支持静态资源处理 -

V1.3.0

+

20201126 - 1.3.0

- feature: request添加context-path字段 @@ -338,11 +338,11 @@ - fixbug: 响应头设置Content-Type报NullPonterException问题解决 -

V1.2.1

+

20201120 - 1.2.1

- feature:server支持自定义context-path -

V1.2.0

+

20201120 - 1.2.0

- feature:请求及响应支持对cookie的处理 @@ -358,17 +358,17 @@ - optimizing:对http请求的响应统一添加server框架名称及版本信息 -

V1.1.1

+

20201115 - 1.1.1

- fixbug:修正启动多个rest server时url映射冲突的错误 -

V1.1.0

+

20201115 - 1.1.0

- feature:添加默认JWT服务端实现 - fixbug:设置响应体write操作仅可执行一次 -

V1.0.0

+

20201115 - 1.0.0

- feature:支持发布rest接口 From a8cbc094da3bb3c9b73d8d18b800c72ae0157b0d Mon Sep 17 00:00:00 2001 From: jiashunx Date: Thu, 7 Nov 2024 20:54:53 +0800 Subject: [PATCH 03/10] =?UTF-8?q?refactor:=20http=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=BF=E7=A8=8B=E6=B1=A0=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E7=A7=BB=E9=99=A4restpool=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jiashunx/masker/rest/framework/util/MRestThreadFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/util/MRestThreadFactory.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/util/MRestThreadFactory.java index 9fd0062..a3a0fe9 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/util/MRestThreadFactory.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/util/MRestThreadFactory.java @@ -18,7 +18,7 @@ public class MRestThreadFactory implements ThreadFactory { public MRestThreadFactory(MRestNettyThreadType threadType, int listenPort) { SecurityManager s = System.getSecurityManager(); this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); - this.namePrefix = String.format("restpool-%s-%d-thread-", threadType.name(), listenPort); + this.namePrefix = String.format("%s-%d-Thread-", threadType.name(), listenPort); } @Override From 9ee306c810bbc69ebfde66e69a1e04690a24b025 Mon Sep 17 00:00:00 2001 From: jiashunx Date: Fri, 8 Nov 2024 10:53:52 +0800 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20SSL=E5=8A=9F=E8=83=BD=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../masker/rest/framework/MRestServer.java | 44 ++++++++++++++++++- .../MRestServerChannelInitializer.java | 12 +++++ .../src/main/resources/masker-rest/ssl/ca.crt | 19 ++++++++ .../src/main/resources/masker-rest/ssl/ca.key | 28 ++++++++++++ .../main/resources/masker-rest/ssl/client.crt | 18 ++++++++ .../main/resources/masker-rest/ssl/client.csr | 16 +++++++ .../main/resources/masker-rest/ssl/client.key | 28 ++++++++++++ .../masker-rest/ssl/client_pkcs8.key | 28 ++++++++++++ .../main/resources/masker-rest/ssl/server.crt | 18 ++++++++ .../main/resources/masker-rest/ssl/server.csr | 16 +++++++ .../main/resources/masker-rest/ssl/server.key | 28 ++++++++++++ .../masker-rest/ssl/server_pkcs8.key | 28 ++++++++++++ 12 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/ca.crt create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/ca.key create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.crt create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.csr create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.key create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client_pkcs8.key create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.crt create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.csr create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.key create mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server_pkcs8.key diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java index 48897bf..77a6b19 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java @@ -18,9 +18,13 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; +import io.netty.handler.ssl.ClientAuth; +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -50,6 +54,16 @@ public class MRestServer { */ private int httpContentMaxByteSize; + /** + * 是否开启Https + */ + private boolean sslEnabled; + + /** + * SSL配置 + */ + private SslContext sslContext; + private final Map contextMap = new ConcurrentHashMap<>(); private final Map globalObjects = new ConcurrentHashMap<>(); @@ -172,6 +186,23 @@ public int getHttpContentMaxByteSize() { return this.httpContentMaxByteSize; } + public MRestServer sslEnabled(boolean sslEnabled) { + this.sslEnabled = sslEnabled; + return this; + } + + public boolean isSslEnabled() { + return this.sslEnabled; + } + + public SslContext getSslContext() { + return sslContext; + } + + public void setSslContext(SslContext sslContext) { + this.sslContext = sslContext; + } + public MRestServer connectionKeepAlive(boolean connectionKeepAlive) { this.connectionKeepAlive = connectionKeepAlive; return this; @@ -267,10 +298,21 @@ public synchronized MRestServer start() throws MRestServerInitializeException { bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); + SslContext sslContext = null; + if (this.isSslEnabled() || this.sslContext != null) { + sslContext = this.sslContext; + if (sslContext == null) { + try (InputStream serverCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server.crt"); + InputStream serverKey = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server_pkcs8.key"); + InputStream caCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/ca.crt");) { + sslContext = SslContextBuilder.forServer(serverCert, serverKey).trustManager(caCert).clientAuth(ClientAuth.REQUIRE).build(); + } + } + } bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new MRestServerChannelInitializer(this)); + .childHandler(new MRestServerChannelInitializer(this, sslContext)); serverChannel = bootstrap.bind(listenPort).sync().channel(); logger.info("{} started", getServerDesc()); AtomicReference serverChannelRef = new AtomicReference<>(serverChannel); diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java index 6c79c9e..e42b2bb 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java @@ -7,6 +7,8 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.HttpServerExpectContinueHandler; +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslHandler; import io.netty.handler.stream.ChunkedWriteHandler; import java.util.Objects; @@ -18,13 +20,23 @@ public class MRestServerChannelInitializer extends ChannelInitializer Date: Tue, 12 Nov 2024 08:52:28 +0800 Subject: [PATCH 05/10] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96SslContext?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../masker/rest/framework/MRestServer.java | 33 ++++++++++++------- .../MRestServerChannelInitializer.java | 10 ++---- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java index 77a6b19..85ee938 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java @@ -251,6 +251,24 @@ public void checkServerState() throws MRestServerInitializeException { } } + private synchronized void initSslContext() throws MRestServerInitializeException { + if (this.isSslEnabled() || this.sslContext != null) { + SslContext sslContext = this.sslContext; + if (sslContext == null) { + logger.info("{} 未指定SslContext, 加载默认SSL配置", getServerDesc()); + try (InputStream serverCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server.crt"); + InputStream serverKey = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server_pkcs8.key"); + InputStream caCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/ca.crt");) { + sslContext = SslContextBuilder.forServer(serverCert, serverKey).trustManager(caCert).clientAuth(ClientAuth.REQUIRE).build(); + } catch (Throwable throwable) { + throw new MRestServerInitializeException("SslContext initialize failed", throwable); + } + } + this.sslEnabled = true; + this.sslContext = sslContext; + } + } + public synchronized MRestServer shutdown() { if (!started) { throw new MRestServerCloseException(String.format("%s has not been initialized", getServerDesc())); @@ -279,6 +297,8 @@ public synchronized MRestServer start() throws MRestServerInitializeException { try { // 检查Server状态 checkServerState(); + // 初始化SslContext + initSslContext(); // 添加默认Context if (getContext(Constants.DEFAULT_CONTEXT_PATH) == null) { contextMap.put(Constants.DEFAULT_CONTEXT_PATH, new MRestContext(this, Constants.DEFAULT_CONTEXT_PATH)); @@ -298,21 +318,10 @@ public synchronized MRestServer start() throws MRestServerInitializeException { bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); - SslContext sslContext = null; - if (this.isSslEnabled() || this.sslContext != null) { - sslContext = this.sslContext; - if (sslContext == null) { - try (InputStream serverCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server.crt"); - InputStream serverKey = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server_pkcs8.key"); - InputStream caCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/ca.crt");) { - sslContext = SslContextBuilder.forServer(serverCert, serverKey).trustManager(caCert).clientAuth(ClientAuth.REQUIRE).build(); - } - } - } bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new MRestServerChannelInitializer(this, sslContext)); + .childHandler(new MRestServerChannelInitializer(this)); serverChannel = bootstrap.bind(listenPort).sync().channel(); logger.info("{} started", getServerDesc()); AtomicReference serverChannelRef = new AtomicReference<>(serverChannel); diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java index e42b2bb..69782c4 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java @@ -20,21 +20,15 @@ public class MRestServerChannelInitializer extends ChannelInitializer Date: Tue, 12 Nov 2024 21:08:15 +0800 Subject: [PATCH 06/10] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8Netty?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E7=9A=84=E8=AF=81=E4=B9=A6=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=95=B0=E5=AD=97=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../masker/rest/framework/MRestServer.java | 27 +++++++++++++----- .../MRestServerChannelInitializer.java | 8 ++++-- .../src/main/resources/masker-rest/ssl/ca.crt | 19 ------------- .../src/main/resources/masker-rest/ssl/ca.key | 28 ------------------- .../main/resources/masker-rest/ssl/client.crt | 18 ------------ .../main/resources/masker-rest/ssl/client.csr | 16 ----------- .../main/resources/masker-rest/ssl/client.key | 28 ------------------- .../masker-rest/ssl/client_pkcs8.key | 28 ------------------- .../main/resources/masker-rest/ssl/server.crt | 18 ------------ .../main/resources/masker-rest/ssl/server.csr | 16 ----------- .../main/resources/masker-rest/ssl/server.key | 28 ------------------- .../masker-rest/ssl/server_pkcs8.key | 28 ------------------- 12 files changed, 25 insertions(+), 237 deletions(-) delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/ca.crt delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/ca.key delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.crt delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.csr delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client.key delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/client_pkcs8.key delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.crt delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.csr delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server.key delete mode 100644 masker-rest-framework/src/main/resources/masker-rest/ssl/server_pkcs8.key diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java index 85ee938..daddf10 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java @@ -18,13 +18,12 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.netty.handler.ssl.ClientAuth; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; +import io.netty.handler.ssl.util.SelfSignedCertificate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -64,6 +63,11 @@ public class MRestServer { */ private SslContext sslContext; + /** + * SSL是否开启客户端验证 + */ + private boolean sslNeedClientAuth; + private final Map contextMap = new ConcurrentHashMap<>(); private final Map globalObjects = new ConcurrentHashMap<>(); @@ -199,8 +203,18 @@ public SslContext getSslContext() { return sslContext; } - public void setSslContext(SslContext sslContext) { + public MRestServer sslContext(SslContext sslContext) { this.sslContext = sslContext; + return this; + } + + public boolean isSslNeedClientAuth() { + return sslNeedClientAuth; + } + + public MRestServer sslNeedClientAuth(boolean sslNeedClientAuth) { + this.sslNeedClientAuth = sslNeedClientAuth; + return this; } public MRestServer connectionKeepAlive(boolean connectionKeepAlive) { @@ -256,10 +270,9 @@ private synchronized void initSslContext() throws MRestServerInitializeException SslContext sslContext = this.sslContext; if (sslContext == null) { logger.info("{} 未指定SslContext, 加载默认SSL配置", getServerDesc()); - try (InputStream serverCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server.crt"); - InputStream serverKey = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/server_pkcs8.key"); - InputStream caCert = MRestServer.class.getClassLoader().getResourceAsStream("masker-rest/ssl/ca.crt");) { - sslContext = SslContextBuilder.forServer(serverCert, serverKey).trustManager(caCert).clientAuth(ClientAuth.REQUIRE).build(); + try { + SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate(); + sslContext = SslContextBuilder.forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey()).build(); } catch (Throwable throwable) { throw new MRestServerInitializeException("SslContext initialize failed", throwable); } diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java index 69782c4..3106c5e 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/handler/MRestServerChannelInitializer.java @@ -7,10 +7,10 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.HttpServerExpectContinueHandler; -import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslHandler; import io.netty.handler.stream.ChunkedWriteHandler; +import javax.net.ssl.SSLEngine; import java.util.Objects; /** @@ -28,8 +28,10 @@ public MRestServerChannelInitializer(MRestServer restServer) { protected void initChannel(SocketChannel socketChannel) throws Exception { ChannelPipeline pipeline = socketChannel.pipeline(); if (this.restServer.isSslEnabled()) { - SslContext sslContext = this.restServer.getSslContext(); - pipeline.addFirst("ssl", new SslHandler(sslContext.newEngine(socketChannel.alloc()))); + SSLEngine sslEngine = this.restServer.getSslContext().newEngine(socketChannel.alloc()); + sslEngine.setUseClientMode(false); + sslEngine.setNeedClientAuth(this.restServer.isSslNeedClientAuth()); + pipeline.addFirst("ssl", new SslHandler(sslEngine)); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new ChunkedWriteHandler()); diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.crt b/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.crt deleted file mode 100644 index e36754e..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.crt +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDCTCCAfGgAwIBAgIUFUrtr5FcbqEIVSG1a2Wzw0QPfygwDQYJKoZIhvcNAQEL -BQAwEzERMA8GA1UEAwwId2UtYXMtY2EwIBcNMjQxMTA4MDE0MDU4WhgPMjEyNDEw -MTUwMTQwNThaMBMxETAPBgNVBAMMCHdlLWFzLWNhMIIBIjANBgkqhkiG9w0BAQEF -AAOCAQ8AMIIBCgKCAQEAx5J8SLlhgLCnlJpC3Cc2g2pABaiMW+46s1lg7jqbFR46 -B0xNP6FHBSQYnfxRhJfzvOthgWb9mbSeJso2lrfvyFEq7hEqcM4Fds8/Ic9zO6JI -qiuWCLUfPjpbF0gdx8fa2BA5bhTpEwo+c31da0u2Xgcv3NWoNkaKqBosniDbsUR/ -61PImheAri4LXljdLVg9owLf9o7u81pylf1E1oo9LFgT4F4cmAc3BSoItyRgKO8B -LSXkchrvpOEkOjgnW8MmKWuNlPlj7BFzygJ/0ep+hROEcHijOSeXvwD/IbZhJZM7 -NKbRAnFISi4ZdbnJvYynPqMxzuDp54Mi9JY16iuf5wIDAQABo1MwUTAdBgNVHQ4E -FgQU+6OlMctyh/Vy1GYVBGVspaO4EMkwHwYDVR0jBBgwFoAU+6OlMctyh/Vy1GYV -BGVspaO4EMkwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAj6xb -+xLD13h5A3UuSlXrDM+feeJKsx7sqjL06SBB7rbjMh5i42Yt58SHddS2lmpNAZpm -bXXoGQF8Aap45It5nZurBm/5LkDpy23KJK4kHEdRw3XEdPurb01miM/jLb8XxxLS -AE821aUZ4EuYX1aGsus1YYMtQPvVOAIjCIKFIsLKLvoHmYcsqrR8i9xLW55wOWl2 -j2s/DQC+2P7koWo493LVAtEfiMfQ+lPOSD10dk3bAxldp+7KKukMIRnOxEASSAbh -Ueqp7BYfK2DzD4p7azVRdXN6teYc9TUr1v7KCJfpLsB5ZwFb+1uWclpR3fsJNJSr -ZydLPQlnEP067CtEGA== ------END CERTIFICATE----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.key b/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.key deleted file mode 100644 index f8fea70..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/ca.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHknxIuWGAsKeU -mkLcJzaDakAFqIxb7jqzWWDuOpsVHjoHTE0/oUcFJBid/FGEl/O862GBZv2ZtJ4m -yjaWt+/IUSruESpwzgV2zz8hz3M7okiqK5YItR8+OlsXSB3Hx9rYEDluFOkTCj5z -fV1rS7ZeBy/c1ag2RoqoGiyeINuxRH/rU8iaF4CuLgteWN0tWD2jAt/2ju7zWnKV -/UTWij0sWBPgXhyYBzcFKgi3JGAo7wEtJeRyGu+k4SQ6OCdbwyYpa42U+WPsEXPK -An/R6n6FE4RweKM5J5e/AP8htmElkzs0ptECcUhKLhl1ucm9jKc+ozHO4OnngyL0 -ljXqK5/nAgMBAAECggEARZH9HWTyZmguoxD7ib9ps3oQg2h0NX/gmrDnp2Rqt3vo -Aq9IpovUNCiXJEvXJv/JiewL+44pjbF3CFKpoPTR8+THsGHvh49qPDaW7XRh2UID -Tr8O+E4bbBfvtTgAmapD0domCwfjEC4cAyqKrGKiWjjrKHKaxwDkSSGGuEEAFNUM -i8bijXP1T/VbKolmT8dtJIuK8zbe3CriKJKDlKFyWWPwcPEUuje5zvp+oqW7iJK+ -SaSbqMep2vzAlGApplN96EQI6qkcTJ937PETUQhf0ZXGsMrQuJE98xc81EfMYSVW -DNQsEiedFb4JxjyhMIJ3vSyBxoigUddByPl2+PQ4YQKBgQDp7VTn9ro8xOPzTC9c -kFyNxe7tLEBFFeV3gFqzNq24yDYrV/5ltewTPki3ZZNg/Nh/ovuZa1lcdRCtBnc5 -nryoIfRsapd1a4H+Bb1mK2VIBBJ+dclUY/bVt3J32JvHLQ6thgWTODymbfFx08un -mZENX5j7qHYn9JCgyTx8P0VpGQKBgQDaZ0ncWpcfKIaLzVqvU6hUlY6WLgm0TANP -FjXOkcDfndwZpchJl88ILl7Supou53CtjOlmGwuuRjfrWGjae1730BaunZMLryfC -Lu9JLs3+eiDdvskysQrD/3m7ZXgXqb8fSLmRzgTcVm5eHyKxg0zh+KFijo5b6CZk -2m7b/xVw/wKBgQDbtc+TdwcA4KSA9UNemzBy8D8yf+d1e9VkYifOP0L3VQSbvS/x -c+bhRBSkPEEqTRFDAF9zf4IU9tbMzE/azJ7BA/NAiPTskicr4VQ8y/F6rGh6YkLQ -gntpy701lzro3gb1L/W4io9cedLWaGjVZ8T3XJyhcV5YtLnKanfm8r5MsQKBgHwp -wFnfvo5eMa+E/YszWj1MERXb8nRnynHJxKk9P5NhYWHLWAROo8qY4huXLlSACxT/ -SSldMtTO4rePOX0MKj9kM6DtwE0iNM42dJ78VuvXbpvh/OwurlojAYfB9fYt8JPO -eoEjyKujD3e+57BXXvwQp18qgFBLuJgZfnDfocbtAoGAGTokXp5P1hkMGuvyVnuC -DdSPfvRNJ3V7VymQOQR3uVdA1qUtbHRZU4XHVQwNkAmLbw0JMgYrRj4kM4XR6q3Q -Q7bU+5PpkdexcTG7ux5eLcA3+1hngU2OBB/2k/ERsWnnkvTBWdA1SYSqjIW6Tipo -9U0/OVA2Osi8jnYIGY5EL1I= ------END PRIVATE KEY----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.crt b/masker-rest-framework/src/main/resources/masker-rest/ssl/client.crt deleted file mode 100644 index 74a1d15..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.crt +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC+TCCAeGgAwIBAgIUKXy91o+1YrDLBY5Jdj1LikjQJ2QwDQYJKoZIhvcNAQEL -BQAwEzERMA8GA1UEAwwId2UtYXMtY2EwIBcNMjQxMTA4MDI0NzAwWhgPMjEyNDEw -MTUwMjQ3MDBaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEB -BQADggEPADCCAQoCggEBAJDsg0VPQNi9xDzg0imMT4kufZLzzmjOsB7oq4P7KJUU -QuX5spFdA7OqWx1wuaOtmQs6G1QbEE5/7qrkdEXxBpMxBIRuoQiaGCz9eWiMh7h1 -KdMX4bwDNpXJHeKUdiWHzqBta7hVIzPF98eyDllR++6+z3BgUcGPOlZEF2HP5FnJ -zHUOH/rSFDQhr3AHxIaYLsqq8bUeaIlLiUJKD6X6QHXyVknpACJKm4qOzmlMBW2/ -yQ4GBuihWZr7QISE64a+IUMr0fXsTtJH9XX4g1kWYliBiIVbOczDnEv9YpBZ4fYA -Lqud09GZRwOzrJk72WLzqCA7MpU/pm4AnUH/1ElOgq0CAwEAAaNCMEAwHQYDVR0O -BBYEFLDrRS2S4Ee2WGlQTylpj4zTyCqVMB8GA1UdIwQYMBaAFPujpTHLcof1ctRm -FQRlbKWjuBDJMA0GCSqGSIb3DQEBCwUAA4IBAQAFyIN4mr69lfD3S+Dx+yhAdOeP -1UWStlV4LW9OeYXdX0BqpVKvjI8TRWeHTkIuiNO3jnFC2NF4Fo/4O+tttcyLBf65 -N8TyIU5AeGulox/BguVB3V7nobRIKcHv6yIVVqlQ+qzg8e9v1paDahyg62WU95sc -REMgXBSObNkxPIPEI28p5W6WY1qKEv1+8mPI66FjQezuY6bsFiYq1LzSSNczLvlH -CYwikGY/21RfBd6iQ/6v6oM2XebKY5iFSI9R9NomusuP2AxzgWCAndsmJ9iFZFJc -Sou8xIlvUG1CP60jlYv98exr0HJDBjbOUXbmHGPS+gs3y0s7eJkunlYKCRYL ------END CERTIFICATE----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.csr b/masker-rest-framework/src/main/resources/masker-rest/ssl/client.csr deleted file mode 100644 index 32ec1bf..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.csr +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIIChjCCAW4CAQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0B -AQEFAAOCAQ8AMIIBCgKCAQEAkOyDRU9A2L3EPODSKYxPiS59kvPOaM6wHuirg/so -lRRC5fmykV0Ds6pbHXC5o62ZCzobVBsQTn/uquR0RfEGkzEEhG6hCJoYLP15aIyH -uHUp0xfhvAM2lckd4pR2JYfOoG1ruFUjM8X3x7IOWVH77r7PcGBRwY86VkQXYc/k -WcnMdQ4f+tIUNCGvcAfEhpguyqrxtR5oiUuJQkoPpfpAdfJWSekAIkqbio7OaUwF -bb/JDgYG6KFZmvtAhITrhr4hQyvR9exO0kf1dfiDWRZiWIGIhVs5zMOcS/1ikFnh -9gAuq53T0ZlHA7OsmTvZYvOoIDsylT+mbgCdQf/USU6CrQIDAQABoC0wKwYJKoZI -hvcNAQkOMR4wHDAaBgNVHREEEzARgglsb2NhbGhvc3SHBH8AAAEwDQYJKoZIhvcN -AQELBQADggEBACMqTaMMIHCF+G4F6T2ht9dNtE35deA/IFif85N1KefgejKApXbA -ayFROPaJcUa/MX0BueqBqX6ScW0dKLc6jQPVpu3KaaEGKgHQ14ov9ug4kz6XHyDQ -WBl66aX0ELyTeAKoTbKA7zK34Q+ErdCTbtJ0U7kC2qjA4F/lF0qINYqXDOe1lIql -V7uCBVTZLKPV/ARGTtjoH/HLvX8QkUr2O/UUaL6qtf90Y9QXP3M5rM8iefmX6yuy -sG99/HPC5bW8XXav0twuhSH28pLXgvth5603aESzMYcnUCM9bago+KmFTUvynawS -fYT5Z/VvAQ7QzIoLjSwcKwsQAGJxgu8eWYU= ------END CERTIFICATE REQUEST----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.key b/masker-rest-framework/src/main/resources/masker-rest/ssl/client.key deleted file mode 100644 index 5d47612..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/client.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCQ7INFT0DYvcQ8 -4NIpjE+JLn2S885ozrAe6KuD+yiVFELl+bKRXQOzqlsdcLmjrZkLOhtUGxBOf+6q -5HRF8QaTMQSEbqEImhgs/XlojIe4dSnTF+G8AzaVyR3ilHYlh86gbWu4VSMzxffH -sg5ZUfvuvs9wYFHBjzpWRBdhz+RZycx1Dh/60hQ0Ia9wB8SGmC7KqvG1HmiJS4lC -Sg+l+kB18lZJ6QAiSpuKjs5pTAVtv8kOBgbooVma+0CEhOuGviFDK9H17E7SR/V1 -+INZFmJYgYiFWznMw5xL/WKQWeH2AC6rndPRmUcDs6yZO9li86ggOzKVP6ZuAJ1B -/9RJToKtAgMBAAECggEAFmdZtmyVZmw/r/buxlmDL36Duc9S82+Frow4J5kQzFXA -2ciLdbQJZHb2IEuoMcjJG1aKRFWYDxVGkh3rE6ePuqVzQKh8NdY3Mo1PfX1sEHSc -WJ5yg8bYuLh0lEMbLfDGspT3zXFBQI8JdPzuVu849nmCRqm9Ocz92bmBBoVFlH5F -kkvg4bVwSGiiG7Z9XxFhbE0gVd4Z4TTegWVkR4D6BGu1H+mEqJrvqsh+chx1/PEl -kjlwLH4B79iTpBLowmo1dKUhOLdDRF+Drxsimxf744+Lms54oOugc1ElsaPGjhrx -qIqg4FUiQZRNGztgAAdkPJh+sXfnFnuSgo2gzi0bCQKBgQDCUtK7TWUXDOZba+GZ -ryGx6/6diwQGaKO8aieO08f12v1g5QYWJu1iyLZ0XCeQV6qrY4v2vD3TPl2RhtoO -si27rD/Bwp2yNOBl02AUXDtXGPnufhW0DJPocraP5GR0Vjo6JOsKVtedSVvugwzR -5nfEpkvc1hv7l6mrJ7TZuAvkKwKBgQC+695tYU9bpKPBvRR4FtD8YYO7Zt7Osm8J -0WqCP0XG31bkfaqnFefri3sZHR9mtyE7S8v9QfrjFS2oVlyPk9HG996fvoW2rxbe -ucEJzuuLYtF9bs06B2+hRy+4Gnpmr9KhAK+M8kqZ+euPiaWfpjVmjQk17TJPDbpC -FOYbkpOQhwKBgEyMA6b0ndWupy9sF7pKWqOTqwC0OimsHpOh3WNN2X7nfNgmX3dq -bihzmCvOAWfCoOBSnlfbXx9PedxRmqQfXBSJjbPtzeDdI2f5E+fxTQ7KL+nakQIT -0k/GoFOeTFPng5hT4qJ4AwdaVnRl+y7T8mnseAXN8cfxvkxFn+ADt+txAoGAA/e+ -7aMCFTN8u8AENuKygSw9op1msAEBUcDqZ76M4q8tjR4Xd9V6tmh1rHXwex//Ls5K -dP70Cdgc1MzGq600xN/N3qAFA2DsJsDRhDSqrIDnPaYZ2cThywZBtZ/HP28T/4iW -HWXDqyOIg7kmmgTIQ1NXB6ngS8hLQKhSh+wp6O0CgYAcesod5mPq6yoRekitzEJ4 -rHMXnkPeNRQ5UkMMzy1DnNXItksWVwGCOgiYKIghxNQ87LsDLMIn+JwVhtQEdp3b -cRw8YnShDQhYkN1ZobCCi2MP5KeCjrbbwNzuqYxPT0uEfEoFi8ti/7tzCQB2qgq3 -NzogtqO2zuv4GR9GMoiMsA== ------END PRIVATE KEY----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/client_pkcs8.key b/masker-rest-framework/src/main/resources/masker-rest/ssl/client_pkcs8.key deleted file mode 100644 index 5d47612..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/client_pkcs8.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCQ7INFT0DYvcQ8 -4NIpjE+JLn2S885ozrAe6KuD+yiVFELl+bKRXQOzqlsdcLmjrZkLOhtUGxBOf+6q -5HRF8QaTMQSEbqEImhgs/XlojIe4dSnTF+G8AzaVyR3ilHYlh86gbWu4VSMzxffH -sg5ZUfvuvs9wYFHBjzpWRBdhz+RZycx1Dh/60hQ0Ia9wB8SGmC7KqvG1HmiJS4lC -Sg+l+kB18lZJ6QAiSpuKjs5pTAVtv8kOBgbooVma+0CEhOuGviFDK9H17E7SR/V1 -+INZFmJYgYiFWznMw5xL/WKQWeH2AC6rndPRmUcDs6yZO9li86ggOzKVP6ZuAJ1B -/9RJToKtAgMBAAECggEAFmdZtmyVZmw/r/buxlmDL36Duc9S82+Frow4J5kQzFXA -2ciLdbQJZHb2IEuoMcjJG1aKRFWYDxVGkh3rE6ePuqVzQKh8NdY3Mo1PfX1sEHSc -WJ5yg8bYuLh0lEMbLfDGspT3zXFBQI8JdPzuVu849nmCRqm9Ocz92bmBBoVFlH5F -kkvg4bVwSGiiG7Z9XxFhbE0gVd4Z4TTegWVkR4D6BGu1H+mEqJrvqsh+chx1/PEl -kjlwLH4B79iTpBLowmo1dKUhOLdDRF+Drxsimxf744+Lms54oOugc1ElsaPGjhrx -qIqg4FUiQZRNGztgAAdkPJh+sXfnFnuSgo2gzi0bCQKBgQDCUtK7TWUXDOZba+GZ -ryGx6/6diwQGaKO8aieO08f12v1g5QYWJu1iyLZ0XCeQV6qrY4v2vD3TPl2RhtoO -si27rD/Bwp2yNOBl02AUXDtXGPnufhW0DJPocraP5GR0Vjo6JOsKVtedSVvugwzR -5nfEpkvc1hv7l6mrJ7TZuAvkKwKBgQC+695tYU9bpKPBvRR4FtD8YYO7Zt7Osm8J -0WqCP0XG31bkfaqnFefri3sZHR9mtyE7S8v9QfrjFS2oVlyPk9HG996fvoW2rxbe -ucEJzuuLYtF9bs06B2+hRy+4Gnpmr9KhAK+M8kqZ+euPiaWfpjVmjQk17TJPDbpC -FOYbkpOQhwKBgEyMA6b0ndWupy9sF7pKWqOTqwC0OimsHpOh3WNN2X7nfNgmX3dq -bihzmCvOAWfCoOBSnlfbXx9PedxRmqQfXBSJjbPtzeDdI2f5E+fxTQ7KL+nakQIT -0k/GoFOeTFPng5hT4qJ4AwdaVnRl+y7T8mnseAXN8cfxvkxFn+ADt+txAoGAA/e+ -7aMCFTN8u8AENuKygSw9op1msAEBUcDqZ76M4q8tjR4Xd9V6tmh1rHXwex//Ls5K -dP70Cdgc1MzGq600xN/N3qAFA2DsJsDRhDSqrIDnPaYZ2cThywZBtZ/HP28T/4iW -HWXDqyOIg7kmmgTIQ1NXB6ngS8hLQKhSh+wp6O0CgYAcesod5mPq6yoRekitzEJ4 -rHMXnkPeNRQ5UkMMzy1DnNXItksWVwGCOgiYKIghxNQ87LsDLMIn+JwVhtQEdp3b -cRw8YnShDQhYkN1ZobCCi2MP5KeCjrbbwNzuqYxPT0uEfEoFi8ti/7tzCQB2qgq3 -NzogtqO2zuv4GR9GMoiMsA== ------END PRIVATE KEY----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.crt b/masker-rest-framework/src/main/resources/masker-rest/ssl/server.crt deleted file mode 100644 index 124072b..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.crt +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC+TCCAeGgAwIBAgIUKXy91o+1YrDLBY5Jdj1LikjQJ2MwDQYJKoZIhvcNAQEL -BQAwEzERMA8GA1UEAwwId2UtYXMtY2EwIBcNMjQxMTA4MDI0NjQxWhgPMjEyNDEw -MTUwMjQ2NDFaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEB -BQADggEPADCCAQoCggEBAMYocNIa3iDwy6ggUzQV2bEPi7dZv5WfVaKRm8jRVe5d -uC8WlgUq2lpRW/ZaO7K0SuRxeRCGrGRvnE6Ox3zDUA+Oo+NcKxUm9lKqzjehRm8i -0bZmtdCLr5W2TB1ofJrr432nKRgfa7QwjAXw28yCO0LqCniAdyJdkASHPKVtuq4c -Nkro5VwCi4OWezW86iYYWIH5YRnmbvy0xctsnASePDymmqlNymNcitDt5kV05e6U -1eSlJH1bqIYltG3euszQPh1Rr5vQtsTe7+ld/ROw4W4jDDj5TbxZr6BphMnIO1Ly -PEPk3ZMWLRchUI9GyeQ+CtxuxOEBDusCThGVVpAaPG8CAwEAAaNCMEAwHQYDVR0O -BBYEFCHHtSR5lmYf4Yrtps5Z6qxyJ8ktMB8GA1UdIwQYMBaAFPujpTHLcof1ctRm -FQRlbKWjuBDJMA0GCSqGSIb3DQEBCwUAA4IBAQCkEFmIqyXYTjbBnzOpC+hsZeZJ -+VCVX+AVjG55X4/NkaRvPS4thgpw/4a7LOFwIKemGVD/z5dIKcNVPVIN/2BTawDS -h4JwdAztaCbDUS2vaPTsXBo96MGZdmpOtXvntlHyXzHXaqPheIyPfTyJ1oPw4yS1 -7Zoa03B59zcAjc695mpeiizVccFoSb0eeWN32cg4BIg43KHKnbIxlPkdIKvtLJuz -IWkl5ndNIgAPQaEJsPCdntbKCBCsYFzg0xQaY3li/zMZFdQe7PSlEPmBjITmyzba -6+R3ASdQSGkylN9B+Rp5vY7MgpHA+TnU26LpTdl2vkt8wB09NJPoPdLvmmJ4 ------END CERTIFICATE----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.csr b/masker-rest-framework/src/main/resources/masker-rest/ssl/server.csr deleted file mode 100644 index df58f8b..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.csr +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIIChjCCAW4CAQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0B -AQEFAAOCAQ8AMIIBCgKCAQEAxihw0hreIPDLqCBTNBXZsQ+Lt1m/lZ9VopGbyNFV -7l24LxaWBSraWlFb9lo7srRK5HF5EIasZG+cTo7HfMNQD46j41wrFSb2UqrON6FG -byLRtma10IuvlbZMHWh8muvjfacpGB9rtDCMBfDbzII7QuoKeIB3Il2QBIc8pW26 -rhw2SujlXAKLg5Z7NbzqJhhYgflhGeZu/LTFy2ycBJ48PKaaqU3KY1yK0O3mRXTl -7pTV5KUkfVuohiW0bd66zNA+HVGvm9C2xN7v6V39E7DhbiMMOPlNvFmvoGmEycg7 -UvI8Q+TdkxYtFyFQj0bJ5D4K3G7E4QEO6wJOEZVWkBo8bwIDAQABoC0wKwYJKoZI -hvcNAQkOMR4wHDAaBgNVHREEEzARgglsb2NhbGhvc3SHBH8AAAEwDQYJKoZIhvcN -AQELBQADggEBAA3sPMOnyqoeZkrpLc3tnntNHKw2g8eXxzA3dyRn3PH3fkCMqTdQ -boKmUp9GciG8iJTmRwlAvU+/mGhQP9Q2g+d8K7Ab5IoTVcdGS9z497pmVq2jr/hS -3WWVL/5CoIelSSZKvRwgoixJ5vKq2S+LJx6r/bEhKY5kNoJINRDp9v1gEIVvA4R/ -5+odmzmEosvCcEP37Hy0HNQpLXqJLBSsIs8LOXxU4GwdX30ZN79UXVvlP+HZaOYi -61MffhaRdVT0odMUvol/AcCVDFMB2OdQw97zZLqP4SoCLMzF6cBrgALD1CrsF3jn -arCIWftuxm5dCROqw+gXRhVNJWGW6/cTotY= ------END CERTIFICATE REQUEST----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.key b/masker-rest-framework/src/main/resources/masker-rest/ssl/server.key deleted file mode 100644 index b134a65..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/server.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDGKHDSGt4g8Muo -IFM0FdmxD4u3Wb+Vn1WikZvI0VXuXbgvFpYFKtpaUVv2WjuytErkcXkQhqxkb5xO -jsd8w1APjqPjXCsVJvZSqs43oUZvItG2ZrXQi6+VtkwdaHya6+N9pykYH2u0MIwF -8NvMgjtC6gp4gHciXZAEhzylbbquHDZK6OVcAouDlns1vOomGFiB+WEZ5m78tMXL -bJwEnjw8ppqpTcpjXIrQ7eZFdOXulNXkpSR9W6iGJbRt3rrM0D4dUa+b0LbE3u/p -Xf0TsOFuIww4+U28Wa+gaYTJyDtS8jxD5N2TFi0XIVCPRsnkPgrcbsThAQ7rAk4R -lVaQGjxvAgMBAAECggEAQICngOz4A3b+hCLJkrnOG+G4lB1lzLmJ8Zo+QJdLxoTB -UKqkeNgjLaUwLzfeGOSxQD1jsCp2cVcXZUb6zrTxGa9Pz9GPwJnnMq+g4uDfgYuv -AhXa9yCRLkWh7yy06uUAL0W7jbuknony+ngVxDNcQQLYF7ORlCEqoR64cg0O6F94 -1eUa47CxIFXDpoXy89A7LHDdGdbxm682dHYyKO1BikUOaRLeiUTV0lt1Zbtvym0y -8Cw0qMe9xYG3BkecvJPLKpC2NLx7/qhfcjl5UFY+3Q5+6SKMZVLhoLWlM86N0zfw -ZooQQ6zVMf/YT3V0E0x/8wfQaiWcc5QUQgYwjGt5QQKBgQD++qMaFekn+z1alQ5f -+oLVEibEoidG+OPgASaj3V12tf+/9qc6efkJTk240ts6MYbinIAQwq4R5Q8V6+CS -gmBX2VUh3ywgFlafGkQuAKrktDT9r8jyMICRGNcCPocPK63QsTdaH5qeLl+1xDJu -sGSIHSvyc7cuzfAmxoWvd1do4QKBgQDG849Vckn0rK+f/oQdBPcZXv98Q0gGazlJ -G4rzcqIZeRWbnH6zxD5gUL/ijVzY/irqFdB3PCSvArphHWld6tZWDhVJ7jIGqnKw -qMkBUkUIpp4HJfEcOQsi+XyfZiQTkVb6ISNxEehv/60XtiqAj+Vsh0VfZ9QDsRxh -Lk2mnAG/TwKBgQCqr19FlAtLL10H6SYBS/IO7iKzmJTQZsYsarjSEtqBIB4/A784 -XvQ9rYRLyCLnFsZjpj34ekoKQprRot/nU41o4Vyi2wFvzWRZBz1CykGb7aJXfDf5 -IEzAVK+BmhfRKP0m6arTErrvTr3VMKxN+pihoV2M5LdohoVPf694IVyLIQKBgERL -XXumdO6xzMPuWamgh7ZE3wzoB7R0YEDRXJx/UFfQMfOt/+xzxDnJ3mTFxAaVEWQz -wtD7a1hMZnBp6T6dG6CEyxgK1U9meWJdPkre0+XJVFv90Uuv5TvHStlo9Z9l9+Z7 -M7BfxluT9/Y4yVRCkS31LYI3oRb3WFefznYP/aWPAoGBAIIQ1d2DxKoSTTVIeenz -t3/MBzYNexzKciUUNOV6d9AvAnPPkeuWYERAgaTf+4qg6aRkswHyAlXAi0/93x+K -sJB3GogOhMu8rfGRKCbheSOldoQVDKm6Pmif/NHIDX9NOLRATbf+SVSU5/kkk8FW -aSmugVWuoytBQHorHhS3OIJs ------END PRIVATE KEY----- diff --git a/masker-rest-framework/src/main/resources/masker-rest/ssl/server_pkcs8.key b/masker-rest-framework/src/main/resources/masker-rest/ssl/server_pkcs8.key deleted file mode 100644 index b134a65..0000000 --- a/masker-rest-framework/src/main/resources/masker-rest/ssl/server_pkcs8.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDGKHDSGt4g8Muo -IFM0FdmxD4u3Wb+Vn1WikZvI0VXuXbgvFpYFKtpaUVv2WjuytErkcXkQhqxkb5xO -jsd8w1APjqPjXCsVJvZSqs43oUZvItG2ZrXQi6+VtkwdaHya6+N9pykYH2u0MIwF -8NvMgjtC6gp4gHciXZAEhzylbbquHDZK6OVcAouDlns1vOomGFiB+WEZ5m78tMXL -bJwEnjw8ppqpTcpjXIrQ7eZFdOXulNXkpSR9W6iGJbRt3rrM0D4dUa+b0LbE3u/p -Xf0TsOFuIww4+U28Wa+gaYTJyDtS8jxD5N2TFi0XIVCPRsnkPgrcbsThAQ7rAk4R -lVaQGjxvAgMBAAECggEAQICngOz4A3b+hCLJkrnOG+G4lB1lzLmJ8Zo+QJdLxoTB -UKqkeNgjLaUwLzfeGOSxQD1jsCp2cVcXZUb6zrTxGa9Pz9GPwJnnMq+g4uDfgYuv -AhXa9yCRLkWh7yy06uUAL0W7jbuknony+ngVxDNcQQLYF7ORlCEqoR64cg0O6F94 -1eUa47CxIFXDpoXy89A7LHDdGdbxm682dHYyKO1BikUOaRLeiUTV0lt1Zbtvym0y -8Cw0qMe9xYG3BkecvJPLKpC2NLx7/qhfcjl5UFY+3Q5+6SKMZVLhoLWlM86N0zfw -ZooQQ6zVMf/YT3V0E0x/8wfQaiWcc5QUQgYwjGt5QQKBgQD++qMaFekn+z1alQ5f -+oLVEibEoidG+OPgASaj3V12tf+/9qc6efkJTk240ts6MYbinIAQwq4R5Q8V6+CS -gmBX2VUh3ywgFlafGkQuAKrktDT9r8jyMICRGNcCPocPK63QsTdaH5qeLl+1xDJu -sGSIHSvyc7cuzfAmxoWvd1do4QKBgQDG849Vckn0rK+f/oQdBPcZXv98Q0gGazlJ -G4rzcqIZeRWbnH6zxD5gUL/ijVzY/irqFdB3PCSvArphHWld6tZWDhVJ7jIGqnKw -qMkBUkUIpp4HJfEcOQsi+XyfZiQTkVb6ISNxEehv/60XtiqAj+Vsh0VfZ9QDsRxh -Lk2mnAG/TwKBgQCqr19FlAtLL10H6SYBS/IO7iKzmJTQZsYsarjSEtqBIB4/A784 -XvQ9rYRLyCLnFsZjpj34ekoKQprRot/nU41o4Vyi2wFvzWRZBz1CykGb7aJXfDf5 -IEzAVK+BmhfRKP0m6arTErrvTr3VMKxN+pihoV2M5LdohoVPf694IVyLIQKBgERL -XXumdO6xzMPuWamgh7ZE3wzoB7R0YEDRXJx/UFfQMfOt/+xzxDnJ3mTFxAaVEWQz -wtD7a1hMZnBp6T6dG6CEyxgK1U9meWJdPkre0+XJVFv90Uuv5TvHStlo9Z9l9+Z7 -M7BfxluT9/Y4yVRCkS31LYI3oRb3WFefznYP/aWPAoGBAIIQ1d2DxKoSTTVIeenz -t3/MBzYNexzKciUUNOV6d9AvAnPPkeuWYERAgaTf+4qg6aRkswHyAlXAi0/93x+K -sJB3GogOhMu8rfGRKCbheSOldoQVDKm6Pmif/NHIDX9NOLRATbf+SVSU5/kkk8FW -aSmugVWuoytBQHorHhS3OIJs ------END PRIVATE KEY----- From 3e16550de81dd34691690dbceb6cb20fba66d25a Mon Sep 17 00:00:00 2001 From: jiashunx Date: Tue, 12 Nov 2024 22:07:08 +0800 Subject: [PATCH 07/10] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0https=E6=A0=B7?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/UserGuide.md | 33 +++++++++++++++++-- .../masker/rest/demo/MaskerRestMain.java | 21 ++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index bf75f76..7764ae3 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -4,7 +4,7 @@ - [0.1、版本清单](#0.2) - [0.3、框架引用](#0.3) - [0.4、框架样例](#0.4) -- [1、masker-rest发布Http服务](#1) +- [1、masker-rest发布Http(s)服务](#1) - [1.1、发布Rest服务](#1.1) - [1.1.1、Get请求处理](#1.1.1) - [1.1.2、Post请求处理](#1.1.2) @@ -21,6 +21,7 @@ - [1.2.1、静态资源绑定](#1.2.1) - [1.2.2、classpath静态资源](#1.2.2) - [1.2.3、磁盘静态资源](#1.2.3) + - [1.3、发布Https服务](#1.3) - [2、masker-rest发布WebSocket服务](#2) - [2.1、发布WebSocket服务](#2.1) - [2.2、WebSocket实现简易聊天室](#2.2) @@ -113,7 +114,7 @@ public class Test { } ``` -

1、masker-rest发布Http服务

+

1、masker-rest发布Http(s)服务

1.1、发布Rest服务

@@ -700,7 +701,35 @@ public class Test { } ``` +

1.3、发布Https服务

+```java +public class Test { + private static final Logger logger = LoggerFactory.getLogger(Test.class); + public static void main(String[] args) { + new MRestServer(10015) + .sslEnabled(true) + .context("/demo") + // "/"扫描classpath: "META-INF/resources/", "resources/", "static/", "public/" + .addDefaultClasspathResource("/") + .addClasspathResource("/html/dist", "dist/") + .addDiskpathResource("/html/dist", "/root/html/") + // https://127.0.0.1:10015/demo/get-html + .get("/get-html", request -> { + return "this is a html page !"; + }, MRestHeaderBuilder.Build("Content-Type", "text/html")) + .post(("/post-form"), request -> { + logger.info("post, form data: {}", request.parseBodyToObj(Vo.class)); + return new HashMap(); + }) + .servlet("/servlet/{name}", (request, response) -> { + response.writeString("/servlet/{name}" + request.getPathVariable("name")); + }) + .getRestServer() + .start(); + } +} +```

2、masker-rest发布WebSocket服务

diff --git a/masker-rest-demo/src/main/java/io/github/jiashunx/masker/rest/demo/MaskerRestMain.java b/masker-rest-demo/src/main/java/io/github/jiashunx/masker/rest/demo/MaskerRestMain.java index c16bbd2..9236513 100644 --- a/masker-rest-demo/src/main/java/io/github/jiashunx/masker/rest/demo/MaskerRestMain.java +++ b/masker-rest-demo/src/main/java/io/github/jiashunx/masker/rest/demo/MaskerRestMain.java @@ -457,6 +457,27 @@ public static void main(String[] args) throws InterruptedException { .getRestServer() .start(); + // 发布HTTPS服务: https://127.0.0.1:10015/demo/get-html + new MRestServer(10015) + .sslEnabled(true) + .context("/demo") + // "/"扫描classpath: "META-INF/resources/", "resources/", "static/", "public/" + .addDefaultClasspathResource("/") + .addClasspathResource("/html/dist", "dist/") + .addDiskpathResource("/html/dist", "/root/html/") + .get("/get-html", request -> { + return "this is a html page !"; + }, MRestHeaderBuilder.Build("Content-Type", "text/html")) + .post(("/post-form"), request -> { + logger.info("post, form data: {}", request.parseBodyToObj(Vo.class)); + return new HashMap(); + }) + .servlet("/servlet/{name}", (request, response) -> { + response.writeString("/servlet/{name}" + request.getPathVariable("name")); + }) + .getRestServer() + .start(); + // 异常测试 new MRestServer(21701) .context() From 5b19056bdfcd792219f40bd15204ecacb756e733 Mon Sep 17 00:00:00 2001 From: jiashunx Date: Wed, 13 Nov 2024 15:32:05 +0800 Subject: [PATCH 08/10] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4server?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/jiashunx/masker/rest/framework/MRestServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java index daddf10..8d4be87 100644 --- a/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java +++ b/masker-rest-framework/src/main/java/io/github/jiashunx/masker/rest/framework/MRestServer.java @@ -320,7 +320,7 @@ public synchronized MRestServer start() throws MRestServerInitializeException { contextMap.forEach((key, restContext) -> { restContext.initResources(); }); - logger.info("{} starting, Context: {}", getServerDesc(), getContextList()); + logger.info("{} Context List: {}", getServerDesc(), getContextList()); // Context初始化 contextMap.forEach((key, restContext) -> { restContext.init(); @@ -336,7 +336,7 @@ public synchronized MRestServer start() throws MRestServerInitializeException { .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new MRestServerChannelInitializer(this)); serverChannel = bootstrap.bind(listenPort).sync().channel(); - logger.info("{} started", getServerDesc()); + logger.info("{} started on port {} (http{})", getServerDesc(), getListenPort(), isSslEnabled() ? "s" : ""); AtomicReference serverChannelRef = new AtomicReference<>(serverChannel); final Thread syncThread = new Thread(() -> { try { From edbf435f58ae8dc1b8e2f9947a97f8c92890dd00 Mon Sep 17 00:00:00 2001 From: jiashunx Date: Wed, 13 Nov 2024 15:46:35 +0800 Subject: [PATCH 09/10] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B02.3.0.RELEASE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/Version.md | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b985f57..c94a781 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - Websocket Server Framework - 复用Http服务器端口发布Websocket服务(websocket服务可根据url进行请求分发) -- 版本清单(最新版本: 2.2.2.RELEASE): +- 版本清单(最新版本: 2.3.0.RELEASE): - 参见: [Version.md][0] diff --git a/docs/Version.md b/docs/Version.md index cbf1ed0..35ef49a 100644 --- a/docs/Version.md +++ b/docs/Version.md @@ -1,6 +1,7 @@

masker-rest版本清单

+- [20241113 - 2.3.0.RELEASE](#2.3.0.RELEASE) - [20240824 - 2.2.2.RELEASE](#2.2.2.RELEASE) - [20240823 - 2.2.1.RELEASE](#2.2.1.RELEASE) - [20240120 - 2.2.0.RELEASE](#2.2.0.RELEASE) @@ -42,6 +43,16 @@ - [20201115 - 1.1.0](#1.1.0) - [20201115 - 1.0.0](#1.0.0) +

20241113 - 2.3.0.RELEASE

+ +- feat: 支持发布https服务(使用Netty自带的证书工具生成数字证书) + +- refactor: 优化http处理线程池线程名称 + +- refactor: 调整版本发布日志 + +- refactor: 调整Server启动输出日志 +

20240824 - 2.2.2.RELEASE

- fix: 修正application/x-www-form-urlencoded请求报文解析处理 From e134bf9c9982744506099df2cf1866eb297325d6 Mon Sep 17 00:00:00 2001 From: jiashunx Date: Wed, 13 Nov 2024 15:48:10 +0800 Subject: [PATCH 10/10] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B02.3.0.RELEASE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- masker-rest-demo/pom.xml | 2 +- masker-rest-framework/pom.xml | 2 +- masker-rest-jjwt/pom.xml | 2 +- masker-rest-rsa/pom.xml | 2 +- pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/masker-rest-demo/pom.xml b/masker-rest-demo/pom.xml index ca90ea4..762cc46 100644 --- a/masker-rest-demo/pom.xml +++ b/masker-rest-demo/pom.xml @@ -3,7 +3,7 @@ io.github.jiashunx masker-rest - x.y.z-SNAPSHOT + 2.3.0.RELEASE ../pom.xml masker-rest-demo diff --git a/masker-rest-framework/pom.xml b/masker-rest-framework/pom.xml index f9cd7e6..09ac899 100644 --- a/masker-rest-framework/pom.xml +++ b/masker-rest-framework/pom.xml @@ -3,7 +3,7 @@ io.github.jiashunx masker-rest - x.y.z-SNAPSHOT + 2.3.0.RELEASE ../pom.xml masker-rest-framework diff --git a/masker-rest-jjwt/pom.xml b/masker-rest-jjwt/pom.xml index 2b3d9bf..e12bb23 100644 --- a/masker-rest-jjwt/pom.xml +++ b/masker-rest-jjwt/pom.xml @@ -3,7 +3,7 @@ io.github.jiashunx masker-rest - x.y.z-SNAPSHOT + 2.3.0.RELEASE ../pom.xml masker-rest-jjwt diff --git a/masker-rest-rsa/pom.xml b/masker-rest-rsa/pom.xml index 6deca31..f74d2e8 100644 --- a/masker-rest-rsa/pom.xml +++ b/masker-rest-rsa/pom.xml @@ -3,7 +3,7 @@ io.github.jiashunx masker-rest - x.y.z-SNAPSHOT + 2.3.0.RELEASE ../pom.xml masker-rest-rsa diff --git a/pom.xml b/pom.xml index c18a035..28a230c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ masker-rest masker-rest pom - x.y.z-SNAPSHOT + 2.3.0.RELEASE UTF-8 UTF-8