@ThreadSafe public abstract class AbstractBceClient extends Object
Responsible for basic client capabilities that are the same across all BCE SDK Java clients (ex: setting the client endpoint).
Subclass names should be in the form of "com.baidubce.services.xxx.XxxClient", while "xxx" is the service ID and "Xxx" is the capitalized service ID.
| Modifier and Type | Field and Description |
|---|---|
protected BceClientConfiguration |
config
The client configuration for this client.
|
static String |
DEFAULT_CONTENT_TYPE
The default http request content type for all BCE service APIs.
|
static String |
DEFAULT_ENCODING
The default string encoding for all BCE service APIs.
|
static String |
DEFAULT_SERVICE_DOMAIN
The default service domain for BCE.
|
static String |
URL_PREFIX
The common URL prefix for all BCE service APIs.
|
| Constructor and Description |
|---|
AbstractBceClient(BceClientConfiguration config,
HttpResponseHandler[] responseHandlers)
Equivalent to AbstractBceClient(config, responseHandlers, false)
|
AbstractBceClient(BceClientConfiguration config,
HttpResponseHandler[] responseHandlers,
boolean isHttpAsyncPutEnabled)
Constructs a new AbstractBceClient with the specified client configuration and handlers.
|
| Modifier and Type | Method and Description |
|---|---|
protected URI |
buildHostEndpoint(URI originalEndpoint,
String hostPrefix)
根据 hostPrefix 构建新的 endpoint
|
void |
computeBktVirEndpoint(String bucketName)
BOS
|
String |
computeServiceId()
Returns the service ID based on the actual class name.
|
protected InternalRequest |
createRequest(AbstractBceRequest bceRequest,
HttpMethodName httpMethod,
SignOptions signOptions,
String... pathVariables)
创建内部请求对象,自动处理 @Host 注解,并支持自定义签名选项
|
protected InternalRequest |
createRequest(AbstractBceRequest bceRequest,
HttpMethodName httpMethod,
String... pathVariables)
创建内部请求对象,自动处理 @Host 注解
|
protected String |
extractHostAnnotationValue(AbstractBceRequest bceRequest)
从请求对象中提取 @Host 注解字段的值
|
URI |
getBktVirEndpoint(String bucketName)
Returns the service endpoint(bucket virtual hosting) to which this client will send requests.
|
BceHttpClient |
getClient() |
URI |
getEndpoint()
Returns the service endpoint to which this client will send requests.
|
String |
getServiceId()
Returns the target service ID.
|
protected <T extends AbstractBceResponse> |
invokeHttpClient(InternalRequest request,
Class<T> responseClass)
Subclasses should invoke this method for sending request to the target service.
|
protected <T extends AbstractBceResponse> |
invokeHttpClient(InternalRequest request,
Class<T> responseClass,
HttpResponseHandler[] customHandlers)
Subclasses should invoke this method for sending request to the target service with custom handlers.
|
boolean |
isRegionSupported()
Returns true if the target service supports regions.
|
void |
setClient(BceHttpClient client) |
void |
shutdown()
Shuts down the client and releases all underlying resources.
|
public static final String DEFAULT_SERVICE_DOMAIN
public static final String URL_PREFIX
public static final String DEFAULT_ENCODING
public static final String DEFAULT_CONTENT_TYPE
protected BceClientConfiguration config
public AbstractBceClient(BceClientConfiguration config, HttpResponseHandler[] responseHandlers, boolean isHttpAsyncPutEnabled)
The constructor will extract serviceId from the class name automatically. And if there is no endpoint specified in the client configuration, the constructor will create a default one.
config - the client configuration. The constructor makes a copy of this parameter so that it is
safe to change the configuration after then.responseHandlers - a list of handlers for processing HTTP responses from services. See
BceHttpClient.execute(InternalRequest, Class, HttpResponseHandler[])isHttpAsyncPutEnabled - whether or not PUT method use Async manner.IllegalStateException - if the class name does not follow the naming convention for BCE clients.IllegalArgumentException - if the endpoint specified in the client configuration is not a valid URI.public AbstractBceClient(BceClientConfiguration config, HttpResponseHandler[] responseHandlers)
config - the client configuration. The constructor makes a copy of this parameter so that it is
safe to change the configuration after then.responseHandlers - a list of handlers for processing HTTP responses from services. See
BceHttpClient.execute(InternalRequest, Class, HttpResponseHandler[])IllegalStateException - if the class name does not follow the naming convention for BCE clients.IllegalArgumentException - if the endpoint specified in the client configuration is not a valid URI.public boolean isRegionSupported()
The result will impact the construction of default service endpoint.
public URI getEndpoint()
public String getServiceId()
public BceHttpClient getClient()
public void setClient(BceHttpClient client)
public void shutdown()
Invoking this method is NOT a must. Once it is called, no subsequent requests should be made.
protected <T extends AbstractBceResponse> T invokeHttpClient(InternalRequest request, Class<T> responseClass)
This method will add "Content-Type" and "Date" to headers with default values if not present.
T - the type of responserequest - the request to build up the HTTP request.responseClass - the response class.protected <T extends AbstractBceResponse> T invokeHttpClient(InternalRequest request, Class<T> responseClass, HttpResponseHandler[] customHandlers)
This method will add "Content-Type" and "Date" to headers with default values if not present.
T - the type of responserequest - the request to build up the HTTP request.responseClass - the response class.customHandlers - custom response handlers to use instead of the default ones.public String computeServiceId()
The class name should be in the form of "com.baidubce.services.xxx.XxxClient", while "xxx" is the service ID and "Xxx" is the capitalized service ID.
IllegalStateException - if the class name does not follow the naming convention for BCE clients.public URI getBktVirEndpoint(String bucketName)
public void computeBktVirEndpoint(String bucketName)
Returns the bucket virtual hosting service endpoint.
The endpoint will be in the form of "http(s)://
IllegalArgumentException - if the endpoint specified in the client configuration is not a valid URI.protected String extractHostAnnotationValue(AbstractBceRequest bceRequest)
此方法通过反射扫描请求对象的所有字段,查找标记了 Host 注解的字段,
并返回该字段的值。该值将被用作主机名前缀拼接到 endpoint 中。
bceRequest - 原始请求对象protected URI buildHostEndpoint(URI originalEndpoint, String hostPrefix)
将 hostPrefix 作为子域名拼接到原始 endpoint 的主机名前面。
http://bj.bcebos.commybuckethttp://mybucket.bj.bcebos.comoriginalEndpoint - 原始 endpointhostPrefix - 主机名前缀protected InternalRequest createRequest(AbstractBceRequest bceRequest, HttpMethodName httpMethod, String... pathVariables)
此方法是子类创建请求的统一入口,提供以下功能:
// 在子类 Client 中
InternalRequest internalRequest = this.createRequest(
request,
HttpMethodName.PUT,
request.getObjectName()
);
bceRequest - 原始 BCE 请求对象httpMethod - HTTP 方法pathVariables - 路径变量protected InternalRequest createRequest(AbstractBceRequest bceRequest, HttpMethodName httpMethod, SignOptions signOptions, String... pathVariables)
此方法是 createRequest(com.baidubce.model.AbstractBceRequest, com.baidubce.http.HttpMethodName, String...)
的重载版本,支持传入自定义的签名选项。
bceRequest - 原始 BCE 请求对象httpMethod - HTTP 方法signOptions - 签名选项(可选,为 null 则不设置)pathVariables - 路径变量Copyright © 2026. All rights reserved.