use of com.aliyuncs.exceptions.ClientException in project paascloud-master by paascloud.
the class OptSmsServiceImpl method sendSms.
@Override
public SendSmsResponse sendSms(SendSmsRequest sendSmsRequest) {
checkParam(sendSmsRequest);
SendSmsResponse acsResponse;
try {
if (GlobalConstant.DEV_PROFILE.equals(profile)) {
log.error("dev环境不发送短信");
return new SendSmsResponse();
}
if (GlobalConstant.TEST_PROFILE.equals(profile)) {
log.error("test环境不发送短信");
return new SendSmsResponse();
}
acsResponse = iAcsClient.getAcsResponse(sendSmsRequest);
} catch (ClientException e) {
log.error("send sms message error={}", e.getMessage(), e);
throw new OpcBizException(ErrorCodeEnum.OPC10040004, e);
}
log.info("send sms message OK acsResponse={}", acsResponse);
return acsResponse;
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class STSKeyPairSessionCredentialsProvider method getNewSessionCredentials.
private BasicCredentials getNewSessionCredentials() {
GetSessionAccessKeyRequest request = new GetSessionAccessKeyRequest();
request.setPublicKeyId(keyPairCredentials.getAccessKeyId());
request.setDurationSeconds((int) expiredDurationSeconds);
request.setProtocol(ProtocolType.HTTPS);
GetSessionAccessKeyResponse response = null;
try {
response = this.ramClient.getAcsResponse(request);
} catch (ClientException e) {
LogUtils.logException("RamClient.getAcsResponse Exception:", e);
return null;
}
return new BasicCredentials(response.getSessionAccesskey().getSessionAccessKeyId(), response.getSessionAccesskey().getSessionAccessKeySecert(), null, expiredDurationSeconds).withExpiredFactor(expiredFactor);
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsFetcher method parse.
public Credentials parse(HttpResponse response) throws ClientException {
String jsonContent = new String(response.getHttpContent());
try {
JSONObject jsonObject = new JSONObject(jsonContent);
if (!jsonObject.has("StatusCode")) {
throw new ClientException("Invalid json " + jsonContent + " got from oss auth server.");
}
if (!"200".equals(jsonObject.get("StatusCode"))) {
throw new ClientException("Failed to get credentials from oss auth server");
}
if (!jsonObject.has("AccessKeyId") || !jsonObject.has("AccessKeySecret")) {
throw new ClientException("Invalid json " + jsonContent + " got from oss auth server.");
}
String securityToken = null;
if (jsonObject.has("SecurityToken")) {
securityToken = jsonObject.getString("SecurityToken");
}
if (jsonObject.has("Expiration")) {
return new InstanceProfileCredentials(jsonObject.getString("AccessKeyId"), jsonObject.getString("AccessKeySecret"), securityToken, jsonObject.getString("Expiration")).withExpiredDuration(AuthUtils.DEFAULT_STS_SESSION_TOKEN_DURATION_SECONDS);
}
return new BasicCredentials(jsonObject.getString("AccessKeyId"), jsonObject.getString("AccessKeySecret"), securityToken);
} catch (JSONException e) {
throw new ClientException("CustomSessionCredentialsFetcher.parse [" + jsonContent + "] exception:" + e);
}
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherTest method testFetchInvalidCredentials.
@Test
public void testFetchInvalidCredentials() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.FormatInvalid);
credentialsFetcher.fetch(3);
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
Assert.assertEquals(FORMAT_ERROR_MESSAGE, e.getMessage());
}
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.FormatInvalid);
credentialsFetcher.fetch();
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
Assert.assertEquals(FORMAT_ERROR_MESSAGE, e.getMessage());
}
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.ServerHalt);
credentialsFetcher.fetch(3);
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
}
}
use of com.aliyuncs.exceptions.ClientException in project vertx-zero by silentbalanceyh.
the class SmsClientImpl method getResponse.
private Future<JsonObject> getResponse(final SendSmsRequest request) {
try {
final SendSmsResponse response = this.client.getAcsResponse(request);
final JsonObject data = new JsonObject();
data.put(SmsConfig.RESPONSE_REQUEST_ID, response.getRequestId());
data.put(SmsConfig.RESPONSE_BUSINESS_ID, response.getBizId());
data.put(SmsConfig.RESPONSE_CODE, response.getCode());
data.put(SmsConfig.RESPONSE_MESSAGE, response.getMessage());
return Future.succeededFuture(data);
} catch (final ClientException ex) {
Fn.flingWeb(true, LOGGER, _424MessageSendException.class, this.getClass(), ex);
return Future.failedFuture(ex);
}
}
Aggregations