描述
我做了一个JUnit测试,专注于尝试测试对SOAP Web服务的调用.
我正在使用嵌入式tomcat服务器进行测试,以便使用模拟服务器运行我的测试.
我也使用http和https连接器.
我需要为这两个连接器使用自动端口,因为测试在Jenkins服务器上运行,我不能只使用端口443或8443,因为它们已被占用.
我知道使用端口0作为标准端口将导致tomcat使用自动端口分配,但我无法使用它与两个连接器.
预期的行为
我也想为我的自定义ssl连接器使用自动端口分配.
是否有可能以某种方式这样做?
示例代码
这是我的tomcat实例的代码:
@Before
public void setup() throws Throwable {
File tomcatWorkingDir = new File(mWorkingDir);
//Empty the target/tomcat-working-dir directory if it exist
//Create the directory otherwise
if(tomcatWorkingDir.exists() && tomcatWorkingDir.isDirectory()){
LOGGER.info("cleaning tomcat-working-dir directory");
FileUtils.cleanDirectory(new File(mWorkingDir));
} else {
LOGGER.info("create tomcat-working-dir directory");
tomcatWorkingDir.mkdir();
}
LOGGER.info("disabling ssl certification validation");
//Disable JVM ssl sockets connection
disableJVMCertificate();
//Add server certificate
createServerCertificate();
//Custom SSL Connector
Connector SSLConnector = getSSLConnector();
mTomcat = new Tomcat();
//Standard http startup port …Run Code Online (Sandbox Code Playgroud)