arquillian / arquillian-container-tomcat

Arquillian Containers for Tomcat
https://arquillian.org
25 stars 36 forks source link

Automatically use free Port #115

Closed pschwarzer-tt closed 1 month ago

pschwarzer-tt commented 3 years ago

Hi, is it possible to adjust plugin, so it allows automatic search for a free port? The org.apache.catalina.startup.Tomcat class allows this by passing 0 as port:

tomcatServer.setPort(0);
try {
    tomcatServer.start();
    assertThat(tomcatServer.getConnector().getLocalPort()).isGreaterThan(0);
} 
catch (LifecycleException e) {
    fail("Failed to start Tomcat server");
}

When i pass 0 in setup(TomcatConfiguration) the TomcatContainer::start method will pass 0 to Tomcat and Tomcat identifies any free port. Checking tomcat.getConnector().getLocalPort() after tomcat.start() give me the free port.

But in the TomcatContainer::deploy method, the original port 0 is passed to create a HTTPContext.

Is it possible to change this to new HTTPContext(tomcat.getHost().getName(), tomcat.getConnector().getLocalPort()); so it uses the port used by tomcat?

We are using the tomcat-embedded-8 version of the plugin.

SebastianTomTec commented 3 years ago

Seems to be a duplicate of #23

bartoszmajsak commented 3 years ago

Thanks for figuring out the root cause.

Is it possible to change this to new HTTPContext(tomcat.getHost().getName(), tomcat.getConnector().getLocalPort()); so it uses the port used by tomcat?

Sure, would anyone of you be up for opening a pull request with this improvement?

rhusar commented 1 month ago

Seems to be a duplicate of #23

Right, closed as duplicate.

rhusar commented 1 month ago

Fixed for 1.2.2.Final. Closing! Thanks for the reports and fixes everyone.