
Linuxeden 开源社区 --
Firefly v4.6.0 新增了 OpenSSL 引擎支持,命名参数 SQL API,HTTP 客户端连接泄露追踪,并修复了一些 bug。完善了 HTTP 服务器与客户端 Kotlin 版 ,数据库访问 Kotlin 版 以及 SSL/TLS 配置 文档。
使用 OpenSSL 引擎
现在 Firefly 支持 JDK SSL 引擎和 OpenSSL 引擎作为网络安全层。JDK SSL 引擎是默认的。JDK8 的 SSL 引擎不支持 ALPN(应用层协议协商),HTTP2 协议在 TLS 握手中需要 ALPN 的支持。如果您使用 JDK8 SSL 引擎则需要添加 VM 参数来设置一个引导程序 alpn-boot.jar(具体情况参考 SSL/TLS 配置 文档)。如果您在某些情况下无法修改 VM 参数,我们提供了支持 ALPN 的 OpenSSL 引擎支持,不需要任何 VM 设置就能启用 HTTP2 协议。例如:
public class OpensslHTTPsServer {
public static void main(String[] args) {
$.httpsServer(new DefaultOpenSSLSecureSessionFactory())
.router().get("/").handler(ctx -> ctx.end("hello world!"))
.listen("localhost", 8081);
}
}
访问 https://localhost:8081 ,浏览器将显示
hello world!
您也可以使用自己的证书文件,例如:
public class OpensslFileCertHTTPsServer {
public static void main(String[] args) throws IOException {
ClassPathResource certificate = new ClassPathResource("/myCA.cer");
ClassPathResource privateKey = new ClassPathResource("/myCAPriv8.key");
SecureSessionFactory factory = new FileCertificateOpenSSLSecureSessionFactory(
certificate.getFile().getAbsolutePath(),
privateKey.getFile().getAbsolutePath());
$.httpsServer(factory)
.router().get("/").handler(ctx -> ctx.end("hello world!"))
.listen("localhost", 8081);
}
}
注意:OpenSSL 私钥文件必须使用 PKCS8 格式,您可以使用“openssl pkcs8”命令进行格式转换,例如:
openssl genrsa -out myCA.key 2048 openssl req -new -x509 -key myCA.key -out myCA.cer -days 36500 openssl pkcs8 -topk8 -inform PEM -outform PEM -in myCA.key -out myCAPriv8.key -nocrypt
命名参数 SQL API
命名参数 SQL 增加了代码的可读性。当我们使用命名参数 SQL 的时候,可以使用 map 或者 javabean 来替换占位符。
Java 版例子:
@Test
public void testInsert() {
String sql = "insert into `test`.`user`(pt_name, pt_password) values(?,?)";
Mono<Long> newUserId = exec(c -> c.insert(sql, "hello user", "hello user pwd"));
StepVerifier.create(newUserId).expectNext(size + 1L).verifyComplete();
String namedSql = "insert into `test`.`user`(pt_name, pt_password) values(:name, :password)";
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("name", "hello user1");
paramMap.put("password", "hello user pwd1");
newUserId = exec(c -> c.namedInsert(namedSql, paramMap));
StepVerifier.create(newUserId).expectNext(size + 2L).verifyComplete();
User user = new User();
user.setName("hello user2");
user.setPassword("hello user pwd2");
newUserId = exec(c -> c.namedInsert(namedSql, user));
StepVerifier.create(newUserId).expectNext(size + 3L).verifyComplete();
}
Kotlin 版例子:
@Test
fun testInsert() = runBlocking {
val newUserId = exec {
it.asyncInsert<Long>("insert into `test`.`user`(pt_name, pt_password) values(?,?)",
"hello user", "hello user pwd")
}
assertEquals(size + 1L, newUserId)
val namedSQL = "insert into `test`.`user`(pt_name, pt_password) values(:name, :password)"
val newUserId2 = exec {
it.asyncNamedInsert<Long>(namedSQL, mapOf("name" to "hello user", "password" to "hello user pwd"))
}
assertEquals(size + 2L, newUserId2)
val newUserId3 = exec {
it.asyncNamedInsert<Long>(namedSQL, User(null, "hello user", "hello user pwd", null))
}
assertEquals(size + 3L, newUserId3)
}
更新日志:
- 网络工具增加 OpenSSL 引擎支持。
- 增加命名参数 SQL API。
- 完成了 Kotlin 相关文档。
- 新增了 SSL/TLS 配置文档。
- 修复了使用请求 Accept 头匹配 router 时,router 优先级错误的问题。
- 增加了默认的 bad message 监听器。
- 增加了 HTTP client 连接泄露追踪。
转自 http://ift.tt/2mOKAn1
The post Firefly 4.6.0 正式版发布,新增 OpenSSL 引擎支持 appeared first on Linuxeden开源社区.
http://ift.tt/2zoCCqA
没有评论:
发表评论