Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 6.1.5 #121

Merged
merged 16 commits into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: java

before_script:
- export QINIU_ACCESS_KEY=iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV
- export QINIU_SECRET_KEY=6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
- export QINIU_UP_HOST=http://up.qbox.me
- export QINIU_RS_HOST=http://rs.qbox.me
- export QINIU_IO_HOST=http://iovip.qbox.me
- export QINIU_TEST_BUCKET=junit_bucket
- export QINIU_TEST_BUCKET=javasdk
- export QINIU_TEST_SRC_BUCKET=testsrc
- export QINIU_TEST_DOMAIN=javasdk.qiniudn.com
14 changes: 8 additions & 6 deletions src/main/java/com/qiniu/api/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/
public class Config {
public static final String CHARSET = "utf-8";

public static String USER_AGENT="qiniu java-sdk v6.0.0";

/**本地检测不通过、程序抛异常,设置 CallRet 的 statusCode 为此错误码*/
public static final int ERROR_CODE = 0;

public static final String VERSION = "6.1.5";

/**
* You can get your accesskey from <a href="https://dev.qiniutek.com"
* target="blank"> https://dev.qiniutek.com </a>
Expand All @@ -24,14 +26,14 @@ public class Config {
public static String RS_HOST = "http://rs.qbox.me";

public static String UP_HOST = "http://up.qiniu.com";

public static String RSF_HOST = "http://rsf.qbox.me";

/**
* HTTP连接超时的时间毫秒(ms)
* Determines the timeout in milliseconds until a connection is established.
* A timeout value of zero is interpreted as an infinite timeout.
*
*
* Please note this parameter can only be applied to connections that
* are bound to a particular local address.
*/
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/qiniu/api/io/IoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static PutRet put(String uptoken, String key, File file,
PutExtra extra) {

if (!file.exists() || !file.canRead()) {
return new PutRet(new CallRet(400, new Exception(
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception(
"File does not exist or not readable.")));
}
MultipartEntity requestEntity = new MultipartEntity();
Expand All @@ -42,7 +42,7 @@ private static PutRet put(String uptoken, String key, File file,
setParam(requestEntity, extra.params);
if (extra.checkCrc != NO_CRC32) {
if (extra.crc32 == 0) {
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception("no crc32 specified!")));
}
requestEntity.addPart("crc32", new StringBody(extra.crc32 + ""));
}
Expand All @@ -54,7 +54,7 @@ private static PutRet put(String uptoken, String key, File file,
}
} catch (Exception e) {
e.printStackTrace();
return new PutRet(new CallRet(400, e));
return new PutRet(new CallRet(Config.ERROR_CODE, e));
}

String url = Config.UP_HOST;
Expand Down Expand Up @@ -95,13 +95,13 @@ private static PutRet putStream(String uptoken, String key, InputStream reader,P
setParam(requestEntity, extra.params);
if (extra.checkCrc != NO_CRC32) {
if (extra.crc32 == 0) {
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
return new PutRet(new CallRet(Config.ERROR_CODE, new Exception("no crc32 specified!")));
}
requestEntity.addPart("crc32", new StringBody(extra.crc32 + ""));
}
} catch (Exception e) {
e.printStackTrace();
return new PutRet(new CallRet(400, e));
return new PutRet(new CallRet(Config.ERROR_CODE, e));
}

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

public static PutRet putFile(String uptoken, String key, String fileName, PutExtra extra) {
File file=new File(fileName);
return putFile(uptoken, key, file, extra);
}

public static PutRet putFile(String uptoken, String key, File file, PutExtra extra) {
if (extra.checkCrc == AUTO_CRC32) {
try {
extra.crc32 = getCRC32(file);
} catch (Exception e) {
return new PutRet(new CallRet(400, e));
return new PutRet(new CallRet(Config.ERROR_CODE, e));
}
}
return put(uptoken, key, file, extra);
Expand Down
59 changes: 35 additions & 24 deletions src/main/java/com/qiniu/api/net/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,78 @@

/**
* The class {@code Client} is a typical wrapper of RPC. Also see
* {@code com.qiniu.api.auth.DigestAuthClient}
* {@code com.qiniu.api.auth.DigestAuthClient}
*/
public class Client {
private final static String HEADER_AGENT="User-Agent";

private final static String HEADER_AGENT="User-Agent";

/**
*
*
* @param post
* @throws AuthException
*/
public void setAuth(HttpPost post) throws AuthException {

}

public static HttpPost newPost(String url){
HttpPost postMethod = new HttpPost(url);
postMethod.setHeader(HEADER_AGENT, getUserAgent());
return postMethod;
}

private static String getUserAgent(){
String javaVersion = "Java/" + System.getProperty("java.version");
String os = System.getProperty("os.name") + " "
+ System.getProperty("os.arch") + " " + System.getProperty("os.version");
String sdk = "QiniuJava/" + Config.VERSION;
return sdk + " (" + os +") " + javaVersion;
}

/**
* Sends a http post request to the specified url.
*
*
* @param url
* the request url
* @return A general response
*/
public CallRet call(String url) {
HttpClient client = Http.getClient();
HttpPost postMethod = new HttpPost(url);
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
HttpPost postMethod = newPost(url);
try {
setAuth(postMethod);
HttpResponse response = client.execute(postMethod);
return handleResult(response);
} catch (Exception e) {
e.printStackTrace();
return new CallRet(400, e);
return new CallRet(Config.ERROR_CODE, e);
}
}

/**
* Sends a http post request to the specified url with a list of
* <code>NameValuePair<code>.
*
*
* @param url
* the request url
* @param nvps
* @return A general response
*/
public CallRet call(String url, List<NameValuePair> nvps) {
HttpClient client = Http.getClient();
HttpPost postMethod = new HttpPost(url);
HttpPost postMethod = newPost(url);
try {
StringEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8");
entity.setContentType("application/x-www-form-urlencoded");
postMethod.setEntity(entity);
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
setAuth(postMethod);
HttpResponse response = client.execute(postMethod);

return handleResult(response);
} catch (Exception e) {
e.printStackTrace();
return new CallRet(400, e);
return new CallRet(Config.ERROR_CODE, e);
}
}

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

try {
Expand All @@ -99,12 +111,12 @@ public CallRet callWithBinary(String url, AbstractHttpEntity entity) {
return handleResult(response);
} catch (Exception e) {
e.printStackTrace();
return new CallRet(400, e);
return new CallRet(Config.ERROR_CODE, e);
}
}

/**
*
*
* @param url
* the request url
* @param contentType
Expand All @@ -126,48 +138,47 @@ public CallRet callWithBinary(String url, String contentType, byte[] body) {
}

/**
*
*
* @param url
* @param requestEntity
* @return A general response format
*/
public CallRet callWithMultiPart(String url, MultipartEntity requestEntity) {
HttpPost postMethod = new HttpPost(url);
HttpPost postMethod = newPost(url);
postMethod.setEntity(requestEntity);
postMethod.setHeader(HEADER_AGENT,Config.USER_AGENT);
HttpClient client = Http.getClient();

try {
HttpResponse response = client.execute(postMethod);
return handleResult(response);
} catch (Exception e) {
e.printStackTrace();
return new CallRet(400, e);
return new CallRet(Config.ERROR_CODE, e);
}
}

/**
* Transforms a httpresponse to user expected format.
*
*
* @param response
* http response body
* @return a formated general response structure
*/
private CallRet handleResult(HttpResponse response) {
if (response == null || response.getStatusLine() == null) {
return new CallRet(400, "No response");
return new CallRet(Config.ERROR_CODE, "No response");
}

String responseBody;
try {
responseBody = EntityUtils.toString(response.getEntity(),"UTF-8");
} catch (Exception e) {
e.printStackTrace();
return new CallRet(400, e);
return new CallRet(Config.ERROR_CODE, e);
}

StatusLine status = response.getStatusLine();
int statusCode = (status == null) ? 400 : status.getStatusCode();
int statusCode = (status == null) ? Config.ERROR_CODE : status.getStatusCode();
return new CallRet(statusCode, responseBody);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/qiniu/api/resumableio/UploadBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;

import com.qiniu.api.config.Config;


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

return checkAndRetryUpload(url, start, len, time, ret);
} catch (Exception e) {
return new ChunkUploadCallRet(400, e);
return new ChunkUploadCallRet(Config.ERROR_CODE, e);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/qiniu/api/resumableio/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import com.qiniu.api.config.Config;
import com.qiniu.api.net.CallRet;
import com.qiniu.api.net.Client;

public class Util {
public static HttpPost buildUpPost(String url, String token) {
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", Config.USER_AGENT);
HttpPost post = Client.newPost(url);
post.setHeader("Authorization", "UpToken " + token);
return post;
}

public static CallRet handleResult(HttpResponse response) {
try {
StatusLine status = response.getStatusLine();
Expand All @@ -26,12 +26,12 @@ public static CallRet handleResult(HttpResponse response) {
response.getEntity(), "utf-8");
return new CallRet(statusCode, responseBody);
} catch (Exception e) {
CallRet ret = new CallRet(400, "can not load response.");
CallRet ret = new CallRet(Config.ERROR_CODE, "can not load response.");
ret.exception = e;
return ret;
}
}

public static long crc32(byte[] data){
CRC32 crc32 = new CRC32();
crc32.update(data);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/qiniu/api/rs/PutPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class PutPolicy {
public String persistentOps;

private long deadline;

/**
* 转码队列名,须预先开通
* 资源上传成功后,触发转码时指定独立的队列进行转码
*/
public String persistentPipeline;


public PutPolicy(String scope) {
Expand Down Expand Up @@ -100,6 +106,10 @@ public String marshal() throws JSONException {
if (this.persistentOps != null && this.persistentOps.length() > 0) {
stringer.key("persistentOps").value(this.persistentOps);
}
if(persistentPipeline != null && persistentPipeline.trim().length() > 0){
stringer.key("persistentPipeline").value(this.persistentPipeline);
}

stringer.key("deadline").value(this.deadline);
stringer.endObject();

Expand Down
Loading