Initialization
BlbClient is a Java client for the Blb service, which is used to manage BLB resources. To initiate a BLB request using the Java SDK, you need to initialize a BlbClient instance and modify the default configuration items of BlbClientConfiguration as needed.
Confirm Endpoint
When confirming the Endpoint configured when you use the SDK, you can first read the section on BLB Access Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently supports multi-regions. Please see Region Selection Instructions.
Currently support the regions of "Beijing", "Guangzhou", "Suzhou", "Hong Kong", "Wuhan" and "Baoding".
The corresponding information of the service domain name is:
Access region | Corresponding Endpoint |
---|---|
bj | blb.bj.baidubce.com |
gz | blb.gz.baidubce.com |
su | blb.su.baidubce.com |
hkg | blb.hkg.baidubce.com |
fwh | blb.fwh.baidubce.com |
bd | blb.bd.baidubce.com |
New BlbClient
Create BlbClient Using AK/SK
To access BLB through AK/SK, users can see the following code to create a BlbClient:
public class Sample {
public static void main(String[] args) {
String ACCESS_KEY_ID =<your-access-key-id>; // User's Access Key ID
String SECRET_ACCESS_KEY =<your-secret-access-key>; // User's Secret Access Key
// Initialize a BlbClient
BlbClientConfiguration config = new BlbClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
BlbClient client = new BlbClient(config);
}
}
In the above code, ACCESS_KEY_ID
corresponds to the "Access Key ID" in the console, and SECRET_ACCESS_KEY
corresponds to the "Access Key Secret" in the console. For how to obtain it, please see <ACCESSKEY Management in the Operation Guide>.
The above method uses the default domain name as the service address of the BLB. If the user needs to specify the domain name himself, he can specify it by passing in the ENDPOINT parameter.
String ACCESS_KEY_ID =<your-access-key-id>; // User's Access Key ID
String SECRET_ACCESS_KEY =<your-secret-access-key>; // User's Secret Access Key
String ENDPOINT =<domain-name>; // User-specified domain name
BlbClientConfiguration config = new BlbClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY));
config.setEndpoint(ENDPOINT);
BlbClient client = new BlbClient(config);
Note: The
ENDPOINT
parameter can only be defined with the specified domain name of the areas included. If not specified, it defaults to the Beijing area (http://blb.bj.baidubce.com
).
Set Network Parameters
Users can set basic network parameters with BlbClientConfiguration:
BlbClientConfiguration config = new BlbClientConfiguration();
// Set the maximum number of HTTP connections to 10.
config.setMaxConnections(10);
// Set TCP connection timeout to 5,000 milliseconds
config.setConnectionTimeout(5000);
// Set the timeout for socket data transmission to 2,000 milliseconds
config.setSocketTimeout(2000);
Parameter Description
All parameters that can be specified through BlbClientConfiguration are shown in the following table:
Parameter | Description |
---|---|
UserAgent | User agent, referring to the HTTP User-Agent header |
Protocol | Connection protocol type |
ProxyDomain | Windows domain name for access to NTLM verified proxy server |
ProxyHost | Proxy server host address |
ProxyPort | Proxy server port |
ProxyUsername | User name for proxy server authentication |
ProxyPassword | Password for proxy server authentication |
ProxyPreemptiveAuthenticationEnabled | Whether to set up user agent authentication |
ProxyWorkstation | Windows workstation name of the NTLM proxy server |
LocalAddress | Local address |
ConnectionTimeoutInMillis | Timeout for establishing a connection (unit: millisecond) |
SocketTimeoutInMillis | Timeout for transmitting data over open connections (unit: millisecond) |
MaxConnections | Maximum number of HTTP connections allowed to open |
RetryPolicy | Connection retry policy |
SocketBufferSizeInBytes | Socket buffer size |
StreamBufferSize | Stream file buffer size |