Skip to content

Commit a86bafd

Browse files
committed
Configure default cname
1 parent 70ca795 commit a86bafd

File tree

14 files changed

+276
-83
lines changed

14 files changed

+276
-83
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.aliyun.oss;
21+
22+
public class ClientBuilderConfiguration extends ClientConfiguration {
23+
24+
public ClientBuilderConfiguration() {
25+
super();
26+
this.supportCname = false;
27+
}
28+
29+
}

src/main/java/com/aliyun/oss/ClientConfiguration.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
*/
4141
public class ClientConfiguration {
4242

43-
private static final String DEFAULT_USER_AGENT = VersionInfoUtils.getDefaultUserAgent();
43+
public static final String DEFAULT_USER_AGENT = VersionInfoUtils.getDefaultUserAgent();
4444

45-
private static final int DEFAULT_MAX_RETRIES = 3;
45+
public static final int DEFAULT_MAX_RETRIES = 3;
4646

4747
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = -1;
4848
public static final int DEFAULT_CONNECTION_TIMEOUT = 50 * 1000;
@@ -59,40 +59,40 @@ public class ClientConfiguration {
5959

6060
public static final String DEFAULT_CNAME_EXCLUDE_LIST = "aliyuncs.com,aliyun-inc.com,aliyun.com";
6161

62-
private String userAgent = DEFAULT_USER_AGENT;
63-
private int maxErrorRetry = DEFAULT_MAX_RETRIES;
64-
private int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;
65-
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
66-
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
67-
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
68-
private long connectionTTL = DEFAULT_CONNECTION_TTL;
69-
private boolean useReaper = DEFAULT_USE_REAPER;
70-
private long idleConnectionTime = DEFAULT_IDLE_CONNECTION_TIME;
62+
protected String userAgent = DEFAULT_USER_AGENT;
63+
protected int maxErrorRetry = DEFAULT_MAX_RETRIES;
64+
protected int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;
65+
protected int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
66+
protected int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
67+
protected int maxConnections = DEFAULT_MAX_CONNECTIONS;
68+
protected long connectionTTL = DEFAULT_CONNECTION_TTL;
69+
protected boolean useReaper = DEFAULT_USE_REAPER;
70+
protected long idleConnectionTime = DEFAULT_IDLE_CONNECTION_TIME;
7171

72-
private Protocol protocol = Protocol.HTTP;
72+
protected Protocol protocol = Protocol.HTTP;
7373

74-
private String proxyHost = null;
75-
private int proxyPort = -1;
76-
private String proxyUsername = null;
77-
private String proxyPassword = null;
78-
private String proxyDomain = null;
79-
private String proxyWorkstation = null;
74+
protected String proxyHost = null;
75+
protected int proxyPort = -1;
76+
protected String proxyUsername = null;
77+
protected String proxyPassword = null;
78+
protected String proxyDomain = null;
79+
protected String proxyWorkstation = null;
8080

81-
private boolean supportCname = true;
82-
private List<String> cnameExcludeList = new ArrayList<String>();
83-
private Lock rlock = new ReentrantLock();
81+
protected boolean supportCname = true;
82+
protected List<String> cnameExcludeList = new ArrayList<String>();
83+
protected Lock rlock = new ReentrantLock();
8484

85-
private boolean sldEnabled = false;
85+
protected boolean sldEnabled = false;
8686

87-
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
88-
private boolean requestTimeoutEnabled = false;
89-
private long slowRequestsThreshold = DEFAULT_SLOW_REQUESTS_THRESHOLD;
87+
protected int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
88+
protected boolean requestTimeoutEnabled = false;
89+
protected long slowRequestsThreshold = DEFAULT_SLOW_REQUESTS_THRESHOLD;
9090

91-
private Map<String, String> defaultHeaders = new LinkedHashMap<String, String>();
91+
protected Map<String, String> defaultHeaders = new LinkedHashMap<String, String>();
9292

93-
private boolean crcCheckEnabled = true;
93+
protected boolean crcCheckEnabled = true;
9494

95-
private List<RequestSigner> signerHandlers = new LinkedList<RequestSigner>();
95+
protected List<RequestSigner> signerHandlers = new LinkedList<RequestSigner>();
9696

9797
/**
9898
* Gets the user agent string.

src/main/java/com/aliyun/oss/OSSBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public interface OSSBuilder {
6666
* @param secretAccessKey
6767
* Secret Access Key.
6868
* @param config
69-
* A {@link ClientConfiguration} instance. The method would use
69+
* A {@link ClientBuilderConfiguration} instance. The method would use
7070
* default configuration if it's null.
7171
*/
72-
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, ClientConfiguration config);
72+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, ClientBuilderConfiguration config);
7373

7474
/**
7575
* Uses specified OSS Endpoint, the temporary (Access Id/Access Key/Security
@@ -85,11 +85,11 @@ public interface OSSBuilder {
8585
* @param securityToken
8686
* Security token provided by STS.
8787
* @param config
88-
* A {@link ClientConfiguration} instance. The method would use
88+
* A {@link ClientBuilderConfiguration} instance. The method would use
8989
* default configuration if it's null.
9090
*/
9191
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, String securityToken,
92-
ClientConfiguration config);
92+
ClientBuilderConfiguration config);
9393

9494
/**
9595
* Uses the specified {@link CredentialsProvider} and OSS Endpoint to create
@@ -114,6 +114,6 @@ public OSS build(String endpoint, String accessKeyId, String secretAccessKey, St
114114
* @param config
115115
* client configuration.
116116
*/
117-
public OSS build(String endpoint, CredentialsProvider credsProvider, ClientConfiguration config);
117+
public OSS build(String endpoint, CredentialsProvider credsProvider, ClientBuilderConfiguration config);
118118

119119
}

src/main/java/com/aliyun/oss/OSSClientBuilder.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,46 @@ public class OSSClientBuilder implements OSSBuilder {
3131
@Override
3232
public OSS build(String endpoint, String accessKeyId, String secretAccessKey) {
3333
return new OSSClient(endpoint, getDefaultCredentialProvider(accessKeyId, secretAccessKey),
34-
getDefaultClientConfiguration());
34+
getClientConfiguration());
3535
}
3636

3737
@Override
3838
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, String securityToken) {
3939
return new OSSClient(endpoint, getDefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken),
40-
getDefaultClientConfiguration());
40+
getClientConfiguration());
4141
}
4242

4343
@Override
44-
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, ClientConfiguration config) {
45-
if (config == null) {
46-
config = getDefaultClientConfiguration();
47-
}
48-
return new OSSClient(endpoint, getDefaultCredentialProvider(accessKeyId, secretAccessKey), config);
44+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, ClientBuilderConfiguration config) {
45+
return new OSSClient(endpoint, getDefaultCredentialProvider(accessKeyId, secretAccessKey),
46+
getClientConfiguration(config));
4947
}
5048

5149
@Override
5250
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, String securityToken,
53-
ClientConfiguration config) {
54-
if (config == null) {
55-
config = getDefaultClientConfiguration();
56-
}
51+
ClientBuilderConfiguration config) {
5752
return new OSSClient(endpoint, getDefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken),
58-
config);
53+
getClientConfiguration(config));
5954
}
6055

6156
@Override
6257
public OSS build(String endpoint, CredentialsProvider credsProvider) {
63-
return new OSSClient(endpoint, credsProvider, getDefaultClientConfiguration());
58+
return new OSSClient(endpoint, credsProvider, getClientConfiguration());
6459
}
6560

6661
@Override
67-
public OSS build(String endpoint, CredentialsProvider credsProvider, ClientConfiguration config) {
68-
if (config == null) {
69-
config = getDefaultClientConfiguration();
70-
}
71-
return new OSSClient(endpoint, credsProvider, config);
62+
public OSS build(String endpoint, CredentialsProvider credsProvider, ClientBuilderConfiguration config) {
63+
return new OSSClient(endpoint, credsProvider, getClientConfiguration(config));
64+
}
65+
66+
private static ClientBuilderConfiguration getClientConfiguration() {
67+
return new ClientBuilderConfiguration();
7268
}
7369

74-
private static ClientConfiguration getDefaultClientConfiguration() {
75-
ClientConfiguration config = new ClientConfiguration();
76-
config.setSupportCname(false);
70+
private static ClientBuilderConfiguration getClientConfiguration(ClientBuilderConfiguration config) {
71+
if (config == null) {
72+
config = new ClientBuilderConfiguration();
73+
}
7774
return config;
7875
}
7976

src/samples/MultipartUploadSample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.concurrent.Executors;
3535
import java.util.concurrent.TimeUnit;
3636

37-
import com.aliyun.oss.ClientConfiguration;
37+
import com.aliyun.oss.ClientBuilderConfiguration;
3838
import com.aliyun.oss.ClientException;
3939
import com.aliyun.oss.OSS;
4040
import com.aliyun.oss.OSSClientBuilder;
@@ -73,7 +73,7 @@ public static void main(String[] args) throws IOException {
7373
/*
7474
* Constructs a client instance with your account for accessing OSS
7575
*/
76-
ClientConfiguration conf = new ClientConfiguration();
76+
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
7777
conf.setIdleConnectionTime(1000);
7878
client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, conf);
7979

src/test/java/com/aliyun/oss/common/comm/OSSClientTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
import org.junit.Ignore;
3131
import org.junit.Test;
32-
33-
import com.aliyun.oss.ClientConfiguration;
32+
import com.aliyun.oss.ClientBuilderConfiguration;
3433
import com.aliyun.oss.OSS;
3534
import com.aliyun.oss.OSSClientBuilder;
3635
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
@@ -78,7 +77,7 @@ public void testProxyHost() {
7877
String accessKeyId = "accessKeyId";
7978
String accessKeySecret = "accessKeySecret";
8079

81-
ClientConfiguration conf = new ClientConfiguration();
80+
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
8281
conf.setProxyHost(endpoint);
8382
conf.setProxyPort(80);
8483
conf.setProxyUsername("user");

0 commit comments

Comments
 (0)