我部署了一个带websocket应用程序的java spring引导程序,该程序在本地可用于azure Web应用程序。当我进入html页面时出现错误
websocket.js:6到'wss://ctiadapter.azurewebsites.net/ws/806/0qbqlnon/websocket'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:403
我的猜测是由于反向代理Azure网络应用程序的使用,但不确定如何解决或绕过它。
感谢您的反馈。
答案 0 :(得分:0)
实际上,首先,当您创建Azure WebApp并在Application settings
中进行配置时,您需要启用以下Web sockets
功能。
为了重现您的问题,我从https://github.com/spring-guides/gs-messaging-stomp-websocket/releases下载了最新版本的spring-guides/gs-messaging-stomp-websocket
。然后,通过gradlew build
构建可执行的jar文件,并通过Kudo控制台将其上传到我现有WebApp的路径site/wwwroot
中,并配置web.config
文件使其运行。>
这里是web.config
的内容。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<!-- <httpPlatform processPath="%JAVA_HOME%\bin\java.exe" -->
<httpPlatform processPath="D:\Program Files\Java\jre1.8.0_181\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\gs-messaging-stomp-websocket-0.1.0.jar"">
</httpPlatform>
</system.webServer>
</configuration>
接下来,当我访问https://<my webapp name>.azurewebsites.net
并单击Connect
按钮与服务器建立Websocket连接时,我也遇到了同样的问题。
我注意到websocket
请求与SSL一起使用wss://
。因此,我尝试访问http://<my webapp name>.azurewebsites.net
来执行相同的操作,但它的工作异常。
我搜索了它并研究了示例源代码,我认为此示例中缺少Spring Security WebSocket支持。您可以参考旧的Spring博客Preview Spring Security WebSocket Support,并按照有关WebSocket Configuration的Spring Security文档进行修复。有两个个人GitHub存储库BijanVan/Spring-Boot-Websocket-Sample和rstoyanchev/spring-websocket-portfolio,它们都使用org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer
来支持带SSL的WebSocket。