Skip to content

Commit b5b9e4a

Browse files
committed
Merge pull request #121 from qiniu/develop
Release 6.1.5
2 parents 1d2eafb + ff3e0d5 commit b5b9e4a

File tree

15 files changed

+176
-184
lines changed

15 files changed

+176
-184
lines changed

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
language: java
22

33
before_script:
4-
- export QINIU_ACCESS_KEY=iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV
5-
- export QINIU_SECRET_KEY=6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j
4+
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
5+
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
66
- export QINIU_UP_HOST=http://up.qbox.me
77
- export QINIU_RS_HOST=http://rs.qbox.me
88
- export QINIU_IO_HOST=http://iovip.qbox.me
9-
- export QINIU_TEST_BUCKET=junit_bucket
9+
- export QINIU_TEST_BUCKET=javasdk
10+
- export QINIU_TEST_SRC_BUCKET=testsrc
11+
- export QINIU_TEST_DOMAIN=javasdk.qiniudn.com

src/main/java/com/qiniu/api/config/Config.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77
public class Config {
88
public static final String CHARSET = "utf-8";
9-
10-
public static String USER_AGENT="qiniu java-sdk v6.0.0";
11-
9+
/**本地检测不通过、程序抛异常,设置 CallRet 的 statusCode 为此错误码*/
10+
public static final int ERROR_CODE = 0;
11+
12+
public static final String VERSION = "6.1.5";
13+
1214
/**
1315
* You can get your accesskey from <a href="https://dev.qiniutek.com"
1416
* target="blank"> https://dev.qiniutek.com </a>
@@ -24,14 +26,14 @@ public class Config {
2426
public static String RS_HOST = "http://rs.qbox.me";
2527

2628
public static String UP_HOST = "http://up.qiniu.com";
27-
29+
2830
public static String RSF_HOST = "http://rsf.qbox.me";
29-
31+
3032
/**
3133
* HTTP连接超时的时间毫秒(ms)
3234
* Determines the timeout in milliseconds until a connection is established.
3335
* A timeout value of zero is interpreted as an infinite timeout.
34-
*
36+
*
3537
* Please note this parameter can only be applied to connections that
3638
* are bound to a particular local address.
3739
*/

src/main/java/com/qiniu/api/io/IoApi.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static PutRet put(String uptoken, String key, File file,
3030
PutExtra extra) {
3131

3232
if (!file.exists() || !file.canRead()) {
33-
return new PutRet(new CallRet(400, new Exception(
33+
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception(
3434
"File does not exist or not readable.")));
3535
}
3636
MultipartEntity requestEntity = new MultipartEntity();
@@ -42,7 +42,7 @@ private static PutRet put(String uptoken, String key, File file,
4242
setParam(requestEntity, extra.params);
4343
if (extra.checkCrc != NO_CRC32) {
4444
if (extra.crc32 == 0) {
45-
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
45+
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception("no crc32 specified!")));
4646
}
4747
requestEntity.addPart("crc32", new StringBody(extra.crc32 + ""));
4848
}
@@ -54,7 +54,7 @@ private static PutRet put(String uptoken, String key, File file,
5454
}
5555
} catch (Exception e) {
5656
e.printStackTrace();
57-
return new PutRet(new CallRet(400, e));
57+
return new PutRet(new CallRet(Config.ERROR_CODE, e));
5858
}
5959

6060
String url = Config.UP_HOST;
@@ -95,13 +95,13 @@ private static PutRet putStream(String uptoken, String key, InputStream reader,P
9595
setParam(requestEntity, extra.params);
9696
if (extra.checkCrc != NO_CRC32) {
9797
if (extra.crc32 == 0) {
98-
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
98+
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception("no crc32 specified!")));
9999
}
100100
requestEntity.addPart("crc32", new StringBody(extra.crc32 + ""));
101101
}
102102
} catch (Exception e) {
103103
e.printStackTrace();
104-
return new PutRet(new CallRet(400, e));
104+
return new PutRet(new CallRet(Config.ERROR_CODE, e));
105105
}
106106

107107
String url = Config.UP_HOST;
@@ -134,11 +134,15 @@ public static PutRet Put(String uptoken,String key,InputStream reader,PutExtra e
134134

135135
public static PutRet putFile(String uptoken, String key, String fileName, PutExtra extra) {
136136
File file=new File(fileName);
137+
return putFile(uptoken, key, file, extra);
138+
}
139+
140+
public static PutRet putFile(String uptoken, String key, File file, PutExtra extra) {
137141
if (extra.checkCrc == AUTO_CRC32) {
138142
try {
139143
extra.crc32 = getCRC32(file);
140144
} catch (Exception e) {
141-
return new PutRet(new CallRet(400, e));
145+
return new PutRet(new CallRet(Config.ERROR_CODE, e));
142146
}
143147
}
144148
return put(uptoken, key, file, extra);

src/main/java/com/qiniu/api/net/Client.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,66 +19,78 @@
1919

2020
/**
2121
* The class {@code Client} is a typical wrapper of RPC. Also see
22-
* {@code com.qiniu.api.auth.DigestAuthClient}
22+
* {@code com.qiniu.api.auth.DigestAuthClient}
2323
*/
2424
public class Client {
25-
26-
private final static String HEADER_AGENT="User-Agent";
25+
26+
private final static String HEADER_AGENT="User-Agent";
2727

2828
/**
29-
*
29+
*
3030
* @param post
3131
* @throws AuthException
3232
*/
3333
public void setAuth(HttpPost post) throws AuthException {
3434

3535
}
3636

37+
public static HttpPost newPost(String url){
38+
HttpPost postMethod = new HttpPost(url);
39+
postMethod.setHeader(HEADER_AGENT, getUserAgent());
40+
return postMethod;
41+
}
42+
43+
private static String getUserAgent(){
44+
String javaVersion = "Java/" + System.getProperty("java.version");
45+
String os = System.getProperty("os.name") + " "
46+
+ System.getProperty("os.arch") + " " + System.getProperty("os.version");
47+
String sdk = "QiniuJava/" + Config.VERSION;
48+
return sdk + " (" + os +") " + javaVersion;
49+
}
50+
3751
/**
3852
* Sends a http post request to the specified url.
39-
*
53+
*
4054
* @param url
4155
* the request url
4256
* @return A general response
4357
*/
4458
public CallRet call(String url) {
4559
HttpClient client = Http.getClient();
46-
HttpPost postMethod = new HttpPost(url);
47-
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
60+
HttpPost postMethod = newPost(url);
4861
try {
4962
setAuth(postMethod);
5063
HttpResponse response = client.execute(postMethod);
5164
return handleResult(response);
5265
} catch (Exception e) {
5366
e.printStackTrace();
54-
return new CallRet(400, e);
67+
return new CallRet(Config.ERROR_CODE, e);
5568
}
5669
}
5770

5871
/**
5972
* Sends a http post request to the specified url with a list of
6073
* <code>NameValuePair<code>.
61-
*
74+
*
6275
* @param url
6376
* the request url
6477
* @param nvps
6578
* @return A general response
6679
*/
6780
public CallRet call(String url, List<NameValuePair> nvps) {
6881
HttpClient client = Http.getClient();
69-
HttpPost postMethod = new HttpPost(url);
82+
HttpPost postMethod = newPost(url);
7083
try {
7184
StringEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8");
7285
entity.setContentType("application/x-www-form-urlencoded");
7386
postMethod.setEntity(entity);
74-
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
7587
setAuth(postMethod);
7688
HttpResponse response = client.execute(postMethod);
7789

7890
return handleResult(response);
7991
} catch (Exception e) {
8092
e.printStackTrace();
81-
return new CallRet(400, e);
93+
return new CallRet(Config.ERROR_CODE, e);
8294
}
8395
}
8496

@@ -90,7 +102,7 @@ public CallRet call(String url, List<NameValuePair> nvps) {
90102
*/
91103
public CallRet callWithBinary(String url, AbstractHttpEntity entity) {
92104
HttpClient client = Http.getClient();
93-
HttpPost postMethod = new HttpPost(url);
105+
HttpPost postMethod = newPost(url);
94106
postMethod.setEntity(entity);
95107

96108
try {
@@ -99,12 +111,12 @@ public CallRet callWithBinary(String url, AbstractHttpEntity entity) {
99111
return handleResult(response);
100112
} catch (Exception e) {
101113
e.printStackTrace();
102-
return new CallRet(400, e);
114+
return new CallRet(Config.ERROR_CODE, e);
103115
}
104116
}
105117

106118
/**
107-
*
119+
*
108120
* @param url
109121
* the request url
110122
* @param contentType
@@ -126,48 +138,47 @@ public CallRet callWithBinary(String url, String contentType, byte[] body) {
126138
}
127139

128140
/**
129-
*
141+
*
130142
* @param url
131143
* @param requestEntity
132144
* @return A general response format
133145
*/
134146
public CallRet callWithMultiPart(String url, MultipartEntity requestEntity) {
135-
HttpPost postMethod = new HttpPost(url);
147+
HttpPost postMethod = newPost(url);
136148
postMethod.setEntity(requestEntity);
137-
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
138149
HttpClient client = Http.getClient();
139-
150+
140151
try {
141152
HttpResponse response = client.execute(postMethod);
142153
return handleResult(response);
143154
} catch (Exception e) {
144155
e.printStackTrace();
145-
return new CallRet(400, e);
156+
return new CallRet(Config.ERROR_CODE, e);
146157
}
147158
}
148159

149160
/**
150161
* Transforms a httpresponse to user expected format.
151-
*
162+
*
152163
* @param response
153164
* http response body
154165
* @return a formated general response structure
155166
*/
156167
private CallRet handleResult(HttpResponse response) {
157168
if (response == null || response.getStatusLine() == null) {
158-
return new CallRet(400, "No response");
169+
return new CallRet(Config.ERROR_CODE, "No response");
159170
}
160171

161172
String responseBody;
162173
try {
163174
responseBody = EntityUtils.toString(response.getEntity(),"UTF-8");
164175
} catch (Exception e) {
165176
e.printStackTrace();
166-
return new CallRet(400, e);
177+
return new CallRet(Config.ERROR_CODE, e);
167178
}
168179

169180
StatusLine status = response.getStatusLine();
170-
int statusCode = (status == null) ? 400 : status.getStatusCode();
181+
int statusCode = (status == null) ? Config.ERROR_CODE : status.getStatusCode();
171182
return new CallRet(statusCode, responseBody);
172183
}
173184

src/main/java/com/qiniu/api/resumableio/UploadBlock.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.apache.http.client.HttpClient;
66
import org.apache.http.client.methods.HttpPost;
77

8+
import com.qiniu.api.config.Config;
9+
810

911
public abstract class UploadBlock {
1012
public static int CHUNK_SIZE = 1024 * 256;
@@ -78,7 +80,7 @@ private ChunkUploadCallRet upload(String url, int start,int len, int time) {
7880

7981
return checkAndRetryUpload(url, start, len, time, ret);
8082
} catch (Exception e) {
81-
return new ChunkUploadCallRet(400, e);
83+
return new ChunkUploadCallRet(Config.ERROR_CODE, e);
8284
}
8385
}
8486

src/main/java/com/qiniu/api/resumableio/Util.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
import com.qiniu.api.config.Config;
1111
import com.qiniu.api.net.CallRet;
12+
import com.qiniu.api.net.Client;
1213

1314
public class Util {
1415
public static HttpPost buildUpPost(String url, String token) {
15-
HttpPost post = new HttpPost(url);
16-
post.setHeader("User-Agent", Config.USER_AGENT);
16+
HttpPost post = Client.newPost(url);
1717
post.setHeader("Authorization", "UpToken " + token);
1818
return post;
1919
}
20-
20+
2121
public static CallRet handleResult(HttpResponse response) {
2222
try {
2323
StatusLine status = response.getStatusLine();
@@ -26,12 +26,12 @@ public static CallRet handleResult(HttpResponse response) {
2626
response.getEntity(), "utf-8");
2727
return new CallRet(statusCode, responseBody);
2828
} catch (Exception e) {
29-
CallRet ret = new CallRet(400, "can not load response.");
29+
CallRet ret = new CallRet(Config.ERROR_CODE, "can not load response.");
3030
ret.exception = e;
3131
return ret;
3232
}
3333
}
34-
34+
3535
public static long crc32(byte[] data){
3636
CRC32 crc32 = new CRC32();
3737
crc32.update(data);

src/main/java/com/qiniu/api/rs/PutPolicy.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public class PutPolicy {
5151
public String persistentOps;
5252

5353
private long deadline;
54+
55+
/**
56+
* 转码队列名,须预先开通
57+
* 资源上传成功后,触发转码时指定独立的队列进行转码
58+
*/
59+
public String persistentPipeline;
5460

5561

5662
public PutPolicy(String scope) {
@@ -100,6 +106,10 @@ public String marshal() throws JSONException {
100106
if (this.persistentOps != null && this.persistentOps.length() > 0) {
101107
stringer.key("persistentOps").value(this.persistentOps);
102108
}
109+
if(persistentPipeline != null && persistentPipeline.trim().length() > 0){
110+
stringer.key("persistentPipeline").value(this.persistentPipeline);
111+
}
112+
103113
stringer.key("deadline").value(this.deadline);
104114
stringer.endObject();
105115

0 commit comments

Comments
 (0)