我试图使用远程 Tomcat10 服务器设置安全的 WebSocket 服务,但没有成功。在点击“wss://mydomain.org:4123/ws”后,我继续从邮递员那里得到“意外的服务器响应:404”。我附上了最重要的设置,以防有人希望发现我做错了什么。
我想提一下,我正在使用 Maven 通过隧道从 127.0.0.1 部署项目。
服务器.xml
...
<Service name="Catalina">
<Connector executor="tomcatThreadPool"
port="5123"
compression="off"
protocol="HTTP/1.1"
connectionTimeout="20000"
/>
<Connector port="4123"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="100"
compression="off"
connectionTimeout="20000"
SSLEnabled="true"
scheme="https"
secure="true">
<SSLHostConfig >
<Certificate certificateFile="path/to/certificateFile"
certificateKeyFile="path/to/certificateKeyFile"
certificateChainFile="path/to/certificateChainFile" />
</SSLHostConfig>
</Connector>
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
...
</Host>
</Engine>
pom.xml
...
<dependencies>
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.1</version>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>My_WebService</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:5123/manager/text</url>
<path>/</path>
<server>My-Server</server>
<finalName>My_WebService</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
web.xml
...
<display-name>WS Engine</display-name>
<description>Desc.</description>
<resource-ref>
<description>My Database</description>
<res-ref-name>jdbc/my-database</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<context-param>
<param-name>org.apache.tomcat.websocket.binaryBufferSize</param-name>
<param-value>65536</param-value>
</context-param>
MainWs类
@ServerEndpoint("/ws")
public class MainWsClass {..}