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();
}
}
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;
}
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);
}
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;
}
Aggregations