Skip to content

Commit 57b5d9f

Browse files
author
pengyongjian
committed
first commit
1 parent a450b8a commit 57b5d9f

23 files changed

+1300
-7
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ hs_err_pid*
2424
.idea
2525
*.iml
2626
target/
27+
demo/target/
2728
.DS_Store
29+
30+
#demo/

readme renamed to README.md

File renamed without changes.

demo/pom.xml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<artifactId>demo</artifactId>
9+
<groupId>org.pyj</groupId>
10+
<version>0.1.0</version>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.pyj</groupId>
15+
<artifactId>netty-websocket-http-spring-boot-starter</artifactId>
16+
<version>0.1.0</version>
17+
</dependency>
18+
</dependencies>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<configuration>
26+
<source>6</source>
27+
<target>6</target>
28+
</configuration>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
33+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.pyj.demo;
2+
3+
import org.pyj.http.annotation.NettyHttpHandler;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.context.annotation.ComponentScan.Filter;
8+
9+
@SpringBootApplication
10+
@ComponentScan(includeFilters = @Filter(NettyHttpHandler.class))
11+
public class Application {
12+
public static void main(String[] args) {
13+
SpringApplication.run(Application.class, args);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.pyj.demo;
2+
3+
import io.netty.handler.codec.http.HttpHeaders;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.stereotype.Component;
6+
import org.yeauty.annotation.*;
7+
import org.yeauty.pojo.Session;
8+
9+
import java.io.IOException;
10+
import java.util.Map;
11+
12+
/**
13+
* @author pengyongjian
14+
* @Description:
15+
* @date 2020/12/21 下午2:58
16+
*/
17+
@Component
18+
@Slf4j
19+
@ServerEndpoint(port = "${server.port}", path = "/connect")
20+
public class WebSocket {
21+
@OnOpen
22+
public void onOpen(Session session, @RequestParam Map<String, Object> map, HttpHeaders headers) {
23+
System.out.println(session.id());
24+
}
25+
26+
@OnClose
27+
public void onClose(Session session) throws IOException {
28+
}
29+
30+
@OnError
31+
public void onError(Session session, Throwable throwable) {
32+
}
33+
34+
@OnMessage
35+
public void OnMessage(Session session, String message) {
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
package org.pyj.demo.handler;
3+
4+
import org.pyj.http.NettyHttpRequest;
5+
import org.pyj.http.annotation.NettyHttpHandler;
6+
import org.pyj.http.handler.IFunctionHandler;
7+
8+
/**
9+
* @Description: http接口,参数化路径接口示例
10+
* @Author: pengyongjian
11+
* @Date: 2020-04-05 10:14
12+
*/
13+
@NettyHttpHandler(path = "/temp/path/",equal = false)
14+
public class PathVariableHandler implements IFunctionHandler<Object> {
15+
16+
@Override
17+
public Object execute(NettyHttpRequest request) {
18+
/**
19+
* 通过请求uri获取到path参数
20+
*/
21+
String id = request.getStringPathValue(3);
22+
23+
return id;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.pyj.demo.handler;
2+
3+
import org.pyj.http.NettyHttpRequest;
4+
import org.pyj.http.annotation.NettyHttpHandler;
5+
import org.pyj.http.handler.IFunctionHandler;
6+
7+
/**
8+
* @Description: http接口,向对应用户发送消息
9+
* @Author: pengyongjian
10+
* @Date: 2020-04-05 10:14
11+
*/
12+
@NettyHttpHandler(path = "/temp/body",method = "POST")
13+
public class TempHandler implements IFunctionHandler<Object> {
14+
15+
@Override
16+
public Object execute(NettyHttpRequest request) {
17+
String contentText = request.contentText();
18+
return contentText;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server.port=8080
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+

pom.xml

+44-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
</developers>
2323

2424
<properties>
25-
<netty.version>4.1.50.Final</netty.version>
25+
<netty-websocket.version>0.9.5</netty-websocket.version>
2626
<spring-boot.version>2.0.0.RELEASE</spring-boot.version>
27+
<lombok.version>1.18.2</lombok.version>
28+
<slf4j.version>1.7.12</slf4j.version>
2729
</properties>
2830

2931
<dependencies>
@@ -34,16 +36,51 @@
3436
<optional>true</optional>
3537
</dependency>
3638

39+
<!-- springcloud公共组件依赖开始 -->
3740
<dependency>
38-
<groupId>io.netty</groupId>
39-
<artifactId>netty-codec-http</artifactId>
40-
<version>${netty.version}</version>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-web</artifactId>
43+
<exclusions>
44+
<exclusion>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-tomcat</artifactId>
47+
</exclusion>
48+
</exclusions>
49+
<version>${spring-boot.version}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.yeauty</groupId>
54+
<artifactId>netty-websocket-spring-boot-starter</artifactId>
55+
<version>${netty-websocket.version}</version>
4156
</dependency>
57+
4258
<dependency>
43-
<groupId>io.netty</groupId>
44-
<artifactId>netty-handler</artifactId>
45-
<version>${netty.version}</version>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-dependencies</artifactId>
61+
<version>${spring-boot.version}</version>
62+
<type>pom</type>
63+
<scope>import</scope>
64+
<exclusions>
65+
<exclusion>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-starter-tomcat</artifactId>
68+
</exclusion>
69+
</exclusions>
4670
</dependency>
71+
72+
<dependency>
73+
<groupId>org.projectlombok</groupId>
74+
<artifactId>lombok</artifactId>
75+
<version>${lombok.version}</version>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>org.slf4j</groupId>
80+
<artifactId>slf4j-api</artifactId>
81+
<version>${slf4j.version}</version>
82+
</dependency>
83+
4784
</dependencies>
4885

4986

0 commit comments

Comments
 (0)