小编Flo*_*t M的帖子

使用嵌入式tomcat服务器进行JUnit测试,如何为http和https连接器指定自动端口?

描述

我做了一个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)

java ssl tomcat http jenkins

13
推荐指数
1
解决办法
1364
查看次数

标签 统计

http ×1

java ×1

jenkins ×1

ssl ×1

tomcat ×1