WinRM Java Client 2.0.00
-
Home
- Usage
Timeouts and Errors
Timeouts
Timeouts are java.time.Duration values and must be at least one millisecond. The builder's timeout(...) sets the default for every operation (30 seconds when unset), and each operation can override it:
try (WinRMClient client = WinRMClient.builder("server.example.com")
.credentials("DOMAIN\\Administrator", password)
.timeout(Duration.ofSeconds(30)) // client default
.build()) {
client.wql("SELECT * FROM Win32_NTLogEvent")
.timeout(Duration.ofMinutes(2)) // this query only
.execute();
}
The timeout is a wall-clock deadline for the whole operation: it covers authentication (on the first operation), every WSMan round trip, and — for commands — the file uploads, all budgeted against the same deadline. When it elapses, the operation fails with WinRMTimeoutException[1] and no part of it (in particular: the command itself) runs afterward.
The timeout also drives the wire-level behavior: the WSMan OperationTimeout header and the socket timeouts follow each operation's own deadline.
Streaming terminals: inactivity timeout
The streaming terminals — stream() on a WQL request and start() on a command (see WQL Queries[2] and Remote Commands[3]) — interpret the same timeout(...) value differently, because an overall deadline would make long-running streams impossible: there it is an inactivity timeout, the longest silence tolerated from the server between two responses. A query result can be consumed, or a command can keep streaming output, for arbitrarily long — but as soon as the server stays silent for a whole timeout, the operation fails with WinRMTimeoutException[1]. For commands, RemoteProcess.waitFor(Duration) provides an overall deadline on top when one is needed.
The exception surface
The fluent API is unchecked: every failure is a WinRMClientException[4], with subtypes for the cases worth catching specifically:
| Exception | Meaning |
|---|---|
WinRMAuthenticationException[5] |
The credentials were rejected (after every scheme of an ordered fallback list). |
WinRMFaultException[6] |
The remote service answered with a WSMan fault. |
WinRMTimeoutException[1] |
The operation exceeded its timeout. |
WqlSyntaxException[7] |
The WQL query does not match the supported SELECT syntax. |
WinRMClientException[4] |
Base type: any other failure (connection, DNS, TLS, protocol, local I/O). |
IllegalArgumentException (invalid option values) and IllegalStateException (missing credentials at build(), or an operation on a closed client) report programming errors immediately, before anything touches the network.
Fault detail
WinRMFaultException[6] exposes the fault programmatically, so no message parsing is needed:
| Method | Returns |
|---|---|
getFaultCode() |
The numeric WSManFault code, e.g. 2150858778. |
getFaultReason() |
The SOAP fault reason text. |
getFaultDetail() |
The provider-level detail — where WMI puts mnemonics such as WBEM_E_INVALID_CLASS or WBEM_E_INVALID_NAMESPACE. |
getHttpStatus() |
The HTTP status of the faulting response (typically 500). |
The exception message still carries the same text as the legacy API, so message-based matching keeps working.
Authentication failures
A rejected credential surfaces as a WinRMAuthenticationException[5] whose message has the stable form Authentication error on <endpoint> with user name "<user>".
The legacy API
The legacy static helpers[8] keep their historical checked exceptions (WinRMException, WqlQuerySyntaxException, TimeoutException, IOException); they are unaffected by the unchecked hierarchy above.
Command-line exit codes
The standalone jar maps these outcomes to stable process exit codes — see the Command-Line Client[9] manual.
See also
- Preparing the Windows Host[10] — a symptom-to-cause table for host-side causes: WinRM disabled, a closed firewall, UAC token filtering, and missing WMI rights
- Authentication[11] — how authentication failures are reported
- [1] apidocs/org/metricshub/winrm/exceptions/WinRMTimeoutException.html
- [2] wql.html
- [3] commands.html
- [4] apidocs/org/metricshub/winrm/exceptions/WinRMClientException.html
- [5] apidocs/org/metricshub/winrm/exceptions/WinRMAuthenticationException.html
- [6] apidocs/org/metricshub/winrm/exceptions/WinRMFaultException.html
- [7] apidocs/org/metricshub/winrm/exceptions/WqlSyntaxException.html
- [8] legacy.html
- [9] cli.html
- [10] preparing-the-host.html
- [11] authentication.html
