Module bus.http

Class Platform

java.lang.Object
org.miaixz.bus.http.accord.platform.Platform

public class Platform extends Object
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 Details

    • Platform

      public Platform()
  • Method Details

    • get

      public static Platform get()
      Returns the platform-specific implementation.
      Returns:
      The current platform.
    • alpnProtocolNames

      public static List<String> alpnProtocolNames(List<org.miaixz.bus.core.net.Protocol> protocols)
      Converts a list of Protocol objects to a list of their string representations.
      Parameters:
      protocols - The list of protocols.
      Returns:
      A list of protocol names.
    • getPrefix

      public String getPrefix()
      Returns the prefix used in custom headers.
      Returns:
      The prefix string.
    • trustManager

      protected X509TrustManager trustManager(SSLSocketFactory sslSocketFactory)
      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 the sslSocket for the given route.
      Parameters:
      sslSocket - The SSL socket.
      hostname - The hostname for client-side handshakes; null for server-side.
      protocols - The supported protocols.
    • afterHandshake

      public void afterHandshake(SSLSocket sslSocket)
      Parameters:
      sslSocket - The SSL socket.
    • getSelectedProtocol

      public String getSelectedProtocol(SSLSocket socket)
      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

      public boolean isCleartextTrafficPermitted(String hostname)
      Returns true if cleartext traffic is permitted for the given hostname.
      Parameters:
      hostname - The hostname to check.
      Returns:
      true if cleartext traffic is permitted.
    • getStackTraceForCloseable

      public Object getStackTraceForCloseable(String closer)
      Returns an object that holds a stack trace created at the time this method was called. Used for debugging Closeable leaks with logCloseableLeak(String, Object).
      Parameters:
      closer - A string describing the closeable resource.
      Returns:
      An object holding the stack trace.
    • logCloseableLeak

      public void logCloseableLeak(String message, Object stackTrace)
      Logs a message about a leaked closeable resource.
      Parameters:
      message - The message to log.
      stackTrace - An object holding the stack trace, created by getStackTraceForCloseable(String).
    • buildCertificateChainCleaner

      public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager trustManager)
      Builds a certificate chain cleaner for the given trust manager.
      Parameters:
      trustManager - The trust manager.
      Returns:
      A certificate chain cleaner.
    • buildCertificateChainCleaner

      public CertificateChainCleaner buildCertificateChainCleaner(SSLSocketFactory sslSocketFactory)
      Builds a certificate chain cleaner for the given SSL socket factory.
      Parameters:
      sslSocketFactory - The SSL socket factory.
      Returns:
      A certificate chain cleaner.
    • buildTrustRootIndex

      public TrustRootIndex buildTrustRootIndex(X509TrustManager trustManager)
      Builds a trust root index for the given trust manager.
      Parameters:
      trustManager - The trust manager.
      Returns:
      A trust root index.
    • configureSslSocketFactory

      public void configureSslSocketFactory(SSLSocketFactory socketFactory)
      Configures the given SSL socket factory.
      Parameters:
      socketFactory - The SSL socket factory to configure.
    • toString

      public String toString()
      Overrides:
      toString in class Object