Skip to content

Commit 0f12e49

Browse files
authored
Merge pull request #111 from aliyun/dev-3-0-0
Dev-3-0-0
2 parents 6e08d06 + 8f8a110 commit 0f12e49

File tree

99 files changed

+8075
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+8075
-168
lines changed

pom.xml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
<groupId>com.aliyun.oss</groupId>
1313
<artifactId>aliyun-sdk-oss</artifactId>
14-
<version>2.8.3</version>
14+
<version>3.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616
<name>Aliyun OSS SDK for Java</name>
1717
<description>The Aliyun OSS SDK for Java used for accessing Aliyun Object Storage Service</description>
1818
<url>http://www.aliyun.com/product/oss</url>
1919

20-
2120
<dependencies>
2221
<dependency>
2322
<groupId>org.apache.httpcomponents</groupId>
@@ -33,13 +32,26 @@
3332
<groupId>com.sun.jersey</groupId>
3433
<artifactId>jersey-json</artifactId>
3534
<version>1.9</version>
36-
<scope>test</scope>
37-
<exclusions>
38-
<exclusion>
39-
<groupId>stax</groupId>
40-
<artifactId>stax-api</artifactId>
41-
</exclusion>
42-
</exclusions>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.aliyun</groupId>
38+
<artifactId>aliyun-java-sdk-core</artifactId>
39+
<version>3.4.0</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.aliyun</groupId>
43+
<artifactId>aliyun-java-sdk-ram</artifactId>
44+
<version>3.0.0</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.aliyun</groupId>
48+
<artifactId>aliyun-java-sdk-sts</artifactId>
49+
<version>3.0.0</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.aliyun</groupId>
53+
<artifactId>aliyun-java-sdk-ecs</artifactId>
54+
<version>4.2.0</version>
4355
</dependency>
4456
<dependency>
4557
<groupId>junit</groupId>
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: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import java.util.ArrayList;
2323
import java.util.Collections;
2424
import java.util.LinkedHashMap;
25+
import java.util.LinkedList;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.concurrent.locks.Lock;
2829
import java.util.concurrent.locks.ReentrantLock;
2930

31+
import com.aliyun.oss.common.auth.RequestSigner;
3032
import com.aliyun.oss.common.comm.IdleConnectionReaper;
3133
import com.aliyun.oss.common.comm.Protocol;
3234
import com.aliyun.oss.common.utils.ResourceManager;
@@ -38,9 +40,9 @@
3840
*/
3941
public class ClientConfiguration {
4042

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

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

4547
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = -1;
4648
public static final int DEFAULT_CONNECTION_TIMEOUT = 50 * 1000;
@@ -57,38 +59,40 @@ public class ClientConfiguration {
5759

5860
public static final String DEFAULT_CNAME_EXCLUDE_LIST = "aliyuncs.com,aliyun-inc.com,aliyun.com";
5961

60-
private String userAgent = DEFAULT_USER_AGENT;
61-
private int maxErrorRetry = DEFAULT_MAX_RETRIES;
62-
private int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;
63-
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
64-
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
65-
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
66-
private long connectionTTL = DEFAULT_CONNECTION_TTL;
67-
private boolean useReaper = DEFAULT_USE_REAPER;
68-
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;
6971

70-
private Protocol protocol = Protocol.HTTP;
72+
protected Protocol protocol = Protocol.HTTP;
7173

72-
private String proxyHost = null;
73-
private int proxyPort = -1;
74-
private String proxyUsername = null;
75-
private String proxyPassword = null;
76-
private String proxyDomain = null;
77-
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;
7880

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

83-
private boolean sldEnabled = false;
85+
protected boolean sldEnabled = false;
8486

85-
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
86-
private boolean requestTimeoutEnabled = false;
87-
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;
8890

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

91-
private boolean crcCheckEnabled = true;
93+
protected boolean crcCheckEnabled = true;
94+
95+
protected List<RequestSigner> signerHandlers = new LinkedList<RequestSigner>();
9296

9397
/**
9498
* Gets the user agent string.
@@ -622,4 +626,30 @@ public void setCrcCheckEnabled(boolean crcCheckEnabled) {
622626
this.crcCheckEnabled = crcCheckEnabled;
623627
}
624628

629+
/**
630+
* Gets signer handlers
631+
*
632+
* @return signer handlers
633+
*/
634+
public List<RequestSigner> getSignerHandlers() {
635+
return signerHandlers;
636+
}
637+
638+
/**
639+
* Sets signer handlers using for authentication of the proxy server.
640+
*
641+
* @param signerHandlers
642+
*/
643+
public void setSignerHandlers(List<RequestSigner> signerHandlers) {
644+
if (signerHandlers == null) {
645+
return;
646+
}
647+
this.signerHandlers.clear();
648+
for (RequestSigner signer : signerHandlers) {
649+
if (signer != null) {
650+
this.signerHandlers.add(signer);
651+
}
652+
}
653+
}
654+
625655
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ public interface OSS {
177177
*/
178178
public AccessControlList getBucketAcl(GenericRequest genericRequest) throws OSSException, ClientException;
179179

180+
/**
181+
* Gets the metadata of {@link Bucket}.
182+
*
183+
* @param bucketName
184+
* Bucket name.
185+
*
186+
* @return The {@link BucketMetadata} instance.
187+
*/
188+
public BucketMetadata getBucketMetadata(String bucketName) throws OSSException, ClientException;
189+
190+
/**
191+
* Gets all the metadata of {@link Bucket}.
192+
*
193+
* @param genericRequest
194+
* Generic request which specifies the bucket name.
195+
*
196+
* @return The {@link BucketMetadata} instance.
197+
*
198+
*/
199+
public BucketMetadata getBucketMetadata(GenericRequest genericRequest) throws OSSException, ClientException;
200+
180201
/**
181202
* Sets the http referer on the {@link Bucket} instance specified by the
182203
* bucket name.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
import com.aliyun.oss.common.auth.CredentialsProvider;
23+
24+
/**
25+
* Fluent builder for OSS Client. Use of the builder is preferred over using
26+
* constructors of the client class.
27+
*/
28+
public interface OSSBuilder {
29+
30+
/**
31+
* Uses the specified OSS Endpoint and Access Id/Access Key to create a new
32+
* {@link OSSClient} instance.
33+
*
34+
* @param endpoint
35+
* OSS endpoint.
36+
* @param accessKeyId
37+
* Access Key ID.
38+
* @param secretAccessKey
39+
* Secret Access Key.
40+
*/
41+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey);
42+
43+
/**
44+
* Uses the specified OSS Endpoint, a security token from AliCloud STS and
45+
* Access Id/Access Key to create a new {@link OSSClient} instance.
46+
*
47+
* @param endpoint
48+
* OSS Endpoint.
49+
* @param accessKeyId
50+
* Access Id from STS.
51+
* @param secretAccessKey
52+
* Access Key from STS
53+
* @param securityToken
54+
* Security Token from STS.
55+
*/
56+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, String securityToken);
57+
58+
/**
59+
* Uses a specified OSS Endpoint, Access Id, Access Key, Client side
60+
* configuration to create a {@link OSSClient} instance.
61+
*
62+
* @param endpoint
63+
* OSS Endpoint.
64+
* @param accessKeyId
65+
* Access Key ID.
66+
* @param secretAccessKey
67+
* Secret Access Key.
68+
* @param config
69+
* A {@link ClientBuilderConfiguration} instance. The method would use
70+
* default configuration if it's null.
71+
*/
72+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, ClientBuilderConfiguration config);
73+
74+
/**
75+
* Uses specified OSS Endpoint, the temporary (Access Id/Access Key/Security
76+
* Token) from STS and the client configuration to create a new
77+
* {@link OSSClient} instance.
78+
*
79+
* @param endpoint
80+
* OSS Endpoint.
81+
* @param accessKeyId
82+
* Access Key Id provided by STS.
83+
* @param secretAccessKey
84+
* Secret Access Key provided by STS.
85+
* @param securityToken
86+
* Security token provided by STS.
87+
* @param config
88+
* A {@link ClientBuilderConfiguration} instance. The method would use
89+
* default configuration if it's null.
90+
*/
91+
public OSS build(String endpoint, String accessKeyId, String secretAccessKey, String securityToken,
92+
ClientBuilderConfiguration config);
93+
94+
/**
95+
* Uses the specified {@link CredentialsProvider} and OSS Endpoint to create
96+
* a new {@link OSSClient} instance.
97+
*
98+
* @param endpoint
99+
* OSS services Endpoint.
100+
* @param credsProvider
101+
* Credentials provider which has access key Id and access Key
102+
* secret.
103+
*/
104+
public OSS build(String endpoint, CredentialsProvider credsProvider);
105+
106+
/**
107+
* Uses the specified {@link CredentialsProvider}, client configuration and
108+
* OSS endpoint to create a new {@link OSSClient} instance.
109+
*
110+
* @param endpoint
111+
* OSS services Endpoint.
112+
* @param credsProvider
113+
* Credentials provider.
114+
* @param config
115+
* client configuration.
116+
*/
117+
public OSS build(String endpoint, CredentialsProvider credsProvider, ClientBuilderConfiguration config);
118+
119+
}

0 commit comments

Comments
 (0)