Search in sources :

Example 1 with ClientException

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);
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) JsonObject(io.vertx.core.json.JsonObject) io.vertx.up.exception._424ProfileEndPointException(io.vertx.up.exception._424ProfileEndPointException) ClientException(com.aliyuncs.exceptions.ClientException) IClientProfile(com.aliyuncs.profile.IClientProfile)

Example 2 with ClientException

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();
    }
}
Also used : SingleSendMailRequest(com.aliyuncs.dm.model.v20151123.SingleSendMailRequest) HttpResponse(com.aliyuncs.http.HttpResponse) EmailSendException(zjp.translateit.web.exception.EmailSendException) ClientException(com.aliyuncs.exceptions.ClientException)

Example 3 with ClientException

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());
    }
}
Also used : PublicKey(com.aliyun.oss.common.auth.PublicKey) CredentialsProvider(com.aliyun.oss.common.auth.CredentialsProvider) IOException(java.io.IOException) ClientException(com.aliyuncs.exceptions.ClientException) Test(org.junit.Test)

Example 4 with ClientException

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;
}
Also used : HttpResponse(com.aliyuncs.http.HttpResponse) ClientException(com.aliyuncs.exceptions.ClientException) IOException(java.io.IOException)

Example 5 with ClientException

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);
    }
}
Also used : InstanceProfileCredentialsFetcher(com.aliyun.oss.common.auth.InstanceProfileCredentialsFetcher) ClientException(com.aliyuncs.exceptions.ClientException) ClientException(com.aliyuncs.exceptions.ClientException) Test(org.junit.Test)

Aggregations

ClientException (com.aliyuncs.exceptions.ClientException)16 HttpResponse (com.aliyuncs.http.HttpResponse)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 InstanceProfileCredentialsFetcher (com.aliyun.oss.common.auth.InstanceProfileCredentialsFetcher)3 InstanceProfileCredentialsFetcherMock (com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock)2 SendSmsResponse (com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse)2 JsonObject (io.vertx.core.json.JsonObject)2 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)1 PublicKey (com.aliyun.oss.common.auth.PublicKey)1 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)1 AssumeRoleRequest (com.aliyuncs.auth.sts.AssumeRoleRequest)1 AssumeRoleResponse (com.aliyuncs.auth.sts.AssumeRoleResponse)1 GetSessionAccessKeyRequest (com.aliyuncs.auth.sts.GetSessionAccessKeyRequest)1 GetSessionAccessKeyResponse (com.aliyuncs.auth.sts.GetSessionAccessKeyResponse)1 SingleSendMailRequest (com.aliyuncs.dm.model.v20151123.SingleSendMailRequest)1 ServerException (com.aliyuncs.exceptions.ServerException)1 HttpRequest (com.aliyuncs.http.HttpRequest)1 IClientProfile (com.aliyuncs.profile.IClientProfile)1 PushRequest (com.aliyuncs.push.model.v20160801.PushRequest)1