use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ServiceClientTest method testRetryWithNoneMarkSupportedStream.
@Test
public void testRetryWithNoneMarkSupportedStream() throws Exception {
String filename = ResourceUtils.getTestFilename("oss/listBucket.xml");
File file = new File(filename);
InputStream contentStream = new FileInputStream(file);
RequestMessage request = new RequestMessage(null, null);
request.setEndpoint(new URI("http://localhost"));
request.setMethod(HttpMethod.GET);
request.setContent(contentStream);
request.setContentLength(file.length());
ExecutionContext context = new ExecutionContext();
ClientException exceptionToThrown = createRetryableException();
String content = "";
InputStream contentStream2 = new FileInputStream(file);
try {
content = StreamUtils.readContent(contentStream2, "utf-8");
} finally {
contentStream2.close();
}
// This request will succeed after 2 retries
ServiceClientImpl client = new ServiceClientImpl(new ClientConfiguration(), 3, exceptionToThrown, 400, content);
// Fix the max error retry count to 3
try {
client.sendRequest(request, context);
fail("ClientException has not been thrown.");
} catch (ClientException e) {
assertEquals(exceptionToThrown, e);
assertEquals(1, client.getRequestAttempts());
}
}
use of com.aliyun.oss.ClientConfiguration in project DataX by alibaba.
the class OssUtil method initOssClient.
public static OSSClient initOssClient(Configuration conf) {
String endpoint = conf.getString(Key.ENDPOINT);
String accessId = conf.getString(Key.ACCESSID);
String accessKey = conf.getString(Key.ACCESSKEY);
ClientConfiguration ossConf = new ClientConfiguration();
ossConf.setSocketTimeout(Constant.SOCKETTIMEOUT);
// .aliyun.com, if you are .aliyun.ga you need config this
String cname = conf.getString(Key.CNAME);
if (StringUtils.isNotBlank(cname)) {
List<String> cnameExcludeList = new ArrayList<String>();
cnameExcludeList.add(cname);
ossConf.setCnameExcludeList(cnameExcludeList);
}
OSSClient client = null;
try {
client = new OSSClient(endpoint, accessId, accessKey, ossConf);
} catch (IllegalArgumentException e) {
throw DataXException.asDataXException(OssReaderErrorCode.ILLEGAL_VALUE, e.getMessage());
}
return client;
}
use of com.aliyun.oss.ClientConfiguration in project DataX by alibaba.
the class OssUtil method initOssClient.
public static OSSClient initOssClient(Configuration conf) {
String endpoint = conf.getString(Key.ENDPOINT);
String accessId = conf.getString(Key.ACCESSID);
String accessKey = conf.getString(Key.ACCESSKEY);
ClientConfiguration ossConf = new ClientConfiguration();
ossConf.setSocketTimeout(Constant.SOCKETTIMEOUT);
// .aliyun.com, if you are .aliyun.ga you need config this
String cname = conf.getString(Key.CNAME);
if (StringUtils.isNotBlank(cname)) {
List<String> cnameExcludeList = new ArrayList<String>();
cnameExcludeList.add(cname);
ossConf.setCnameExcludeList(cnameExcludeList);
}
OSSClient client = null;
try {
client = new OSSClient(endpoint, accessId, accessKey, ossConf);
} catch (IllegalArgumentException e) {
throw DataXException.asDataXException(OssWriterErrorCode.ILLEGAL_VALUE, e.getMessage());
}
return client;
}
Aggregations