use of com.aliyun.oss.OSSClient 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.OSSClient 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;
}
use of com.aliyun.oss.OSSClient in project druid by druid-io.
the class OssObjectSummaryIteratorTest method makeMockClient.
/**
* Makes a mock OSS client that handles enough of "listObjects" to test the functionality of the
* {@link OssObjectSummaryIterator} class.
*/
private static OSS makeMockClient(final List<OSSObjectSummary> objects) {
return new OSSClient("endpoint", "accessKey", "keySecret") {
@Override
public ObjectListing listObjects(final ListObjectsRequest request) {
// Continuation token is an index in the "objects" list.q
final String continuationToken = request.getMarker();
final int startIndex = continuationToken == null ? 0 : Integer.parseInt(continuationToken);
// Find matching objects.
final List<OSSObjectSummary> summaries = new ArrayList<>();
int nextIndex = -1;
for (int i = startIndex; i < objects.size(); i++) {
final OSSObjectSummary summary = objects.get(i);
if (summary.getBucketName().equals(request.getBucketName()) && summary.getKey().startsWith(request.getPrefix())) {
if (summaries.size() == request.getMaxKeys()) {
// We reached our max key limit; set nextIndex (which will lead to a result with truncated = true).
nextIndex = i;
break;
}
// Generate a summary.
summaries.add(summary);
}
}
// Generate the result.
final ObjectListing retVal = new ObjectListing();
retVal.getObjectSummaries().addAll(summaries);
if (nextIndex >= 0) {
retVal.setTruncated(true);
retVal.setNextMarker(String.valueOf(nextIndex));
}
return retVal;
}
};
}
Aggregations