Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow automatic port selection by tomcat #116

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ protected synchronized void beforeStart() {
Tomcat.initWebappDefaults(context);
}

;

/**
* Override to assign an internal field that will trigger the removal of the unpacked WAR when the context is closed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
final StandardContext standardContext = (StandardContext) host.findChild(contextName.getName());
standardContextProducer.set(standardContext);

final HTTPContext httpContext =
new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort());
// CHANGED: Use tomcat values instead of configured once, to support automatic port selection
final HTTPContext httpContext = new HTTPContext(tomcat.getHost().getName(), tomcat.getConnector().getLocalPort());

for (final String mapping : standardContext.findServletMappings()) {
httpContext.add(new Servlet(standardContext.findServletMapping(mapping), contextName.getPath()));
Expand Down Expand Up @@ -230,8 +230,11 @@ protected void startTomcatEmbedded() throws LifecycleException, org.apache.catal
host.setAutoDeploy(false);
host.setConfigClass(EmbeddedContextConfig.class.getCanonicalName());

// CHANGED: call embeddedHostConfig.setUnpackWARs again instead of ((StandardHost) host).setUnpackWARs(configuration.isUnpackArchive()), without this change org.apache.wicket.protocol.http.WebApplication.getServletContext().getRealPath("/") return null
// with embeddedHostConfig.setUnpackWARs(configuration.isUnpackArchive()); it returns the valid path somewhere in [userdir]]\AppData\Local\Temp\ so i expect ((StandardHost) host).setUnpackWARs(configuration.isUnpackArchive()) is not working propably in an
// arquillian tomcat8 setup
embeddedHostConfig = new EmbeddedHostConfig();
((StandardHost) host).setUnpackWARs(configuration.isUnpackArchive());
embeddedHostConfig.setUnpackWARs(configuration.isUnpackArchive());

host.addLifecycleListener(embeddedHostConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class TomcatEmbeddedConfiguration implements ContainerConfiguration {

private String bindAddress = "localhost";

private int bindHttpPort = 8080;
private int bindHttpPort; // CHANGED: Use 0 as default to auto select next free port (this change is not strictly necessary, it is also possible to set 0 by configuration)

private String tomcatHome = null;
private String tomcatHome;

private String appBase = "webapps";

private String workDir = null;
private String workDir;

private String serverName = "arquillian-tomcat-embedded";

Expand Down