use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherTest method testFetchExceptionalCredentials.
@Test
public void testFetchExceptionalCredentials() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Exceptional);
credentialsFetcher.fetch(3);
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
}
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Exceptional);
credentialsFetcher.fetch();
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
}
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class STSAssumeRoleSessionCredentialsProvider method getNewSessionCredentials.
private BasicCredentials getNewSessionCredentials() {
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
assumeRoleRequest.setRoleArn(roleArn);
assumeRoleRequest.setRoleSessionName(roleSessionName);
assumeRoleRequest.setDurationSeconds(expiredDurationSeconds);
AssumeRoleResponse response = null;
try {
response = ramClient.getAcsResponse(assumeRoleRequest);
} catch (ClientException e) {
LogUtils.logException("RamClient.getAcsResponse Exception:", e);
return null;
}
return new BasicCredentials(response.getCredentials().getAccessKeyId(), response.getCredentials().getAccessKeySecret(), response.getCredentials().getSecurityToken(), expiredDurationSeconds).withExpiredFactor(expiredFactor);
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class HttpCredentialsFetcher method fetch.
@Override
public Credentials fetch() throws ClientException {
URL url = buildUrl();
HttpRequest request = new HttpRequest(url.toString());
request.setMethod(MethodType.GET);
request.setConnectTimeout(AuthUtils.DEFAULT_HTTP_SOCKET_TIMEOUT_IN_MILLISECONDS);
request.setReadTimeout(AuthUtils.DEFAULT_HTTP_SOCKET_TIMEOUT_IN_MILLISECONDS);
HttpResponse response = null;
try {
response = send(request);
} catch (IOException e) {
throw new ClientException("CredentialsFetcher.fetch exception: " + e);
}
return parse(response);
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsFetcherMock method send.
@Override
public HttpResponse send(HttpRequest request) throws IOException {
HttpResponse response;
try {
response = new HttpResponse(buildUrl().toString());
} catch (ClientException e) {
throw new IOException("CredentialsFetcher.buildUrl Exception.");
}
switch(responseCategory) {
case Normal:
response.setStatus(200);
response.setHttpContent(NORMAL_METADATA.getBytes(), "UTF-8", FormatType.JSON);
break;
case NormalWithoutExpiration:
response.setStatus(200);
response.setHttpContent(NORMAL_WITHOUT_EXPIRATION_METADATA.getBytes(), "UTF-8", FormatType.JSON);
break;
case NormalWithoutToken:
response.setStatus(200);
response.setHttpContent(NORMAL_WITHOUT_TOKEN_METADATA.getBytes(), "UTF-8", FormatType.JSON);
break;
case Expired:
response.setStatus(200);
response.setHttpContent(EXPIRED_METADATA.getBytes(), "UTF-8", FormatType.JSON);
break;
case FormatInvalid:
response.setStatus(200);
response.setHttpContent(FORMAT_INVALID_METADATA.getBytes(), "UTF-8", FormatType.JSON);
break;
case ServerHalt:
response.setStatus(500);
response.setHttpContent("".getBytes(), "UTF-8", null);
break;
case Exceptional:
throw new IOException("CredentialsFetcher.send Exception.");
default:
break;
}
return response;
}
use of com.aliyuncs.exceptions.ClientException in project ranch by heisedebaise.
the class AliyunAppSenderImpl method send.
@Override
public boolean send(PushModel push, String receiver, JSONObject args) {
AliyunModel aliyun = aliyunService.find(push.getAppCode());
if (aliyun == null)
return false;
PushRequest pushRequest = new PushRequest();
pushRequest.setAppKey(numeric.toLong(aliyun.getAppKey()));
pushRequest.setTarget("DEVICE");
pushRequest.setTargetValue(receiver);
pushRequest.setPushType("NOTICE");
pushRequest.setDeviceType("ALL");
pushRequest.setTitle(pushService.parse(PushService.Type.Subject, push.getKey(), push.getSubject(), args));
pushRequest.setBody(pushService.parse(PushService.Type.Content, push.getKey(), push.getContent(), args));
pushRequest.setIOSApnsEnv(json.hasTrue(args, "product") ? "PRODUCT" : "DEV");
pushRequest.setIOSBadge((json.containsKey(args, "badge") ? args.getIntValue("badge") : 1) + 1);
pushRequest.setIOSMusic(json.containsKey(args, "ios-music") ? args.getString("ios-music") : "default");
pushRequest.setAndroidMusic(json.containsKey(args, "android-music") ? args.getString("android-music") : "default");
if (json.containsKey(args, "url")) {
pushRequest.setAndroidOpenType("URL");
pushRequest.setAndroidOpenUrl(args.getString("url"));
} else if (json.containsKey(args, "activity")) {
pushRequest.setAndroidOpenType("ACTIVITY");
pushRequest.setAndroidActivity(args.getString("activity"));
} else
pushRequest.setAndroidOpenType("APPLICATION");
try {
aliyunService.getIAcsClient(aliyun.getAppCode()).getAcsResponse(pushRequest);
return true;
} catch (ClientException e) {
logger.warn(e, "使用阿里云APP推送[{}:{}:{}]时发生异常!", modelHelper.toJson(push), receiver, args);
}
return false;
}
Aggregations