更新时间:2024-04-30 GMT+08:00
分享

查询独立加密任务

说明

  • 查询独立加密任务,支持根据任务ID查询、任务状态、时间段、分页查询和复合查询。
  • 在查询到的结果集中,如果不提供页码数page和显示条数size并且数据大于10条时,会默认显示10条数据并进行分页处理。

根据任务ID查询

1
2
3
4
5
6
//根据任务ID查询,最多支持10个任务ID
ListEncryptTaskRequest req = new ListEncryptTaskRequest().withTaskId(Collections.singletonList("3223179"));
// 向MPC发送查询独立加密任务的请求
ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);   
// 打印返回消息         
System.out.println(rsp.toString());

分页查询

1
2
3
4
5
6
// 分页查询
ListEncryptTaskRequest req = new ListEncryptTaskRequest().withPage(1).withSize(4);
// 向MPC发送查询独立加密任务的请求
ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);   
// 打印返回消息         
System.out.println(rsp.toString());

根据时间段查询

1
2
3
4
5
6
// 根据时间段查询
ListEncryptTaskRequest req = new ListEncryptTaskRequest().withStartTime("20201220131400").withEndTime("20201221131400");
// 向MPC发送查询独立加密任务的请求
ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);   
// 打印返回消息         
System.out.println(rsp.toString());

根据任务状态查询

1
2
3
4
5
6
// 根据任务的状态查询
ListEncryptTaskRequest req = new ListEncryptTaskRequest().withStatus(ListEncryptTaskRequest.StatusEnum.FAILED);
// 向MPC发送查询独立加密任务的请求
ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);   
// 打印返回消息         
System.out.println(rsp.toString());

复合查询

1
2
3
4
5
6
7
8
// 复合查询
ListEncryptTaskRequest req = new ListEncryptTaskRequest().withPage(1).withSize(4)
        .withStartTime("20201220131400").withEndTime("20201221131400")
        .withStatus(ListEncryptTaskRequest.StatusEnum.FAILED);
// 向MPC发送查询独立加密任务的请求
ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);   
// 打印返回消息         
System.out.println(rsp.toString());

完整代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.mpc.v1.MpcClient;
import com.huaweicloud.sdk.mpc.v1.model.ListEncryptTaskRequest;
import com.huaweicloud.sdk.mpc.v1.model.ListEncryptTaskResponse;
import com.obs.services.internal.ServiceException;

public class TestListEncrypt {
    /**
     * 初始化 MpcClient
     * @return
     */
    public static MpcClient initMpcClient() {
        HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig().withIgnoreSSLVerification(true).withTimeout(3);
        //http代理设置,请根据实际情况设置
        //httpConfig.withProxyHost("xxxxxx").withProxyPort(xxxxxx).withProxyUsername("xxxxxx").
        //        withProxyPassword("xxxxxx");
        //根据实际填写ak,sk,在控制台账号名下“我的凭证 > 访问密钥”上创建和查看您的AK/SK
        
        String ak = System.getenv("SDK_AK");
        String sk = System.getenv("SDK_SK");
        //根据实际填写项目ID,在控制台账号名下“我的凭证 > API凭证”下查看您的项目ID
        String projectId = System.getenv("PROJECT_ID");
        //根据实际填写所需endpoint,这里以“region01”为例
        String endpoint = "https://mpc.region01.myhuaweicloud.com";
        BasicCredentials auth = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);
        return MpcClient.newBuilder()
                .withHttpConfig(httpConfig)
                .withCredential(auth)
                .withEndpoint(endpoint)
                .build();
    }

    /**
     * 查询加密任务
     * @param args
     */
    public static void main(String[] args) {
        ListEncryptTaskRequest req = new ListEncryptTaskRequest().withPage(1).withSize(4)
                .withStartTime("20201220131400").withEndTime("20201221131400")
                .withStatus(ListEncryptTaskRequest.StatusEnum.FAILED);
        try {
            ListEncryptTaskResponse rsp = initMpcClient().listEncryptTask(req);
            System.out.println(rsp.toString());
        } catch (ClientRequestException | ConnectionException | RequestTimeoutException | ServiceException e) {
            System.out.println(e);
        }
    }
}
分享:

    相关文档

    相关产品