如何通过Maven在Tomcat10上远程部署一个安全的websocket服务

How to remotely deploy a secure websocket service on Tomcat10 through Maven

我试图使用我的远程 Tomcat10 服务器设置安全的 WebSocket 服务,但没有成功。在点击“wss://mydomain.org:4123/ws”后,我继续从邮递员那里得到“意外的服务器响应:404”。我附上了最重要的设置,以防有人发现我做错了什么。

我想提一下,我正在使用 Maven 通过隧道从 127.0.0.1 部署项目。

server.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>

MainWsClass

@ServerEndpoint("/ws")
public class MainWsClass {..}

我最终使用了以下有效的 POM:

...
<dependencies>

<dependency>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven3-plugin</artifactId>
  <version>1.9.9</version>
</dependency>

<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>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>10.1.0-M10</version>
</dependency>

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-websocket</artifactId>
  <version>10.1.0-M10</version>
</dependency>

</dependencies>

<build>
<finalName>My_WebService</finalName>
<plugins>

    <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven3-plugin</artifactId>
    <version>1.9.9</version>
    <configuration>
      <container>
        <containerId>tomcat10x</containerId>
        <type>remote</type>
      </container>
      <configuration>
        <type>runtime</type>
        <properties>
          <cargo.server.settings>My_WebService</cargo.server.settings>
        </properties>
      </configuration>
    </configuration>
    </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
    <configuration>
      <webResources>
        <resource>
          <directory>src/main/webapp</directory>
          <filtering>true</filtering>
        </resource>
      </webResources>
    </configuration>
  </plugin>

</plugins>
</build>