java.lang.Object
org.miaixz.bus.http.accord.platform.Platform
Provides access to platform-specific features.
This class abstracts away differences in Java and Android runtimes, providing a consistent API for features like TLS extensions (SNI, ALPN), trust manager extraction, and network security policy checks.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterHandshake(SSLSocket sslSocket) Called after the TLS handshake to release any resources allocated byconfigureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List<org.miaixz.bus.core.net.Protocol>).alpnProtocolNames(List<org.miaixz.bus.core.net.Protocol> protocols) Converts a list ofProtocolobjects to a list of their string representations.buildCertificateChainCleaner(SSLSocketFactory sslSocketFactory) Builds a certificate chain cleaner for the given SSL socket factory.buildCertificateChainCleaner(X509TrustManager trustManager) Builds a certificate chain cleaner for the given trust manager.buildTrustRootIndex(X509TrustManager trustManager) Builds a trust root index for the given trust manager.voidconfigureSslSocketFactory(SSLSocketFactory socketFactory) Configures the given SSL socket factory.voidconfigureTlsExtensions(SSLSocket sslSocket, String hostname, List<org.miaixz.bus.core.net.Protocol> protocols) Configures TLS extensions on thesslSocketfor the givenroute.voidconnectSocket(Socket socket, InetSocketAddress address, int connectTimeout) Connects the given socket to the specified address.static Platformget()Returns the platform-specific implementation.Returns the prefix used in custom headers.getSelectedProtocol(SSLSocket socket) Returns the negotiated protocol, or null if no protocol was negotiated.getStackTraceForCloseable(String closer) Returns an object that holds a stack trace created at the time this method was called.booleanisCleartextTrafficPermitted(String hostname) Returns true if cleartext traffic is permitted for the given hostname.voidlogCloseableLeak(String message, Object stackTrace) Logs a message about a leaked closeable resource.toString()protected X509TrustManagertrustManager(SSLSocketFactory sslSocketFactory) Manages which X.509 certificates can be used to authenticate the remote end of a secure socket.
-
Constructor Details
-
Platform
public Platform()
-
-
Method Details
-
get
Returns the platform-specific implementation.- Returns:
- The current platform.
-
alpnProtocolNames
Converts a list ofProtocolobjects to a list of their string representations.- Parameters:
protocols- The list of protocols.- Returns:
- A list of protocol names.
-
getPrefix
Returns the prefix used in custom headers.- Returns:
- The prefix string.
-
trustManager
Manages which X.509 certificates can be used to authenticate the remote end of a secure socket. Decisions may be based on trusted certificate authorities, certificate revocation lists, online status checks, or other methods.- Parameters:
sslSocketFactory- The SSL socket factory.- Returns:
- The trust manager.
-
configureTlsExtensions
public void configureTlsExtensions(SSLSocket sslSocket, String hostname, List<org.miaixz.bus.core.net.Protocol> protocols) Configures TLS extensions on thesslSocketfor the givenroute.- Parameters:
sslSocket- The SSL socket.hostname- The hostname for client-side handshakes; null for server-side.protocols- The supported protocols.
-
afterHandshake
Called after the TLS handshake to release any resources allocated byconfigureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List<org.miaixz.bus.core.net.Protocol>).- Parameters:
sslSocket- The SSL socket.
-
getSelectedProtocol
Returns the negotiated protocol, or null if no protocol was negotiated.- Parameters:
socket- The socket.- Returns:
- The negotiated protocol.
-
connectSocket
public void connectSocket(Socket socket, InetSocketAddress address, int connectTimeout) throws IOException Connects the given socket to the specified address.- Parameters:
socket- The socket to connect.address- The address to connect to.connectTimeout- The connection timeout in milliseconds.- Throws:
IOException- if an I/O error occurs.
-
isCleartextTrafficPermitted
Returns true if cleartext traffic is permitted for the given hostname.- Parameters:
hostname- The hostname to check.- Returns:
trueif cleartext traffic is permitted.
-
getStackTraceForCloseable
Returns an object that holds a stack trace created at the time this method was called. Used for debuggingCloseableleaks withlogCloseableLeak(String, Object).- Parameters:
closer- A string describing the closeable resource.- Returns:
- An object holding the stack trace.
-
logCloseableLeak
Logs a message about a leaked closeable resource.- Parameters:
message- The message to log.stackTrace- An object holding the stack trace, created bygetStackTraceForCloseable(String).
-
buildCertificateChainCleaner
Builds a certificate chain cleaner for the given trust manager.- Parameters:
trustManager- The trust manager.- Returns:
- A certificate chain cleaner.
-
buildCertificateChainCleaner
Builds a certificate chain cleaner for the given SSL socket factory.- Parameters:
sslSocketFactory- The SSL socket factory.- Returns:
- A certificate chain cleaner.
-
buildTrustRootIndex
Builds a trust root index for the given trust manager.- Parameters:
trustManager- The trust manager.- Returns:
- A trust root index.
-
configureSslSocketFactory
Configures the given SSL socket factory.- Parameters:
socketFactory- The SSL socket factory to configure.
-
toString
-