Java jetty http客户端中SslSocketConnector setPort()的替代品是什么?
我目前正在将jetty的版本从7.1.6升级到7.6.2。我注意到,我们目前使用的SslSocketConnector的许多方法在旧版本中就被弃用了 从我在其他一些SO问题中看到的情况来看,我已经通过使用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
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不同,它不默认为用户的主目录。