Skip to content

Commit 3ac04fb

Browse files
committed
Support for default port in service address
1 parent 4ae1024 commit 3ac04fb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

winrm4j/src/main/java/io/cloudsoft/winrm4j/winrm/WinRmTool.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public WinRmToolResponse executeScript(List<String> commands) {
3030
}
3131

3232
public WinRmToolResponse executeScript(String commands) {
33-
// TODO better support for address formats, host:port required
34-
Builder builder = WinRmClient.builder("http://" + address + "/wsman");
33+
Builder builder = WinRmClient.builder(getEndpointUrl());
3534
if (username != null && password != null) {
3635
builder.credentials(username, password);
3736
}
@@ -48,6 +47,17 @@ public WinRmToolResponse executeScript(String commands) {
4847
}
4948
}
5049

50+
//TODO support https transport
51+
private String getEndpointUrl() {
52+
if (address.startsWith("http:") || address.startsWith("https:")) {
53+
return address;
54+
} else if (address.contains(":")) {
55+
return "http://" + address + "/wsman";
56+
} else {
57+
return "http://" + address + ":5985/wsman";
58+
}
59+
}
60+
5161
public WinRmToolResponse executePs(List<String> commands) {
5262
return executeScript(compilePs(joinPs(commands)));
5363
}

0 commit comments

Comments
 (0)