Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solon-boot-tomcat添加https支持 #328

Open
looly opened this issue Dec 24, 2024 · 1 comment
Open

solon-boot-tomcat添加https支持 #328

looly opened this issue Dec 24, 2024 · 1 comment

Comments

@looly
Copy link

looly commented Dec 24, 2024

源码在这里:
https://github.com/opensolon/solon/blob/main/__hatch/solon-boot-tomcat/src/main/java/org/noear/solon/boot/tomcat/TomcatServerBase.java

现在不支持HTTPS,Hutool在封装简单的Server门面时,做了实现,可以参考:

https://github.com/dromara/hutool/blob/v6-dev/hutool-http/src/main/java/org/dromara/hutool/http/server/engine/tomcat/TomcatEngine.java#L125

懒得提PR了,哈哈,做个参考吧。

Hutool中所有HTTPS的启用都是基于javax.net.ssl.SSLContext的,在配置文件中,如果用户传入了这个对象,表示要启用HTTPS,则核心代码为:

final Http11NioProtocol protocol = new Http11NioProtocol();

protocol.setSSLEnabled(true);
protocol.setSecure(true);
protocol.addSslHostConfig(createSSLHostConfig(sslContext));

createSSLHostConfig就是将SSLContext构建为SSLHostConfig
tomcat本身提供了一个org.apache.tomcat.util.net.SSLContext,因此我弄了一个JSSESSLContext将javax的转为tomcat的(PS:tomcat真恶心……),tomcat本身也提供了一个org.apache.tomcat.util.net.jsse.JSSESSLContext,不能传SSLContext,只能传KeyManager之类的,因此我自己写了一个……

希望对你有用。

PS:Hutool-6.x在http模块中提供了一个简单的ServerEngine接口,用于提供http服务器的门面,类似solon中的ServerLifecycle,都是为了简化服务创建和启动差异,也参考了solon的很多实现,在此感谢~~

@noear
Copy link
Member

noear commented Dec 25, 2024

感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants