Class CustomTransport

java.lang.Object
cn.ucloud.common.transport.CustomTransport
All Implemented Interfaces:
Transport, Closeable, AutoCloseable

public class CustomTransport extends Object implements Transport
CustomTransport extends DefaultTransport to support custom HTTP headers

This transport implementation allows adding custom HTTP headers to all requests, which is useful for scenarios like channel identification, custom authentication, etc.

  • Constructor Details

    • CustomTransport

      public CustomTransport(String baseUrl, String userAgent)
  • Method Details

    • addCustomHeader

      public void addCustomHeader(String name, String value)
      Add a custom HTTP header to all requests
      Parameters:
      name - header name
      value - header value
    • removeCustomHeader

      public void removeCustomHeader(String name)
      Remove a custom HTTP header
      Parameters:
      name - header name
    • getCustomHeaders

      public Map<String,String> getCustomHeaders()
      Get all custom headers
      Returns:
      map of custom headers
    • invoke

      public Response invoke(Request request, Class<? extends Response> clazz) throws UCloudException
      Specified by:
      invoke in interface Transport
      Parameters:
      request - Request payload with data
      clazz - Response class without data
      Returns:
      Response
      Throws:
      UCloudException - exception
    • getBaseUrl

      public String getBaseUrl()
    • setBaseUrl

      public void setBaseUrl(String baseUrl)
    • getUserAgent

      public String getUserAgent()
    • setUserAgent

      public void setUserAgent(String userAgent)
    • getHttpClient

      public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
    • setHttpClient

      public void setHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException