简体   繁体   English

在灰熊上设置WebSocket SSL

[英]Setting websocket SSL on grizzly

I'm trying to configure a WebSocket over SSL with the "javax.websocket.server.ServerEndpoint" on a grizzly container. 我正在尝试使用灰熊容器上的“ javax.websocket.server.ServerEndpoint”通过SSL配置WebSocket。 However i can't find any way to set the SSL property to my endpoint. 但是我找不到任何将SSL属性设置为我的端点的方法。

My endpoint code : 我的端点代码:

import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(
    Value="/ptiWs",
    decoders = {ApiMessage.ApiCoder.class},
)
public class WebsocketEndpoint {

   private static final Logger LOG = LogManager.getLogger(WebsocketEndpoint.class);
   private final ApiVisitorImpl apiVisitor;

    public WebsocketEndpoint(){
    }

    @OnOpen
    public void onOpen(Session session){
        LOG.info("New connection open : " + session.toString());
    }


    @OnMessage
    public void message(Session session, ApiMessage message){
        LOG.info("New message arrive " + message.toString());
    }
}

Finally, I add my endpoint to my Grizzly instance with the following code : 最后,使用以下代码将端点添加到我的Grizzly实例:

Server ptiWebsocket = new Server("localhost", 8025, "/", null, WebsocketEndpoint.class);
ptiWebsocket.start();

I have already done this work for glassfish and it's pretty easy, but here i don't find any way to proceed. 我已经为玻璃鱼完成了这项工作,这很容易,但是在这里我找不到任何继续进行的方法。

And the dependency : 和依赖:

   <dependency>
        <groupId>javax.websocket</groupId>
        <artifactId>javax.websocket-api</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.glassfish.tyrus</groupId>
        <artifactId>tyrus-server</artifactId>
        <version>1.7</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.tyrus</groupId>
        <artifactId>tyrus-container-grizzly-server</artifactId>
        <version>1.7</version>
    </dependency> 

Thanks 谢谢

Looking at the tyrus source code, it looks like that this isn't supported out of the box. 查看tyrus源代码,似乎不支持立即使用。 You'll need to make a new ServerContainerFactory much like the org.glassfish.tyrus.container.grizzly.server.GrizzlyServerContainer. 您需要创建一个新的ServerContainerFactory,就像org.glassfish.tyrus.container.grizzly.server.GrizzlyServerContainer一样。 Go grab the code out of Github. 从Github中获取代码。 You can make your own GrizzlySSLServerContainer. 您可以创建自己的GrizzlySSLServerContainer。 And then you'll add the SSL config to the NetworkListener in the start method. 然后,您将在start方法中将SSL配置添加到NetworkListener。 You can then add the full qualified name of your new GrizzlySSLServerContainer class into a META-INF/services/org.glassfish.tyrus.spi.ServerContainerFactory with your JAR and Tyrus should pick it up. 然后,可以使用JAR将新的GrizzlySSLServerContainer类的全限定名称添加到META-INF / services / org.glassfish.tyrus.spi.ServerContainerFactory中,而Tyrus应该选择它。

It is somewhat hacky, and it sucks to have to copy/paste code but it should work. 它有点hacky,必须复制/粘贴代码很烂,但是应该可以。

1.) Copy GrizzlyServerContainer to your new GrizzlySSLServerContainer class. 1.)将GrizzlyServerContainer复制到新的GrizzlySSLServerContainer类。

2.) Add method to provide SSL configuration data into your new Container class. 2.)将提供SSL配置数据的方法添加到新的Container类中。

3.) Add data to NetworkListener to instantiate SSL 3.)将数据添加到NetworkListener以实例化SSL

4.) Add your new class to the META-INF/serivces directory of your jar. 4.)将新类添加到jar的META-INF / serivces目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM