Skip to content

Commit 3542eb6

Browse files
authored
Merge pull request #226 from aguibert/hollow-customized-port
Fix issue where incorrect HTTP port gets used for rest clients in hollow mode
2 parents 4415eb4 + 78411aa commit 3542eb6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

modules/testcontainers/src/main/java/org/microshed/testing/testcontainers/ApplicationContainer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.lang.annotation.Annotation;
2424
import java.lang.reflect.InvocationTargetException;
2525
import java.lang.reflect.Method;
26+
import java.net.MalformedURLException;
2627
import java.net.URI;
28+
import java.net.URL;
2729
import java.nio.file.Files;
2830
import java.nio.file.Path;
2931
import java.nio.file.Paths;
@@ -233,6 +235,11 @@ private void commonInit() {
233235
}
234236
if (isHollow) {
235237
setContainerIpAddress(ManuallyStartedConfiguration.getHostname());
238+
try {
239+
setFirstMappedPort(new URL(ManuallyStartedConfiguration.getRuntimeURL()).getPort());
240+
} catch (MalformedURLException e) {
241+
LOG.debug("Unable to obtain port from " + ManuallyStartedConfiguration.getRuntimeURL(), e);
242+
}
236243
withAppContextRoot(ManuallyStartedConfiguration.getBasePath());
237244
} else {
238245
withAppContextRoot("/");
@@ -273,6 +280,10 @@ public void setFirstMappedPort(int port) {
273280
if (!isHollow)
274281
throw new IllegalStateException("Can only set first mapped port in hollow mode");
275282
primaryPort = port;
283+
List<Integer> exposedPorts = new ArrayList<>(getExposedPorts());
284+
if (!exposedPorts.contains(primaryPort))
285+
exposedPorts.add(0, primaryPort);
286+
setExposedPorts(exposedPorts);
276287
}
277288

278289
@Override

0 commit comments

Comments
 (0)