OpenShift上DIY盒式磁带上的WebSockets

时间:2014-06-04 14:50:54

标签: websocket glassfish openshift grizzly

我试图在OpenShift上构建实现WebSockets的DIY应用程序。我从这个例子开始:

https://www.openshift.com/blogs/how-to-build-java-websocket-applications-using-the-jsr-356-api

如果我在本地运行,它可以完美运行。当我将代码上传到DIY OpenShift盒式磁带并进行编译时,我收到错误消息。我修改了代码,以便服务器连接到端口8000上的$ OPENSHIFT_DIY_IP,但是当代码到达行server.start();它因以下错误而崩溃。

我做错了什么?我尝试了其他端口(17500及以上),没有任何运气。

错误:

Binding server to 127.7.177.1:8000
Jun 04, 2014 10:28:02 AM org.glassfish.tyrus.server.ServerContainerFactory create
INFO: Provider class loaded: org.glassfish.tyrus.container.grizzly.GrizzlyEngine
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:131)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:87)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:64)
at org.glassfish.grizzly.AbstractBindingHandler.bind(AbstractBindingHandler.java:140)
at org.glassfish.grizzly.AbstractBindingHandler.bind(AbstractBindingHandler.java:159)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:470)
at org.glassfish.grizzly.http.server.NetworkListener.start(NetworkListener.java:658)
at org.glassfish.grizzly.http.server.HttpServer.start(HttpServer.java:264)
at org.glassfish.tyrus.container.grizzly.GrizzlyEngine$1.start(GrizzlyEngine.java:88)
at org.glassfish.tyrus.server.TyrusServerContainer.start(TyrusServerContainer.java:119)
at org.glassfish.tyrus.server.Server.start(Server.java:122)
at org.neo.wordgame.server.WebSocketServer.runServer(WebSocketServer.java:23)
at org.neo.wordgame.server.WebSocketServer.main(WebSocketServer.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:744)
Please press a key to stop the server.Jun 04, 2014 10:28:04 AM org.glassfish.tyrus.server.Server stop
INFO: Websocket Server stopped.

2 个答案:

答案 0 :(得分:3)

您的应用需要在$ OPENSHIFT_DIY_IP上侦听端口8080,但您需要在http://app-domain.rhcloud.com:8000http://app-domain.rhcloud.com:8443(ssl)从外部连接到它。绑定到$ OPENSHIFT_DIY_IP上的端口8000将无效。

答案 1 :(得分:0)

正如developercorey所述。关于OpenShift上的WebSockets的最新消息我可以找到this blog post,清楚地说你必须从外面访问8000/8443。

作为一个实例,我使用WebSockets将应用程序部署到OpenShift中。如果您使用http://vinbudin-openshift.anthavio.net/ui

访问它

虽然应用程序仍然有效,但因为它可以降级为长时间轮询,所以 当您查看Chrome Developer Tool Network选项卡时,您可以看到被拒绝的WebSocket升级请求

Request URL:ws://vinbudin-openshift.anthavio.net/ui/PUSH/?v-uiId=0&v-csrfToken=bcd0c9a6-2a6f-4ddb-8332-7929e4337b2d&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.1.5.vaadin4-jquery&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true
Request Method:GET
Status Code:501 Not Implemented

但是使用端口为8000 http://vinbudin-openshift.anthavio.net:8000/ui的url会产生更好的结果

Request URL:ws://vinbudin-openshift.anthavio.net:8000/ui/PUSH/?v-uiId=0&v-csrfToken=bcd0c9a6-2a6f-4ddb-8332-7929e4337b2d&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.1.5.vaadin4-jquery&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true
Request Method:GET
Status Code:101 Switching Protocols