怎么用netty开发一个同时提供http和websocket的服务?

246 阅读1分钟

Sky

项目地址: github.com/fzdwx/sky

依赖

<dependency>
  <groupId>io.github.fzdwx</groupId>
  <artifactId>sky-http-springboot-starter</artifactId>
  <version>0.10.6</version>
</dependency>

启动类

import http.HttpServerRequest;

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        final ConfigurableApplicationContext run = SpringApplication.run(BurstServerApplication.class);
    }

    // normal request
    @GetMapping("hello")
    public String hello(@RequestParam String name) {
        return "Hello " + name;
    }

    // upgrade to websocket
    @GetMapping("connect")
    public void connect(@RequestParam String name, HttpServerRequest request) {
        request.upgradeToWebSocket(ws->{
            ws.mountOpen(h -> {
                ws.send("Hello " + name);
            });
        });
    }
}

问题

当前项目对servlet的支持不是很好,也不支持filter等servlet提供的功能。