Search in sources :

Example 11 with ClientConfiguration

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());
    }
}
Also used : ExecutionContext(com.aliyun.oss.common.comm.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) ClientException(com.aliyun.oss.ClientException) File(java.io.File) URI(java.net.URI) FileInputStream(java.io.FileInputStream) ClientConfiguration(com.aliyun.oss.ClientConfiguration) Test(org.junit.Test)

Example 12 with ClientConfiguration

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;
}
Also used : OSSClient(com.aliyun.oss.OSSClient) ArrayList(java.util.ArrayList) ClientConfiguration(com.aliyun.oss.ClientConfiguration)

Example 13 with ClientConfiguration

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;
}
Also used : OSSClient(com.aliyun.oss.OSSClient) ArrayList(java.util.ArrayList) ClientConfiguration(com.aliyun.oss.ClientConfiguration)

Aggregations

ClientConfiguration (com.aliyun.oss.ClientConfiguration)13 OSSClient (com.aliyun.oss.OSSClient)6 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)6 ClientException (com.aliyun.oss.ClientException)4 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 URI (java.net.URI)4 Test (org.junit.Test)3 Credentials (com.aliyun.oss.common.auth.Credentials)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 ServiceException (com.aliyun.oss.ServiceException)1 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)1 DefaultCredentialProvider (com.aliyun.oss.common.auth.DefaultCredentialProvider)1 DefaultCredentials (com.aliyun.oss.common.auth.DefaultCredentials)1 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)1 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)1 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)1 File (java.io.File)1