```xml
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-server-grizzly</artifactId>
</dependency>
```



#### 1、描述

通讯扩展插件，基于 grizzly 的http信号服务适配。可用于 Api 开发、Rpc 开发、Mvc web 开发、WebSocket 开发。支持 http2。(v3.6.0 后支持)

**支持信号：**

| 信号 | 说明 | 
| -------- | -------- | 
| http     | 默认端口 8080，可由 `server.port` 或 `server.http.port` 配置     | 
| ws | 端口与 http 共用 |


**配套的二级插件：**

| 插件 | 说明 | 
| -------- | -------- | 
| solon-server-grizzly-add-websocket     | 增加 websocket 通讯支持（端口与 http 共用）     | 



#### 2、应用示例

**Web 示例：**

```java
public class DemoApp {
    public static void main(String[] args) {
        Solon.start(DemoApp.class, args);
    }
}

@Controller
public class DemoController{
    @Mapping("/hello")
    public String hello(){
        return "Hello world!";
    }
}
```

**WebSocket 示例：（需要添加 solon-server-grizzly-add-websocket 插件）**


```java
public class DemoApp {
    public static void main(String[] args) {
        Solon.start(DemoApp.class, args, app->{
            //启用 WebSocket 服务
            app.enableWebSocket(true);
        });
    }
}

@ServerEndpoint("/ws/demo/{id}")
public class WebSocketDemo extends SimpleWebSocketListener {
    @Override
    public void onMessage(WebSocket socket, String text) throws IOException {
        socket.send("我收到了：" + text);
    }
}
```

更多内容请参考：[《Solon WebSocket 开发》](/article/332)

#### 3、添加 ssl 证书配置，启用 https 支持（极少有需求会用到）

```yml
server.ssl.keyStore: "/data/_ca/demo.jks" #或 "demo.pfx"
server.ssl.keyPassword: "demo"
```

更多配置，可参考：[《应用常用配置说明》](/article/174)



#### 4、自定义 SSLContext（不走配置，也可以 ssl）


```java
public class AppDemo {
    public static void main(String[] args) {
        Solon.start(AppDemo.class, args, app -> {
            SSLContext sslContext = ...;
            app.onEvent(HttpServerConfigure.class, e -> {
                e.enableSsl(true, sslContext);
            });
        });
    }
}
```


#### 5、启用 http2 （极少有需求会用到）

```java
@SolonMain
public class SeverDemo {
    public static void main(String[] args) {
        Solon.start(SeverDemo.class, args, app -> {
            app.onEvent(HttpServerConfigure.class, e -> {
                e.enableHttp2(true); 
            });
        });
    }
}
```

#### 6、添加 http 端口（极少有需求会用到）

一般是在启用 https 或 http2 之后，仍想要有一个 http 端口时，才会使用。 

```java
@SolonMain
public class SeverDemo {
    public static void main(String[] args) {
        Solon.start(SeverDemo.class, args, app -> {
            app.onEvent(HttpServerConfigure.class, e -> {
                e.addHttpPort(8082);
            });
        });
    }
}
```


