在Jetty 9上配置SSL:oeji.SelectorManager:qtp1706748598-22-selector-0:java.lang.NullPointerException

时间:2013-07-07 11:42:25

标签: java ssl websocket jetty

我正在尝试在Jetty 9.0.4上配置SSL。我正在使用Jetty和WebSockets,以及Autobahn Android用于客户端。

我尝试了几种配置,然后: http://www.eclipse.org/jetty/documentation/current/configuring-ssl.html

这个: Configure SSL on Jetty

最后我总是有这个例外

2013-07-07 13:36:11.742:WARN:oeji.SelectorManager:qtp1384613607-13-selector-0: 
java.lang.NullPointerException
    at org.eclipse.jetty.server.HttpConnection.<init>(HttpConnection.java:96)
    at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:61)
    at org.eclipse.jetty.server.SslConnectionFactory.newConnection(SslConnectionFactory.java:86)
    at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:401)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.createEndPoint(SelectorManager.java:575)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.access$500(SelectorManager.java:318)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector$Accept.run(SelectorManager.java:699)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.runChange(SelectorManager.java:407)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.runChanges(SelectorManager.java:396)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processChanges(SelectorManager.java:479)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:440)
    at org.eclipse.jetty.io.SelectorManager$ManagedSelector.run(SelectorManager.java:420)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
    at java.lang.Thread.run(Thread.java:722)

我把所有东西放在jetty.xml中。这是我的配置。

<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
    <Set name="KeyStorePath">
        <Property name="jetty.home" default="." />/<Property name="jetty.keystore" default="etc/keystore"/>
    </Set>
    <Set name="KeyStorePassword">
        <Property name="jetty.keystore.password" default="OBF:password"/>
    </Set>
    <Set name="KeyManagerPassword">
        <Property name="jetty.keymanager.password" default="OBF:password"/>
    </Set>
    <Set name="TrustStorePath">
        <Property name="jetty.home" default="." />/<Property name="jetty.truststore" default="etc/keystore"/>
    </Set>
    <Set name="TrustStorePassword">
        <Property name="jetty.truststore.password" default="OBF:password"/>
    </Set>
    <Set name="EndpointIdentificationAlgorithm"/>
    <Set name="ExcludeCipherSuites">
        <Array type="String">
            <Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
            <Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
            <Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
            <Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
            <Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
            <Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
            <Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
        </Array>
    </Set>
</New>
<Call id="sslConnector" name="addConnector">
    <Arg>
        <New class="org.eclipse.jetty.server.ServerConnector">
            <Arg name="server">
                <Ref refid="Server" />
            </Arg>
            <Arg name="factories">
                <Array type="org.eclipse.jetty.server.ConnectionFactory">
                    <Item>
                        <New class="org.eclipse.jetty.server.SslConnectionFactory">
                            <Arg name="next">http/1.1</Arg>
                            <Arg name="sslContextFactory">
                                <Ref refid="sslContextFactory"/>
                            </Arg>
                        </New>
                    </Item>
                    <Item>
                        <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                            <Arg name="config">
                                <Ref refid="tlsHttpConfig"/>
                            </Arg>
                        </New>
                    </Item>
                </Array>
            </Arg>
            <Set name="host">
                <Property name="jetty.host" />
            </Set>
            <Set name="port">
                <Property name="jetty.tls.port" default="8443" />
            </Set>
            <Set name="idleTimeout">30000</Set>
        </New>
    </Arg>
</Call>

那么我在没有SSL的情况下做的所有事情都应该适用于码头?我的servlet和socket?

谢谢大家

2 个答案:

答案 0 :(得分:1)

实际上,我使用版本9.0.4的librairies在Jetty 9.0.3上。我将服务器升级到9.0.4,现在可以使用了!

答案 1 :(得分:1)

我遇到了同样的问题(在Jetty 9.0.4上)。使用9.0.4版本的所有库,并假定错误。

经过一些挖掘实例;我遇到了这个jetty configuration example。当您查看jetty-ssl.xml文件时,您会遇到以下代码:

    <!-- =========================================================== -->
  <!-- Create a TLS specific HttpConfiguration based on the        -->
  <!-- common HttpConfiguration defined in jetty.xml               -->
  <!-- Add a SecureRequestCustomizer to extract certificate and    -->
  <!-- session information                                         -->
  <!-- =========================================================== -->
  <New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
    <Arg><Ref refid="httpConfig"/></Arg>
    <Call name="addCustomizer">
      <Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
    </Call>
  </New>

当你将它添加到你的xml文件时,一切都应该正常工作。