• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClientException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.aliyuncs.exceptions.ClientException的典型用法代码示例。如果您正苦于以下问题:Java ClientException类的具体用法?Java ClientException怎么用?Java ClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientException类属于com.aliyuncs.exceptions包,在下文中一共展示了ClientException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: performRequest

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
protected HttpResponse performRequest(IAcsClient client, RpcAcsRequest request) throws IOException {
    HttpResponse response = null;
    X509TrustAll.ignoreSSLCertificate();
    try {
        long time = System.currentTimeMillis();
        if (PhotoStoreClient.getInstance().isLogin()) {
            response = client.doAction(request);
        }
        long escape = System.currentTimeMillis() - time;
        Log.d(TAG, request.getActionName() + " response time: " + escape + "ms");
    } catch (ClientException e) {
        e.printStackTrace();
    }

    return response;
}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:17,代码来源:BaseRequestTask.java


示例2: assumeRole

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,String roleArn, String roleSessionName, String policy,ProtocolType protocolType) throws ClientException {
	try {
		// 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
		IClientProfile profile = DefaultProfile.getProfile(region_cn_hangzhou, accessKeyId, accessKeySecret);
		DefaultAcsClient client = new DefaultAcsClient(profile);
		// 创建一个 AssumeRoleRequest 并设置请求参数
		final AssumeRoleRequest request = new AssumeRoleRequest();
		request.setVersion(sta_api_version);
		request.setMethod(MethodType.POST);
		request.setProtocol(protocolType);
		request.setRoleArn(roleArn);
		request.setRoleSessionName(roleSessionName);
		request.setPolicy(policy);
		// 发起请求,并得到response
		final AssumeRoleResponse response = client.getAcsResponse(request);
		return response;
	} catch (ClientException e) {
		throw e;
	}
}
 
开发者ID:xnx3,项目名称:xnx3,代码行数:21,代码来源:OSSUtil.java


示例3: send

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
public SMSResult send(String sign, String template, String mobile, Map<String, String> params) {
	SMSResult result = new SMSResult();
	try {
		if(BasicUtil.isEmpty(sign)){
			sign = config.SMS_SIGN;
		}
		request.setSignName(sign);
		request.setTemplateCode(template);
		request.setParamString(BeanUtil.map2json(params));
		request.setRecNum(mobile);
		SingleSendSmsResponse response = client.getAcsResponse(request);
		response.getModel();
		result.setResult(true);
	} catch (ClientException e) {
		e.printStackTrace();
		e.printStackTrace();
		result.setCode(e.getErrCode());
		result.setMsg(e.getErrMsg());
	}
	return result;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:22,代码来源:SMSUtil.java


示例4: assumeRole

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,
                                     String roleArn, String roleSessionName, String policy,
                                     ProtocolType protocolType) throws ClientException {
    try {
        // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
        IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

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

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

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

        return response;
    } catch (ClientException e) {
        throw e;
    }
}
 
开发者ID:aliyun,项目名称:sts-demo-simple-android-app,代码行数:27,代码来源:StsServiceImpl.java


示例5: getTempAccessPerm

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
@Override
public Map<String, String> getTempAccessPerm(String id) {
    ProtocolType protocolType = ProtocolType.HTTPS;
    try {
        final AssumeRoleResponse response = assumeRole(id, _config.getConf(id, K_accessKeyId),
                _config.getConf(id, K_accessKeySecret), _config.getConf(id, K_roleArn),
                _config.getConf(id, K_roleSessionName), _config.getConf(id, K_policy), protocolType);

        Map<String, String> rsp = new HashMap<String, String>();
        rsp.put(K_accessKeyId, response.getCredentials().getAccessKeyId());
        rsp.put(K_accessKeySecret, response.getCredentials().getAccessKeySecret());
        rsp.put(K_securityToken, response.getCredentials().getSecurityToken());
        return rsp;
    } catch (ClientException e) {
        LOG.error(e.getMessage(), e.fillInStackTrace());
    }

    return Collections.emptyMap();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:20,代码来源:STSServiceImpl.java


示例6: assumeRole

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
static AssumeRoleResponse assumeRole(String id, String accessKeyId, String accessKeySecret, String roleArn,
        String roleSessionName, String policy, ProtocolType protocolType) throws ClientException {
    try {
        // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
        IClientProfile profile = DefaultProfile.getProfile(_config.getConf(id, K_regionId), accessKeyId,
                accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

        // 创建一个 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);

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

        return response;
    } catch (ClientException e) {
        throw e;
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:27,代码来源:STSServiceImpl.java


示例7: assumeRole

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret, String roleArn, String roleSessionName, String policy,
        ProtocolType protocolType) throws ClientException {
    try {
        // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
        IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

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

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

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

        return response;
    } catch (ClientException e) {
        throw e;
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:26,代码来源:StsServiceSample.java


示例8: setEnv

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
public void setEnv(String env) {
    String domain = "cloudphoto.cn-shanghai.aliyuncs.com";
    try {
        if (env.equals("pre_release")) {
            domain = "cloudphoto-pre.cn-shanghai.aliyuncs.com";
        }
        DefaultProfile.addEndpoint(REGION_CN, REGION_CN, "CloudPhoto", domain); //添加自定义endpoint。
    } catch (ClientException e) {
        e.printStackTrace();
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:12,代码来源:PhotoStoreClient.java


示例9: getCheckResult

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
@Override
public float getCheckResult(String taskId) {
    ImageResultRequest imageResultRequest = new ImageResultRequest();
    imageResultRequest.setTaskId(taskId);
    try {
        ImageResultResponse imageResultResponse = client.getAcsResponse(imageResultRequest);
        logger.info("Getting image detection result... {}^^^^{}", imageResultResponse.getCode(), imageResultResponse.getMsg());
        if ("Success".equals(imageResultResponse.getCode())
                && "TaskProcessSuccess".equals(imageResultResponse.getStatus())) {
            ImageResultResponse.ImageResult imageResult = imageResultResponse.getImageResult();
            ImageResultResponse.ImageResult.PornResult pornResult = imageResult.getPornResult();
            if (pornResult != null) {
                Integer label = pornResult.getLabel();
                Float rate = pornResult.getRate();
                return rate;
            }
            imageResult.getOcrResult();
            imageResult.getIllegalResult();
        } else {
            logger.error("Failed to get image check result");
        }
    } catch (ClientException e) {
        logger.error("Failed to get image check result");
        throw new RuntimeException(e);
    }
    logger.error("Failed to get image check result");
    throw new RuntimeException("Failed to get image check result");
}
 
开发者ID:chocotan,项目名称:lolibox,代码行数:29,代码来源:AliGreenService.java


示例10: createSTS

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
/**
	 * STS 授权给第三方上传,获得临时访问凭证
	 * @param roleSessionName 临时Token的会话名称,自己指定用于标识你的用户,主要用于审计,或者用于区分Token颁发给谁
	 * 							<br/>注意RoleSessionName的长度和规则,不要有空格,只能有'-' '_' 字母和数字等字符
	 * 							<br/>具体规则请参考API文档中的格式要求
	 * 							<br/>如:alice-001
	 * @param policy RAM和STS授权策略,详细参考 <a href="https://help.aliyun.com/document_detail/31867.html">https://help.aliyun.com/document_detail/31867.html</a>
	 * 			<pre>
	 * 				{
	 * 					"Version": "1",
	 * 					"Statement": [
	 * 						{
	 * 							"Action": [
	 * 								"oss:PutObject", 
	 * 								"oss:GetObject"
	 * 							], 
	 * 							"Resource": [
	 * 								"acs:oss:*:*:*"
	 * 							], 
	 * 							"Effect": "Allow",
	 * 							"Condition": {
	 * 								"IpAddress": {
	 * 									"acs:SourceIp": "192.168.0.*"	//指定ip网段,支持*通配
	 * 								}
	 * 							}
	 * 						}
	 * 					]
	 * 				}
	 * 			</pre>
	 * @return 成功,返回 {@link Credentials} ,失败返回null
	 */
	public static Credentials createSTS(String roleSessionName,String policy){
		String accessKeyId = OSSUtil.accessKeyId;
	    String accessKeySecret = OSSUtil.accessKeySecret;
	    // AssumeRole API 请求参数: RoleArn, RoleSessionName, Policy, and DurationSeconds
	    // RoleArn 需要在 RAM 控制台上获取
//	    String roleArn = "acs:ram::1080155601964967:role/aliyunosstokengeneratorrole";
	    // RoleSessionName 是临时Token的会话名称,自己指定用于标识你的用户,主要用于审计,或者用于区分Token颁发给谁
	    // 但是注意RoleSessionName的长度和规则,不要有空格,只能有'-' '_' 字母和数字等字符
	    // 具体规则请参考API文档中的格式要求
//		String roleSessionName = "alice-001";
	    // 如何定制你的policy?
//		    String policy = "{\n" +
//		            "    \"Version\": \"1\", \n" +
//		            "    \"Statement\": [\n" +
//		            "        {\n" +
//		            "            \"Action\": [\n" +
//		            "                \"oss:GetBucket\", \n" +
//		            "                \"oss:GetObject\" \n" +
//		            "            ], \n" +
//		            "            \"Resource\": [\n" +
//		            "                \"acs:oss:*:*:*\"\n" +
//		            "            ], \n" +
//		            "            \"Effect\": \"Allow\"\n" +
//		            "        }\n" +
//		            "    ]\n" +
//		            "}";
	    // 此处必须为 HTTPS
	    ProtocolType protocolType = ProtocolType.HTTPS;
	    try {
	    	AssumeRoleResponse response = assumeRole(accessKeyId, accessKeySecret,roleArn, roleSessionName, policy, protocolType);
	    	Credentials credentials = response.getCredentials();
	    	return credentials;
	    } catch (ClientException e) {
	    	e.printStackTrace();
	    	System.out.println("Failed to get a token.");
	    	System.out.println("Error code: " + e.getErrCode());
	    	System.out.println("Error message: " + e.getErrMsg());
	    }
	    return null;
	}
 
开发者ID:xnx3,项目名称:xnx3,代码行数:72,代码来源:OSSUtil.java


示例11: assumeRole0

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
FederationToken assumeRole0(
            final String accessKeyId, final String accessKeySecret,
            final String roleArn, final String policy, final long expireSeconds) {

        // AssumeRole API 请求参数: RoleArn, RoleSessionName, Polciy, and DurationSeconds
        // 参考: https://docs.aliyun.com/#/pub/ram/sts-api-reference/actions&assume_role

        // RoleSessionName 是临时Token的会话名称,自己指定用于标识你的用户,主要用于审计,或者用于区分Token颁发给谁
        // 但是注意RoleSessionName的长度和规则,不要有空格,只能有'-' '_' 字母和数字等字符
        // 具体规则请参考API文档中的格式要求
        String roleSessionName = "alice-001";

        // 如何定制你的policy?
        // 参考: https://docs.aliyun.com/#/pub/ram/ram-user-guide/policy_reference&struct_def
        // OSS policy 例子: https://docs.aliyun.com/#/pub/oss/product-documentation/acl&policy-configure
        // OSS 授权相关问题的FAQ: https://docs.aliyun.com/#/pub/ram/faq/oss&basic
//        String policy = "{\n" +
//                "    \"Version\": \"1\", \n" +
//                "    \"Statement\": [\n" +
//                "        {\n" +
//                "            \"Action\": [\n" +
//                "                \"oss:GetBucket\", \n" +
//                "                \"oss:GetObject\" \n" +
//                "            ], \n" +
//                "            \"Resource\": [\n" +
//                "                \"acs:oss:*:177530****529849:mybucket\", \n" +
//                "                \"acs:oss:*:177530****529849:mybucket/*\" \n" +
//                "            ], \n" +
//                "            \"Effect\": \"Allow\"\n" +
//                "        }\n" +
//                "    ]\n" +
//                "}";

        // 此处必须为 HTTPS
        ProtocolType protocolType = ProtocolType.HTTPS;

        try {
            final AssumeRoleResponse response = assumeRole(accessKeyId, accessKeySecret,
                    roleArn, roleSessionName, policy, protocolType);

            System.out.println("Expiration: " + response.getCredentials().getExpiration());
            System.out.println("Access Key Id: " + response.getCredentials().getAccessKeyId());
            System.out.println("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
            System.out.println("Security Token: " + response.getCredentials().getSecurityToken());

            FederationToken result = new FederationToken();
            result.setRequestId(response.getRequestId());
            result.setAccessKeyId(response.getCredentials().getAccessKeyId());
            result.setAccessKeySecret(response.getCredentials().getAccessKeySecret());
            result.setSecurityToken(response.getCredentials().getSecurityToken());
            result.setExpiration(response.getCredentials().getExpiration());
            return result;
        } catch (ClientException e) {
            System.out.println("Failed to get a token.");
            System.out.println("Error code: " + e.getErrCode());
            System.out.println("Error message: " + e.getErrMsg());
            return null;
        }
    }
 
开发者ID:aliyun,项目名称:sts-demo-simple-android-app,代码行数:60,代码来源:StsServiceImpl.java


示例12: main

import com.aliyuncs.exceptions.ClientException; //导入依赖的package包/类
public static void main(String[] args) {
    // 只有 RAM用户(子账号)才能调用 AssumeRole 接口
    // 阿里云主账号的AccessKeys不能用于发起AssumeRole请求
    // 请首先在RAM控制台创建一个RAM用户,并为这个用户创建AccessKeys
    String accessKeyId = "";
    String accessKeySecret = "";

    // AssumeRole API 请求参数: RoleArn, RoleSessionName, Polciy, and
    // DurationSeconds

    // RoleArn 需要在 RAM 控制台上获取
    String roleArn = "";

    // RoleSessionName 是临时Token的会话名称,自己指定用于标识你的用户,主要用于审计,或者用于区分Token颁发给谁
    // 但是注意RoleSessionName的长度和规则,不要有空格,只能有'-' '_' 字母和数字等字符
    // 具体规则请参考API文档中的格式要求
    String roleSessionName = "";

    // 如何定制你的policy?
    // String policy = "{\"Statement\": [{\"Action\": \"oss:*\", "
    // + "\"Effect\": \"Allow\",\"Resource\": \"*\"}],\"Version\": \"1\"}";
    String policy = "{" + " \"Statement\": [ " + "             { " + "                \"Action\": \"oss:*\", "
            + "                 \"Effect\": \"Allow\", " + "                \"Resource\": \"*\" " + "            } " + "          ], "
            + "        \"Version\": \"1\" " + "     } ";

    // String policy = "{\"Statement\": [{\"Action\": \"sts:AssumeRole\","
    // + "\"Effect\": \"Allow\",\"Principal\":{\"Service\":
    // [\"oas.aliyuncs.com\"]}}],\"Version\": \"1\"}";
    // 此处必须为 HTTPS
    ProtocolType protocolType = ProtocolType.HTTPS;

    try {
        final AssumeRoleResponse response = assumeRole(accessKeyId, accessKeySecret, roleArn, roleSessionName, policy, protocolType);

        System.out.println("Expiration: " + response.getCredentials().getExpiration());
        System.out.println("Access Key Id: " + response.getCredentials().getAccessKeyId());
        System.out.println("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
        System.out.println("Security Token: " + response.getCredentials().getSecurityToken());
    } catch (

    ClientException e)

    {
        System.out.println("Failed to get a token.");
        System.out.println("Error code: " + e.getErrCode());
        System.out.println("Error message: " + e.getErrMsg());
    }

}
 
开发者ID:dzh,项目名称:jframe,代码行数:50,代码来源:StsServiceSample.java



注:本文中的com.aliyuncs.exceptions.ClientException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RegistryUtils类代码示例发布时间:2022-05-23
下一篇:
Java CredentialRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap