簡體   English   中英

無法使用Maven和Jetty創建SSL連接

[英]Can't create an SSL connection with Maven and Jetty

我有一個與Jetty和Maven一起運行的Web服務。 現在,我想為此WS創建一個SSL連接。 我在pom.xml文件中應用以下代碼:

pom.xml

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
        <scanIntervalSeconds>5</scanIntervalSeconds>
        <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                <port>9090</port>
                <maxIdleTime>60000</maxIdleTime>
            </connector>
            <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
                <port>443</port>
                <maxIdleTime>60000</maxIdleTime>
                <keystore>jetty-ssl.keystore</keystore>
                <password>jetty6</password>
                <keyPassword>jetty6</keyPassword>
            </connector>
        </connectors>
    </configuration>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>keytool-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <id>clean</id>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
        <execution>
            <phase>generate-resources</phase>
            <id>genkey</id>
            <goals>
                <goal>generateKeyPair</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <keystore>jetty-ssl.keystore</keystore>
        <dname>cn=NCSL004</dname>
        <keypass>jetty6</keypass>
        <storepass>jetty6</storepass>
        <alias>jetty6</alias>
        <keyalg>RSA</keyalg>
    </configuration>
</plugin>

當我運行Maven時,我得到:

>       [INFO] >>> jetty-maven-plugin:8.1.13.v20130916:run (default-cli) @ Test >>> 

>       [INFO] --- keytool-maven-plugin:1.3:clean (clean) @ Test ---
>       [INFO] Keystore file 'jetty-ssl.keystore' deleted successfully.
>       [INFO] 
>       [INFO] --- keytool-maven-plugin:1.3:generateKeyPair (genkey) @ Test ---
>       [INFO] 
>
>       ...
>
>       2013-12-13 10:47:46.160:INFO:oejs.AbstractConnector:Started             
>       SelectChannelConnector@0.0.0.0:8080 <br />
>       [INFO] Started Jetty Server 

當我嘗試在[https:// localhost:443]上連接時,我得到了一個錯誤,此外,在[http:// localhost:9090]中,我也得到了一個錯誤! 因此,我的Web服務僅適用於[http:// localhost:8080]。 看來Maven沒有實現端口配置。

我該如何解決這個錯誤?

謝謝!

一些東西 ...

  1. 端口443在特殊的保留空間內(端口1至1024),因此不會發生從非特權用戶對其進行綁定的情況。

  2. 您正在使用jetty-8.1.13,但這是在org.eclipse.jetty名稱空間中,而不是在org.mortbay.jetty ,因此您的<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">行對於以下情況都是錯誤的碼頭8.這些條目適用於碼頭6及更早版本。

對於Jetty 8,它看起來像這樣...

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>8.1.14.v20131031</version>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
    <connectors>
       <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
          <port>9090</port>
          <maxIdleTime>60000</maxIdleTime>
       </connector>
       <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
          <port>9443</port>
          <maxIdleTime>60000</maxIdleTime>
          <keystore>src/test/resources/server.keystore</keystore>
          <keyPassword>123456</keyPassword>
          <password>123456</password>
       </connector>
     </connectors>
  </configuration>
</plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM