Skip to content

Commit acba140

Browse files
committed
适配最新版
1 parent dc26234 commit acba140

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

frameworks/Java/smart-socket/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
</properties>
1818

1919
<dependencies>
20+
<dependency>
21+
<groupId>tech.smartboot.feat</groupId>
22+
<artifactId>feat-restful</artifactId>
23+
<version>0.5</version>
24+
</dependency>
2025
<dependency>
2126
<groupId>io.edap</groupId>
2227
<artifactId>edapx-json</artifactId>
@@ -26,6 +31,12 @@
2631
<groupId>tech.smartboot.servlet</groupId>
2732
<artifactId>servlet-core</artifactId>
2833
<version>${smartservlet.version}</version>
34+
<exclusions>
35+
<exclusion>
36+
<groupId>tech.smartboot.feat</groupId>
37+
<artifactId>feat-restful</artifactId>
38+
</exclusion>
39+
</exclusions>
2940
</dependency>
3041
<dependency>
3142
<groupId>com.zaxxer</groupId>

frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,35 @@
88

99
package org.smartboot.http;
1010

11-
import org.smartboot.Message;
12-
import tech.smartboot.feat.core.Feat;
13-
import tech.smartboot.feat.core.common.enums.HeaderValueEnum;
14-
import tech.smartboot.feat.core.server.HttpHandler;
15-
import tech.smartboot.feat.core.server.HttpRequest;
16-
import tech.smartboot.feat.core.server.HttpResponse;
11+
import tech.smartboot.feat.restful.RestFeat;
1712

1813
public class Bootstrap {
1914
static byte[] body = "Hello, World!".getBytes();
2015

2116
public static void main(String[] args) {
2217
int cpuNum = Runtime.getRuntime().availableProcessors();
2318
// 定义服务器接受的消息类型以及各类消息对应的处理器
24-
Feat.createHttpServer(options -> {
19+
// Feat.createHttpServer(options -> {
20+
// options.threadNum(cpuNum + 1)
21+
// .headerLimiter(0)
22+
// .readBufferSize(1024 * 4)
23+
// .writeBufferSize(1024 * 4);
24+
// }).httpHandler(request -> {
25+
// HttpResponse response = request.getResponse();
26+
// if ("/plaintext".equals(request.getRequestURI())) {
27+
// response.setContentLength(body.length);
28+
// response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
29+
// response.write(body);
30+
// } else if ("/json".equals(request.getRequestURI())) {
31+
// response.setContentType("application/json");
32+
// JsonUtil.writeJsonBytes(response, new Message("Hello, World!"));
33+
// }
34+
// }).listen(8080);
35+
RestFeat.createServer(options -> {
2536
options.threadNum(cpuNum + 1)
2637
.headerLimiter(0)
2738
.readBufferSize(1024 * 4)
2839
.writeBufferSize(1024 * 4);
29-
}).httpHandler(request -> {
30-
HttpResponse response = request.getResponse();
31-
if ("/plaintext".equals(request.getRequestURI())) {
32-
response.setContentLength(body.length);
33-
response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
34-
response.write(body);
35-
} else if ("/json".equals(request.getRequestURI())) {
36-
response.setContentType("application/json");
37-
JsonUtil.writeJsonBytes(response, new Message("Hello, World!"));
38-
}
3940
}).listen(8080);
4041
}
4142

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.smartboot.http;
2+
3+
import org.smartboot.Message;
4+
import tech.smartboot.feat.core.apt.annotation.Controller;
5+
import tech.smartboot.feat.core.apt.annotation.RequestMapping;
6+
import tech.smartboot.feat.core.common.enums.HeaderValueEnum;
7+
import tech.smartboot.feat.core.server.HttpResponse;
8+
9+
@Controller
10+
public class FeatController {
11+
static byte[] body = "Hello, World!".getBytes();
12+
13+
@RequestMapping("/plaintext")
14+
public byte[] plaintext(HttpResponse response) {
15+
response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
16+
return body;
17+
}
18+
19+
@RequestMapping("/json")
20+
public Message json(HttpResponse response) {
21+
response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
22+
return new Message("Hello, World!");
23+
}
24+
}

0 commit comments

Comments
 (0)