use of com.aliyuncs.exceptions.ClientException in project vertx-zero by silentbalanceyh.
the class SmsClientImpl method initClient.
private void initClient() {
// Extract data from config
final JsonObject params = this.config.getConfig();
Fn.safeNull(() -> {
// Set default timeout
final String connect = params.containsKey(SmsConfig.TIMEOUT_CONN) ? params.getInteger(SmsConfig.TIMEOUT_CONN).toString() : "10000";
final String read = params.containsKey(SmsConfig.TIMEOUT_READ) ? params.getInteger(SmsConfig.TIMEOUT_READ).toString() : "10000";
System.setProperty("sun.net.client.defaultConnectTimeout", connect);
System.setProperty("sun.net.client.defaultReadTimeout", read);
// AscClient initialized.
final IClientProfile profile = DefaultProfile.getProfile(SmsConfig.DFT_REGION, this.config.getAccessId(), this.config.getAccessSecret());
try {
DefaultProfile.addEndpoint(SmsConfig.DFT_REGION, SmsConfig.DFT_REGION, SmsConfig.DFT_PRODUCT, this.config.getDomain());
} catch (final ClientException ex) {
Fn.flingWeb(true, LOGGER, _424ProfileEndPointException.class, this.getClass(), ex);
}
this.client = new DefaultAcsClient(profile);
}, params);
}
use of com.aliyuncs.exceptions.ClientException in project TranslateIt-api by zunpiau.
the class EmailService method sendEmail.
private void sendEmail(String mailTo, String subject, String content) {
SingleSendMailRequest request = new SingleSendMailRequest();
request.setAccountName(aliAccount);
request.setFromAlias("TranslateIt");
request.setAddressType(1);
request.setReplyToAddress(true);
request.setToAddress(mailTo);
request.setSubject(subject);
request.setHtmlBody(content);
try {
HttpResponse response = client.doAction(request, true, 2);
logger.debug("send email to [{}] status [{}]", mailTo, response.getStatus());
if (!response.isSuccess()) {
throw new EmailSendException();
}
} catch (ClientException e) {
logger.error(mailTo, e);
throw new EmailSendException();
}
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class STSKeyPairSessionCredentialsProviderTest method testStsKeyPairCredentialsProviderNegative.
@Test
public void testStsKeyPairCredentialsProviderNegative() throws ClientException, IOException {
try {
PublicKey publicKey = AuthUtils.uploadPublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, AuthUtils.loadPublicKeyFromFile(TestConfig.PUBLIC_KEY_PATH));
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSKeyPairSessionCredentialsProvider(TestConfig.RAM_REGION_ID, publicKey.getPublicKeyId(), AuthUtils.loadPrivateKeyFromFile(TestConfig.PRIVATE_KEY_PATH)).withExpiredDuration(899);
Assert.assertNull(credentialsProvider.getCredentials());
credentialsProvider = CredentialsProviderFactory.newSTSKeyPairSessionCredentialsProvider(TestConfig.RAM_REGION_ID, publicKey.getPublicKeyId(), AuthUtils.loadPrivateKeyFromFile(TestConfig.PRIVATE_KEY_PATH)).withExpiredDuration(100);
Assert.assertNull(credentialsProvider.getCredentials());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyuncs.exceptions.ClientException in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherMock 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 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 aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherTest method testGetMetadataNegative.
@Test
public void testGetMetadataNegative() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcher().withRoleName("NotExistRoleName");
credentialsFetcher.fetch();
Assert.fail("EcsInstanceCredentialsFetcher.getMetadata should not be successful.");
} catch (Exception e) {
Assert.assertTrue(e instanceof ClientException);
}
}
Aggregations