websocket 代码在 Prod Tomcat 服务器上不起作用 - 404 错误 [英] websocket code not working on Prod Tomcat Server - 404 Error

查看:43
本文介绍了websocket 代码在 Prod Tomcat 服务器上不起作用 - 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行我的第一个 websocket 应用程序并参考了 这个链接来获取一些示例代码.我只是创建了 CustomEndPointWSClient 类、 html 文件,然后在 netbeans IDE 上运行它,它就像一个魅力.

我尝试通过将 ws:// 更改为 wss:// 和它适用于我的开发环境,但是当我在生产环境中部署相同的代码时,它在控制台中抛出以下错误:

<块引用>

WebSocket 连接到wss://xxxxxx-xxx.xxxx.com/websoc/ratesrv"失败:WebSocket 握手期间出错:意外响应代码:404

对于开发环境,我低于 WS 调用正在工作:

wsocket = new WebSocket("wss://dev_ip:8443/websoc/ratesrv");

对于我使用的 Prod(注意 url 中的 .com):

wss://xxxxx-xxxxx.xx.com/websoc/ratesrv

我是否还需要在 PROD 中明确提供端口号?

解决方案

您的 Tomcat 版本是否包含 Websockets Runtime?

  • 如果是这样,您必须从 WAR 中删除所有 Websockets 依赖项.确保在将范围更改为提供后调用 mvn clean.

  • 如果没有,你应该包括它.如果你想使用 Tyrus,只需输入

<块引用>

<依赖><groupId>org.glassfish.tyrus</groupId><artifactId>tyrus-container-servlet</artifactId><version>1.12</version></依赖><依赖><groupId>org.glassfish.tyrus</groupId><artifactId>tyrus-client</artifactId><version>1.12</version></依赖>

并在部署时检查 Tomcat 控制台中是否没有错误.

I am trying to run my first websocket app and refered this link to get some sample code . I simply created CustomEndPoint , WSClient class , html file and then ran it on netbeans IDE and it was working like a charm.

I tried to deploy it on tomcat server whose url is accessible using https by changing ws:// with wss:// and it worked on my dev environment but when I deployed the same code on Production env its throwing below error in console:

WebSocket connection to 'wss://xxxxxx-xxx.xxxx.com/websoc/ratesrv' failed: Error during WebSocket handshake: Unexpected response code: 404

For dev environment I below WS call is working :

wsocket = new WebSocket("wss://dev_ip:8443/websoc/ratesrv");

For Prod I am using(note the .com in url):

wss://xxxxx-xxxxx.xx.com/websoc/ratesrv

Do I need to explicitly provide the port number as well in PROD ?

解决方案

Does your Tomcat version includes Websockets Runtime?

  • If it does you must delete all the Websockets dependencies from your WAR. Ensure that you call mvn clean after change scope to provided.

  • If not, you should include it. If you want to use Tyrus just put

<dependency>
    <groupId>org.glassfish.tyrus</groupId>
    <artifactId>tyrus-container-servlet</artifactId>
    <version>1.12</version>
</dependency>

<dependency>
    <groupId>org.glassfish.tyrus</groupId>
    <artifactId>tyrus-client</artifactId>
    <version>1.12</version>
</dependency>

And check that that there are no errors in the Tomcat console when deploy.

这篇关于websocket 代码在 Prod Tomcat 服务器上不起作用 - 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆