Search in sources :

Example 1 with HttpResponse

use of com.aliyuncs.http.HttpResponse 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 2 with HttpResponse

use of com.aliyuncs.http.HttpResponse 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 3 with HttpResponse

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

Example 4 with HttpResponse

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

Aggregations

ClientException (com.aliyuncs.exceptions.ClientException)4 HttpResponse (com.aliyuncs.http.HttpResponse)4 IOException (java.io.IOException)3 SingleSendMailRequest (com.aliyuncs.dm.model.v20151123.SingleSendMailRequest)1 HttpRequest (com.aliyuncs.http.HttpRequest)1 URL (java.net.URL)1 EmailSendException (zjp.translateit.web.exception.EmailSendException)1