...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.docker.v1_41;18import org.openqa.selenium.docker.ContainerId;19import org.openqa.selenium.docker.ContainerInfo;20import org.openqa.selenium.internal.Require;21import org.openqa.selenium.json.Json;22import org.openqa.selenium.remote.http.Contents;23import org.openqa.selenium.remote.http.HttpHandler;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import java.util.ArrayList;27import java.util.List;28import java.util.Map;29import java.util.logging.Logger;30import java.util.stream.Collectors;31import static java.net.HttpURLConnection.HTTP_OK;32import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;33import static org.openqa.selenium.json.Json.MAP_TYPE;34import static org.openqa.selenium.remote.http.HttpMethod.GET;35class InspectContainer {36 private static final Logger LOG = Logger.getLogger(InspectContainer.class.getName());37 private static final Json JSON = new Json();38 private final HttpHandler client;39 public InspectContainer(HttpHandler client) {40 this.client = Require.nonNull("HTTP client", client);41 }42 @SuppressWarnings("unchecked")43 public ContainerInfo apply(ContainerId id) {44 Require.nonNull("Container id", id);45 HttpResponse res = client.execute(46 new HttpRequest(GET, String.format("/v%s/containers/%s/json", DOCKER_API_VERSION, id))47 .addHeader("Content-Length", "0")48 .addHeader("Content-Type", "text/plain"));49 if (res.getStatus() != HTTP_OK) {50 LOG.warning("Unable to inspect container " + id);51 }52 Map<String, Object> rawInspectInfo = JSON.toType(Contents.string(res), MAP_TYPE);53 Map<String, Object> networkSettings =54 (Map<String, Object>) rawInspectInfo.get("NetworkSettings");55 Map<String, Object> networks = (Map<String, Object>) networkSettings.get("Networks");56 Map.Entry<String, Object> firstNetworkEntry = networks.entrySet().iterator().next();57 Map<String, Object> networkValues = (Map<String, Object>) firstNetworkEntry.getValue();58 String networkName = firstNetworkEntry.getKey();59 String ip = networkValues.get("IPAddress").toString();60 ArrayList<Object> mounts = (ArrayList<Object>) rawInspectInfo.get("Mounts");61 List<Map<String, Object>> mountedVolumes = mounts62 .stream()63 .map(mount -> (Map<String, Object>) mount)64 .collect(Collectors.toList());65 return new ContainerInfo(id, ip, mountedVolumes, networkName);66 }67}...