提交 23110049 authored 作者: 李炎's avatar 李炎

加速http

上级 4f1ebad1
......@@ -74,13 +74,13 @@
</dependency>
<dependency>
<groupId>client</groupId>
<artifactId>k3cloud-webapi-client</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/src/main/resources/lib/k3cloud-webapi-client.jar</systemPath>
</dependency>
<!--<dependency>-->
<!--<groupId>client</groupId>-->
<!--<artifactId>k3cloud-webapi-client</artifactId>-->
<!--<scope>system</scope>-->
<!--<version>1.0</version>-->
<!--<systemPath>${project.basedir}/src/main/resources/lib/k3cloud-webapi-client.jar</systemPath>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>httpmime</groupId>-->
......@@ -89,11 +89,12 @@
<!--<version>1.0</version>-->
<!--<systemPath>${project.basedir}/src/main/resources/lib/httpmime-4.1.1.jar</systemPath>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.1.1</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.apache.httpcomponents</groupId>-->
<!--<artifactId>httpmime</artifactId>-->
<!--<version>4.1.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>commons-httpclient</groupId>-->
......@@ -114,6 +115,18 @@
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.72</version>
......
......@@ -143,21 +143,5 @@ public class WebApi {
}
ConnectionKeepAliveStrategy myStrategy = new ConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator
(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase
("timeout")) {
return Long.parseLong(value) * 1000;
}
}
return 60 * 1000;//如果没有约定,则默认定义时长为60s
}
};
}
package com.santos.iost.dao;
import com.alibaba.fastjson.JSON;
import com.santos.iost.utils.HttpClientUtil;
import com.santos.iost.utils.HttpUtil;
import com.santos.iost.utils.JsonUtil;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
......@@ -34,26 +36,29 @@ public class SoSsDao {
//请求主体
public String requestK3Api(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====head====="+paramsMap+"====head====");
String post = HttpUtil.post(requestUrl + getMaterialUrl + "?token=" + token, paramsMap, hreader);
// String post = HttpUtil.post(requestUrl + getMaterialUrl + "?token=" + token, paramsMap, hreader);//以弃用
String post = HttpClientUtil.doPostJson(requestUrl + getMaterialUrl + "?token=" + token, paramsMap);
System.out.println(token);
// System.out.println("================response=============="+post+"=================response===================");
return post;
}
//请求主体
public String requestK3ApiDetail(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====Detail====="+paramsMap+"====Detail====");
// String post = HttpUtil.post(requestUrl + getMaterialUrl + "?token=" + token, paramsMap, hreader);
String post = HttpClientUtil.doPostJson(requestUrl + getMaterialUrl + "?token=" + token, paramsMap);
// System.out.println(token);
// System.out.println("================response=============="+post+"=================response===================");
return post;
}
//
public String setK3Api(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====head====="+paramsMap+"====head====");
String post = HttpUtil.post(requestUrl + getMaterialUrl + "?token=" + token, paramsMap, hreader);
String post = HttpClientUtil.doPostJson(requestUrl + getMaterialUrl + "?token=" + token, paramsMap);
System.out.println(token);
// System.out.println("================response=============="+post+"=================response===================");
return post;
}
//请求主体
public String requestK3ApiDetail(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====Detail====="+paramsMap+"====Detail====");
String post = HttpUtil.post(requestUrl + getMaterialUrl + "?token=" + token, paramsMap, hreader);
// System.out.println(token);
// System.out.println("================response=============="+post+"=================response===================");
return post;
}
}
......@@ -8,17 +8,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.santos.iost.dao.SoSsDao;
import com.santos.iost.dto.SoSsRequestData;
import com.santos.iost.dto.SoSsResponseDate;
import com.santos.iost.utils.HttpUtil;
import com.santos.iost.utils.HttpUtils;
import com.santos.iost.utils.JsonUtil;
import com.santos.iost.utils.StringUtil;
import com.santos.iost.utils.*;
import com.santos.iost.vo.SoSsRequestVo;
import kingdee.bos.webapi.client.K3CloudApiClient;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
......@@ -70,7 +69,7 @@ class JintaiDomeApplicationTests {
//
// Map<String, String> hreader = new HashMap<>();
// hreader.put("Content-Type", "application/json");
//
// String post = HttpClientUtil.doPostJson(getGetMaterialUrl + token,JsonUtil.Mapjson(paramsMap));
// String post = HttpUtil.post(getGetMaterialUrl + token, JsonUtil.Mapjson(paramsMap), hreader);
// System.out.println(post);
}
......@@ -116,13 +115,12 @@ class JintaiDomeApplicationTests {
@Test
void asd() throws Exception {
// System.out.println(SoSsDao.token);
// System.out.println(StringUtil.isNumber("1473048265"));
// System.out.println(TimeStamp2Date("1609499999", "yyyy-MM-dd HH:mm:ss"));
// System.out.println(TimeStamp2Date("1609999999", "yyyy-MM-dd HH:mm:ss"));
}
public static String TimeStamp2Date(String timestampString, String formats) {
// System.out.println(TimeStamp2Date("1609499999", "yyyy-MM-dd HH:mm:ss"));
// System.out.println(TimeStamp2Date("1609999999", "yyyy-MM-dd HH:mm:ss"));
if (TextUtils.isEmpty(formats))
formats = "yyyy-MM-dd HH:mm:ss";
Long timestamp = Long.parseLong(timestampString) * 1000;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论