Package org.metricshub.winrm
Class WinRMClient.Builder
java.lang.Object
org.metricshub.winrm.WinRMClient.Builder
- Enclosing class:
- WinRMClient
Builder of
WinRMClient instances: connection-scoped settings with sensible
defaults. Only the hostname and the credentials are mandatory.-
Method Summary
Modifier and TypeMethodDescriptionauthentication(AuthScheme... schemes) Set the authentication schemes, tried in the given order until one succeeds.build()Build the client.consoleCodePage(int consoleCodePage) Set the console code page of the remote command shell.credentials(String username, char[] password) Set the credentials (mandatory).http()Connect over HTTP (port 5985 unlessport(int)is set) — the default.https()Connect over HTTPS (port 5986 unlessport(int)is set).Set the default WMI namespace for WQL queries.port(int port) Set the port.sslContext(SSLContext sslContext) Use a customSSLContextfor HTTPS — e.g. one built around a dedicated trust store.ticketCache(Path ticketCache) Set the Kerberos ticket cache path.Set the default timeout of every operation — a wall-clock deadline covering authentication, every WSMan round trip, and result collection.Trust every server certificate and skip hostname verification over HTTPS — for self-signed test hosts.
-
Method Details
-
https
Connect over HTTPS (port 5986 unlessport(int)is set). The server certificate is validated against the platform trust store and the hostname is verified, unlesstrustAllCertificates()orsslContext(SSLContext)says otherwise.- Returns:
- this builder
-
http
Connect over HTTP (port 5985 unlessport(int)is set) — the default. The SOAP messages are NTLM-encrypted on the wire.- Returns:
- this builder
-
port
Set the port. Default: 5985 for HTTP, 5986 for HTTPS.- Parameters:
port- the TCP port (1-65535)- Returns:
- this builder
-
credentials
Set the credentials (mandatory).- Parameters:
username- the user name, plain (user) or domain-qualified (DOMAIN\\user)password- the password; the array is deliberately not copied, so the caller can wipe the single authoritative copy of the secret after closing the client- Returns:
- this builder
-
namespace
Set the default WMI namespace for WQL queries. Default:ROOT\CIMV2. Each query can override it withWqlRequest.namespace(String).- Parameters:
namespace- the WMI namespace- Returns:
- this builder
-
authentication
Set the authentication schemes, tried in the given order until one succeeds. Default: NTLM only. Kerberos requires HTTPS.- Parameters:
schemes- the schemes in fallback order, e.g.KERBEROS, NTLM- Returns:
- this builder
-
ticketCache
Set the Kerberos ticket cache path. Default: none — Kerberos logs in with the password.- Parameters:
ticketCache- the ticket cache path- Returns:
- this builder
-
trustAllCertificates
Trust every server certificate and skip hostname verification over HTTPS — for self-signed test hosts. Insecure: do not use in production. This per-client setting replaces the globalorg.metricshub.winrm.tls.insecuresystem property.- Returns:
- this builder
-
sslContext
Use a customSSLContextfor HTTPS — e.g. one built around a dedicated trust store. Hostname verification stays on. Mutually exclusive withtrustAllCertificates().- Parameters:
sslContext- the TLS context providing the socket factory- Returns:
- this builder
-
timeout
Set the default timeout of every operation — a wall-clock deadline covering authentication, every WSMan round trip, and result collection. Default: 30 seconds. Each operation can override it.- Parameters:
timeout- the timeout (at least one millisecond)- Returns:
- this builder
-
consoleCodePage
Set the console code page of the remote command shell. Default: 65001 (UTF-8), which makes command output UTF-8 whatever the remote locale — the right choice for reading output and for piping data to a program.An interactive session needs a different setting: under code page 65001 a remote
cmd.exedecodes the command lines it reads from its standard input one byte at a time, so every non-ASCII character is lost. Pin a single-byte code page (typically the remote machine's ANSI one,Win32_OperatingSystem.CodeSet) and use the matching charset for both directions, as the CLI'sshellsubcommand does.- Parameters:
consoleCodePage- the console code page (e.g. 1252), or 0 for the default- Returns:
- this builder
-
build
Build the client. This does not connect yet: the connection is established and authenticated by the first operation.- Returns:
- the client, to use with try-with-resources
- Throws:
WinRMClientException- when the configuration is rejected (e.g. Kerberos requested over HTTP)
-