Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jetty http客户端中SslSocketConnector setPort()的替代品是什么?_Java_Ssl_Jetty - Fatal编程技术网

Java jetty http客户端中SslSocketConnector setPort()的替代品是什么?

Java jetty http客户端中SslSocketConnector setPort()的替代品是什么?,java,ssl,jetty,Java,Ssl,Jetty,我目前正在将jetty的版本从7.1.6升级到7.6.2。我注意到,我们目前使用的SslSocketConnector的许多方法在旧版本中就被弃用了 从我在其他一些SO问题中看到的情况来看,我已经通过使用SslContextFactory替换了大多数方法 然而,我似乎找不到任何与SslSocketConnector的setPort(int)方法等价的方法。关于SslContextFactory的对应方法是什么,你有什么想法吗? 升级jetty版本之前的代码: theSSLConnector.se

我目前正在将jetty的版本从7.1.6升级到7.6.2。我注意到,我们目前使用的SslSocketConnector的许多方法在旧版本中就被弃用了

从我在其他一些SO问题中看到的情况来看,我已经通过使用
SslContextFactory
替换了大多数方法

然而,我似乎找不到任何与
SslSocketConnector
setPort(int)
方法等价的方法。关于
SslContextFactory
的对应方法是什么,你有什么想法吗?

升级jetty版本之前的代码:

theSSLConnector.setPort(theHTTPSPort);
theSSLConnector.setKeystore("key");
theSSLConnector.setPassword("OBF:password");
theSSLConnector.setKeyPassword("OBF:password");
theSSLConnector.setTruststore("trust");
theSSLConnector.setTrustPassword("OBF:password");
及之后:

SslContextFactory theSSLFactory = new SslContextFactory();
// Port goes here?
theSSLFactory.setKeyStorePath("key");
theSSLFactory.setKeyManagerPassword("OBF:password");
theSSLFactory.setKeyStorePassword("OBF:password");
theSSLFactory.setTrustStore("trust");
theSSLFactory.setTrustStorePassword("OBF:password");

通过使用已存在的
SslContextFactory
作为
SslSocketConnector
构造函数的输入参数来解决此问题:

SslContextFactory theSSLFactory = new SslContextFactory();
theSSLFactory.setKeyStorePath("key");
theSSLFactory.setKeyManagerPassword("OBF:password");
theSSLFactory.setKeyStorePassword("OBF:password");
theSSLFactory.setTrustStore("trust");
theSSLFactory.setTrustStorePassword("OBF:password");

SslSocketConnector theSSLConnector = new SslSocketConnector(theSSLFactory);
theSSLConnector.setPort(theHTTPSPort);

我用Jetty 7.4测试了这种方法,并且
setKeyStorePath
被命名为
setKeyStore
,必须设置它。与SslSocketConnector不同,它不默认为用户的主目录。