Search in sources :

Example 11 with ClientException

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;
}
Also used : ClientException(com.aliyuncs.exceptions.ClientException) OpcBizException(com.paascloud.provider.exceptions.OpcBizException) SendSmsResponse(com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse)

Example 12 with ClientException

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);
}
Also used : GetSessionAccessKeyRequest(com.aliyuncs.auth.sts.GetSessionAccessKeyRequest) GetSessionAccessKeyResponse(com.aliyuncs.auth.sts.GetSessionAccessKeyResponse) ClientException(com.aliyuncs.exceptions.ClientException)

Example 13 with ClientException

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);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) ClientException(com.aliyuncs.exceptions.ClientException)

Example 14 with ClientException

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

Example 15 with ClientException

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);
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ClientException(com.aliyuncs.exceptions.ClientException) SendSmsResponse(com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse) io.vertx.up.exception._424MessageSendException(io.vertx.up.exception._424MessageSendException)

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