public abstract class AbstractClient extends Object
Modifier and Type | Field and Description |
---|---|
com.google.gson.Gson |
gson |
static int |
HTTP_RSP_OK |
static String |
SDK_VERSION |
Constructor and Description |
---|
AbstractClient(String endpoint,
String version,
Credential credential,
String region)
Constructor for AbstractClient with default client profile.
|
AbstractClient(String endpoint,
String version,
Credential credential,
String region,
ClientProfile profile)
Constructor for AbstractClient with a custom client profile.
|
Modifier and Type | Method and Description |
---|---|
String |
call(String action,
String jsonPayload)
Calls an API action with JSON payload using the TC3-HMAC-SHA256 signature.
|
String |
callOctetStream(String action,
HashMap<String,String> headers,
byte[] body)
Calls an API action with binary payload using the TC3-HMAC-SHA256 signature.
|
ClientProfile |
getClientProfile()
Gets the client profile.
|
Credential |
getCredential()
Gets the credential.
|
String |
getRegion()
Gets the region.
|
CircuitBreaker |
getRegionBreaker() |
protected String |
internalRequest(AbstractModel request,
String actionName)
Executes an API request and returns the raw string response.
|
protected <T> T |
internalRequest(AbstractModel request,
String actionName,
Class<T> typeOfT)
Executes an API request and returns the deserialized response object.
|
protected okhttp3.Response |
internalRequestRaw(AbstractModel request,
String actionName)
Executes the raw API request and returns the HTTP Response object.
|
protected <T> T |
processResponseJson(okhttp3.Response resp,
Class<T> typeOfT,
CircuitBreaker.Token breakerToken)
Processes a JSON response.
|
protected <T> T |
processResponseSSE(okhttp3.Response resp,
Class<T> typeOfT,
CircuitBreaker.Token breakerToken)
Processes a Server-Sent Events (SSE) response.
|
Object |
retry(AbstractModel req,
int retryTimes)
请注意购买类接口谨慎调用,可能导致多次购买
仅幂等接口推荐使用
|
void |
setClientProfile(ClientProfile profile)
Sets the client profile.
|
void |
setCredential(Credential credential)
Sets the credential.
|
void |
setRegion(String region)
Sets the region.
|
void |
setRegionBreaker(CircuitBreaker regionBreaker) |
public static final int HTTP_RSP_OK
public static final String SDK_VERSION
public com.google.gson.Gson gson
public AbstractClient(String endpoint, String version, Credential credential, String region)
endpoint
- API endpoint URL.version
- API version.credential
- User credentials.region
- Region.public AbstractClient(String endpoint, String version, Credential credential, String region, ClientProfile profile)
endpoint
- API endpoint URL.version
- API version.credential
- User credentials.region
- Region.profile
- Client configuration profile.public String getRegion()
public void setRegion(String region)
region
- The region to set.public ClientProfile getClientProfile()
public void setClientProfile(ClientProfile profile)
profile
- The client profile to set.public Credential getCredential()
public void setCredential(Credential credential)
credential
- The credential to set.public String call(String action, String jsonPayload) throws TencentCloudSDKException
action
- Name of the API action.jsonPayload
- JSON string containing the request parameters.TencentCloudSDKException
- If an error occurs during the API call.public String callOctetStream(String action, HashMap<String,String> headers, byte[] body) throws TencentCloudSDKException
action
- Name of the API action.headers
- HTTP headers to include in the request.body
- Binary payload (octet-stream).TencentCloudSDKException
- If an error occurs during the API call.protected String internalRequest(AbstractModel request, String actionName) throws TencentCloudSDKException
request
- The request object containing API parameters.actionName
- The name of the API action to be called.TencentCloudSDKException
- If an error occurs during the API call.protected <T> T internalRequest(AbstractModel request, String actionName, Class<T> typeOfT) throws TencentCloudSDKException
T
- The type of the response object.request
- The request object containing API parameters.actionName
- The name of the API action to be called.typeOfT
- The class of the response object to deserialize to.TencentCloudSDKException
- If an error occurs during the API call.protected <T> T processResponseSSE(okhttp3.Response resp, Class<T> typeOfT, CircuitBreaker.Token breakerToken) throws TencentCloudSDKException
T
- The type of the response model.resp
- The raw HTTP response.typeOfT
- The class of the response model.breakerToken
- The circuit breaker token.TencentCloudSDKException
- If an error occurs during processing.protected <T> T processResponseJson(okhttp3.Response resp, Class<T> typeOfT, CircuitBreaker.Token breakerToken) throws TencentCloudSDKException
T
- The type of the response object.resp
- The raw HTTP response.typeOfT
- The class of the response object to deserialize to.breakerToken
- The circuit breaker token.TencentCloudSDKException
- If an error occurs during processing.protected okhttp3.Response internalRequestRaw(AbstractModel request, String actionName) throws TencentCloudSDKException, IOException
request
- The request object containing API parameters.actionName
- The name of the API action to be called.TencentCloudSDKException
- If an error occurs during the API call.IOException
- If an I/O error occurs.public Object retry(AbstractModel req, int retryTimes) throws TencentCloudSDKException
req
- retryTimes
- TencentCloudSDKException
public CircuitBreaker getRegionBreaker()
public void setRegionBreaker(CircuitBreaker regionBreaker)
Copyright © 2025. All rights reserved.