update
This commit is contained in:
@@ -90,19 +90,19 @@ public class HttpRequestOptions {
|
||||
private RequestConfig requestConfig;
|
||||
|
||||
/**
|
||||
* 解决多线程下载时,strean被close的问题
|
||||
* 当前请求的输出流
|
||||
*/
|
||||
private static final ThreadLocal<OutputStream> outs = new ThreadLocal<OutputStream>();
|
||||
private OutputStream out;
|
||||
|
||||
/**
|
||||
* 解决多线程处理时,url被覆盖问题
|
||||
* 当前请求的 URL
|
||||
*/
|
||||
private static final ThreadLocal<String> urls = new ThreadLocal<String>();
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 解决多线程处理时,url被覆盖问题
|
||||
* 当前请求的参数,随实例保存,避免线程复用时混入上一次请求的数据
|
||||
*/
|
||||
private static final ThreadLocal<Map<String,Object>> maps = new ThreadLocal<Map<String,Object>>();
|
||||
private Map<String, Object> parameters;
|
||||
|
||||
/**
|
||||
* @param client HttpClient对象
|
||||
@@ -118,7 +118,7 @@ public class HttpRequestOptions {
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public HttpRequestOptions url(String url) {
|
||||
urls.set(url);
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -176,13 +176,13 @@ public class HttpRequestOptions {
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public HttpRequestOptions map(Map<String, Object> map) {
|
||||
Map<String, Object> m = maps.get();
|
||||
if(m == null || map.isEmpty()){
|
||||
m = map;
|
||||
}else {
|
||||
m.putAll(map);
|
||||
if (map == null) {
|
||||
parameters = null;
|
||||
} else if (parameters == null || map.isEmpty()) {
|
||||
parameters = new HashMap<>(map);
|
||||
} else {
|
||||
parameters.putAll(map);
|
||||
}
|
||||
maps.set(m);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -192,9 +192,8 @@ public class HttpRequestOptions {
|
||||
*/
|
||||
public HttpRequestOptions json(String json) {
|
||||
this.json = json;
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(HttpEntityBuilder.ENTITY_JSON, json);
|
||||
maps.set(map);
|
||||
parameters = new HashMap<>();
|
||||
parameters.put(HttpEntityBuilder.ENTITY_JSON, json);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -222,14 +221,12 @@ public class HttpRequestOptions {
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public HttpRequestOptions files(String[] filePaths, String inputName, boolean forceRemoveContentTypeChraset) {
|
||||
Map<String, Object> m = maps.get();
|
||||
if(m == null || m.isEmpty()){
|
||||
m = new HashMap<String, Object>();
|
||||
if (parameters == null) {
|
||||
parameters = new HashMap<>();
|
||||
}
|
||||
m.put(HttpEntityBuilder.ENTITY_MULTIPART, filePaths);
|
||||
m.put(HttpEntityBuilder.ENTITY_MULTIPART+".name", inputName);
|
||||
m.put(HttpEntityBuilder.ENTITY_MULTIPART+".rmCharset", forceRemoveContentTypeChraset);
|
||||
maps.set(m);
|
||||
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART, filePaths);
|
||||
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART+".name", inputName);
|
||||
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART+".rmCharset", forceRemoveContentTypeChraset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -264,7 +261,7 @@ public class HttpRequestOptions {
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public HttpRequestOptions out(OutputStream out) {
|
||||
outs.set(out);
|
||||
this.out = out;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -320,7 +317,7 @@ public class HttpRequestOptions {
|
||||
}
|
||||
|
||||
public String url() {
|
||||
return urls.get();
|
||||
return url;
|
||||
}
|
||||
|
||||
public HttpMethods method() {
|
||||
@@ -336,7 +333,7 @@ public class HttpRequestOptions {
|
||||
}
|
||||
|
||||
public Map<String, Object> map() {
|
||||
return maps.get();
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public String json() {
|
||||
@@ -356,7 +353,7 @@ public class HttpRequestOptions {
|
||||
}
|
||||
|
||||
public OutputStream out() {
|
||||
return outs.get();
|
||||
return out;
|
||||
}
|
||||
|
||||
public RequestConfig requestConfig() {
|
||||
|
||||
Reference in New Issue
Block a user