com.aliyuncs.exceptions.ServerException Java Examples

The following examples show how to use com.aliyuncs.exceptions.ServerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: STSServiceImpl.java    From jframe with Apache License 2.0 6 votes vote down vote up
AssumeRoleResponse assumeRole(String id, String roleArn, String roleSessionName, String policy, ProtocolType protocolType)
        throws ServerException, com.aliyuncs.exceptions.ClientException {
    DefaultAcsClient client = clients.get(id);

    // 创建一个 AssumeRoleRequest 并设置请求参数
    final AssumeRoleRequest request = new AssumeRoleRequest();
    request.setVersion(_config.getConf(id, K_api_version));
    request.setMethod(MethodType.POST);
    request.setProtocol(protocolType);

    request.setRoleArn(roleArn);
    request.setRoleSessionName(roleSessionName);
    request.setPolicy(policy);

    request.setDurationSeconds(Long.parseLong(_config.getConf(id, K_durationSeconds, "3600"))); // 默认值为3600

    // 发起请求,并得到response
    final AssumeRoleResponse response = client.getAcsResponse(request);
    // client.shutdown();

    return response;
}