VPN
Retrieve Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on VPC Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to the VPC section in the Region Selection Guide. VPN service is part of the VPC service and adopts the VPC service domain name.
Retrieve AK/SK
To use Baidu AI Cloud products, you need a Baidu AI Cloud account along with valid AK (Access Key ID) and SK (Secret Access Key) credentials for signature authorization. You can obtain and understand your AK/SK information through the following steps:
Create VPN client
The VPN client acts as the interface for VPN services, offering developers various methods to interact with these services. To create a VPN client, first configure a VPN client configuration instance (config) using endpoint, AK, and SK. Then use this config instance to set up the VPN client. The specific configuration steps are as follows:
1static final String HOST = "";
2static final String AK = "";
3static final String SK = "";
4VpnClientConfiguration config = new VpnClientConfiguration();
5config.setCredentials(new DefaultBceCredentials(AK, SK));
6config.setEndpoint(HOST);
7VpnClient vpnClient = new VpnClient(config);
Create VPN gateway
Function declaration
1public CreateVpnResponse createVpn(CreateVpnRequest createVpnRequest) {
2 ......
3}
Parameter meaning
Refer to the OpenAPI documentation: Request Parameters for Creating VPN
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpnId": "vpn-ku4cxya6nisq"
4}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleCreateVpn.java
Release VPN gateway
Function declaration
1public void deleteVpn(DeleteVpnRequest deleteVpnResquest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Releasing VPN Gateway
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleDeleteVpn.java
Update VPN gateway
Function declaration
1public void updateVpn(UpdateVpnRequest updateVpnRequest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Updating VPN Gateway
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleUpdateVpn.java
Query VPN gateway list
Function declaration
1public ListVpnResponse listVpns(ListVpnRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Querying VPN Gateway List
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "nextMarker": "vpn-xktdeMSf",
4 "marker": "vpn-IyWRtII7",
5 "maxKeys": 1,
6 "isTruncated": true,
7 "vpns": [
8 {
9 "vpnId": "vpn-9c875b4065b5",
10 "vpnName": "VpnJavaSdkTest2",
11 "description": "this is a desc",
12 "status": "unconfigured",
13 "expiredTime": null,
14 "paymentTiming": "Postpaid",
15 "eip": "",
16 "tags": [
17 {
18 "tagKey": "tagKey",
19 "tagValue": "tagValue"
20 }
21 ],
22 "bandwidthInMbps": 0,
23 "vpcId": "vpc-8gc432kidqqb",
24 "vpnConnNum": 0,
25 "vpnConns": null,
26 "sslVpnServer": null,
27 "type": "SSL",
28 "maxConnection": 20,
29 "createTime": "2024-12-24 16:41:00",
30 "deleteProtect": true
31 }
32 ]
33}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleListVpn.java
Query VPN gateway details
Function declaration
1public GetVpnResponse getVpn(String vpnId) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Querying VPN Gateway Details
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpnId": "vpn-9c875b4065b5",
4 "vpnName": "VpnJavaSdkTest2",
5 "description": "this is a desc",
6 "status": "unconfigured",
7 "expiredTime": null,
8 "paymentTiming": "Postpaid",
9 "eip": "",
10 "tags": [
11 {
12 "tagKey": "tagKey",
13 "tagValue": "tagValue"
14 }
15 ],
16 "bandwidthInMbps": 0,
17 "vpcId": "vpc-8gc432kidqqb",
18 "vpnConnNum": 0,
19 "vpnConns": null,
20 "sslVpnServer": null,
21 "type": "SSL",
22 "maxConnection": 20,
23 "createTime": "2024-12-24 16:41:00",
24 "deleteProtect": true
25}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleGetVpn.java
Bind EIP to VPN gateway
Function declaration
1public void bindEip(BindEipRequest bindEipRequest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Binding EIP to VPN Gateway
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleBindEip.java
Unbind EIP from VPN gateway
Function declaration
1public void bindEip(BindEipRequest bindEipRequest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Unbinding EIP from VPN Gateway
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleUnBindEip.java
VPN gateway renewal
Function declaration
1public void renewVpn(RenewVpnRequest renewVpnRequest) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Renewing VPN Gateway
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleRenewVpn.java
Create VPN gateway tunnel
Function declaration
1public CreateVpnConnResponse createVpnConn(CreateVpnConnRequest createVpnConnRequest) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Creating VPN Gateway Tunnel
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpnConnId": "vpnconn-ku4cxya6nisq"
4}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleCreateVpnConn.java
Update VPN gateway tunnel
Function declaration
1public void updateVpnConn(UpdateVpnConnRequest updateVpnConnRequest) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Updating VPN Gateway Tunnel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleUpdateVpnConn.java
Query the VPN gateway tunnel list
Function declaration
1public ListVpnConnResponse listVpnConns(ListVpnConnRequest listVpnConnRequest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Querying VPN Gateway Tunnel List
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpnConns": [
4 {
5 "secretKey": "ddd22@www",
6 "localSubnets": ["192.168.100.0/24"],
7 "remoteIp": "10.107.245.188",
8 "remoteSubnets": ["192.168.100.0/24"],
9 "description": "111",
10 "vpnConnName": "vpncon",
11 "ikeConfig":
12 {
13 "ikeVersion": "v1",
14 "ikeMode": "main",
15 "ikeEncAlg": "aes",
16 "ikeAuthAlg": "sha1",
17 "ikePfs": "group2",
18 "ikeVersion": "v1"
19 },
20 "ipsecConfig":
21 {
22 "ipsecEncAlg": "aes",
23 "ipsecAuthAlg": "sha1",
24 "ipsecPfs": "group2",
25 "ipsecLifetime": "28800s"
26 }
27 }
28 ]
29}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleListVpnConn.java
Delete VPN gateway tunnel
Function declaration
1public void deleteVpnConn(DeleteVpnConnRequest deleteVpnConnRequest) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Deleting VPN Gateway Tunnel
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleDeleteVpnConn.java
Create SSL VPN server
Function declaration
1public CreateSslVpnServerResponse createSslVpnServer(CreateSslVpnServerRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Creating SSL-VPN Server
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "sslVpnServerId": "sslvpn-5b2hq4nm40tt"
4}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleCreateSslVpnServer.java
Query SSL-VPN server
Function declaration
1public GetSslVpnServerResponse getSslVpnServer(String vpnId) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Querying SSL-VPN Server
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpnId": "vpn-shyt1vzgqc3z",
4 "sslVpnServerId": "sslvpn-5b2hq4nm40tt",
5 "sslVpnServerName": "hzb_1_1",
6 "interfaceType": "tap",
7 "status": "active",
8 "localSubnets": ["192.168.0.0/24"],
9 "remoteSubnet": "172.168.0.0/16",
10 "maxConnection": 10,
11 "clientDns":""
12}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleGetSslVpnServer.java
Update SSL VPN server
Function declaration
1public void updateSslVpnServer(UpdateSslVpnServerRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Updating SSL-VPN Server
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleUpdateSslVpnServer.java
Delete SSL VPN server
Function declaration
1public void deleteSslVpnServer(DeleteSslVpnServerRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Deleting SSL-VPN Server
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleDeleteSslVpnServer.java
Create SSL VPN users in batches
Function declaration
1public BatchCreateSslVpnUserResponse batchCreateSslVpnUser(BatchCreateSslVpnUserRequest request) {
2 ......
3}
Parameter meaning
Refer to OpenAPI documentation: Request Parameters for Creating SSL-VPN Users in Batches
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "sslVpnUserIds": ["vpn-ssl-user-d4fwdu3dw0m8"]
4}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleBatchCreateSslVpnUser.java
Update SSL VPN user
Function declaration
1public void updateSslVpnUser(UpdateSslVpnUserRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Updating SSL-VPN User
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleUpdateSslVpnUser.java
Query SSL-VPN user list
Function declaration
1public ListSslVpnUserResponse getSslVpnUser(ListSslVpnUserRequest request) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Querying SSL-VPN User List
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "marker": "vpn-ssl-user-xynkefqf3n5x",
4 "maxKeys": 1,
5 "isTruncated": false,
6 "sslVpnUsers": [
7 {
8 "userId": "vpn-ssl-user-xynkefqf3n5x",
9 "userName": "user",
10 "description": "desc"
11 }
12 ]
13}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleGetSslVpnUser.java
Delete SSL VPN user
Function declaration
1public void deleteSslVpnUser(DeleteSslVpnUserRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Deleting SSL-VPN User
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to ExampleDeleteSslVpnUser.java
Appendix
Public response information in Metadata format
1 {
2 "bceRequestId":"f5f0821d-45fe-439b-bbf4-fc48b639f84a",
3 "contentLength":28,
4 "contentType":"application/json;charset=UTF-8",
5 "date":1701917695000,
6 "server":"openresty/1.15.8.1"
7 }
