Skip to content

Commit 78411aa

Browse files
committed
Fix issue where incorrect HTTP port gets used for rest clients in hollow mode
1 parent 0cc7e0e commit 78411aa

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;
@@ -230,6 +232,11 @@ private void commonInit() {
230232
}
231233
if (isHollow) {
232234
setContainerIpAddress(ManuallyStartedConfiguration.getHostname());
235+
try {
236+
setFirstMappedPort(new URL(ManuallyStartedConfiguration.getRuntimeURL()).getPort());
237+
} catch (MalformedURLException e) {
238+
LOG.debug("Unable to obtain port from " + ManuallyStartedConfiguration.getRuntimeURL(), e);
239+
}
233240
withAppContextRoot(ManuallyStartedConfiguration.getBasePath());
234241
} else {
235242
withAppContextRoot("/");
@@ -270,6 +277,10 @@ public void setFirstMappedPort(int port) {
270277
if (!isHollow)
271278
throw new IllegalStateException("Can only set first mapped port in hollow mode");
272279
primaryPort = port;
280+
List<Integer> exposedPorts = new ArrayList<>(getExposedPorts());
281+
if (!exposedPorts.contains(primaryPort))
282+
exposedPorts.add(0, primaryPort);
283+
setExposedPorts(exposedPorts);
273284
}
274285

275286
@Override

0 commit comments

Comments
 (0)