-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHttpsServer.java
More file actions
57 lines (53 loc) · 1.68 KB
/
Copy pathHttpsServer.java
File metadata and controls
57 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package fun.lib.actor.example;
import fun.lib.actor.api.cb.CbHttpServer;
import fun.lib.actor.api.http.DFHttpSvrReq;
import fun.lib.actor.core.DFActor;
import fun.lib.actor.core.DFActorDefine;
import fun.lib.actor.core.DFActorManager;
import fun.lib.actor.po.DFTcpServerCfg;
import fun.lib.actor.po.DFSSLConfig;
/**
* HttpsServer示例
* @author lostsky
*
*/
public final class HttpsServer {
public static void main(String[] args) {
DFActorManager.get()
.start(EntryActor.class); //启动入口actor,开始消息循环
}
private static class EntryActor extends DFActor{
@Override
public void onStart(Object param) {
//测试证书&私钥生成命令: openssl req -x509 -newkey rsa:2048 -nodes -days 365 -keyout private.pem -out cert.crt
//证书文件路径
String certPath = "/var/dfactor/cert.crt";
//私钥文件路径
String pemPath = "/var/dfactor/private.pem";
net.httpSvr(DFTcpServerCfg.newCfg(443)
.setSslConfig(DFSSLConfig.newCfg()
.certPath(certPath)
.pemPath(pemPath)),
new CbHttpServer() {
@Override
public int onHttpRequest(Object msg) {
DFHttpSvrReq req = (DFHttpSvrReq) msg;
//response
req.response("echo from ssl server, uri="+req.getUri())
.send();
return MSG_AUTO_RELEASE;
}
@Override
public void onListenResult(boolean isSucc, String errMsg) {
log.info("listen result: isSucc="+isSucc+", err="+errMsg);
if(!isSucc){
sys.shutdown();
}
}});
//start http server
}
public EntryActor(Integer id, String name, Boolean isBlockActor) {
super(id, name, isBlockActor);
}
}
}