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

加速http

上级 4f1ebad1
...@@ -74,13 +74,13 @@ ...@@ -74,13 +74,13 @@
</dependency> </dependency>
<dependency> <!--<dependency>-->
<groupId>client</groupId> <!--<groupId>client</groupId>-->
<artifactId>k3cloud-webapi-client</artifactId> <!--<artifactId>k3cloud-webapi-client</artifactId>-->
<scope>system</scope> <!--<scope>system</scope>-->
<version>1.0</version> <!--<version>1.0</version>-->
<systemPath>${project.basedir}/src/main/resources/lib/k3cloud-webapi-client.jar</systemPath> <!--<systemPath>${project.basedir}/src/main/resources/lib/k3cloud-webapi-client.jar</systemPath>-->
</dependency> <!--</dependency>-->
<!--<dependency>--> <!--<dependency>-->
<!--<groupId>httpmime</groupId>--> <!--<groupId>httpmime</groupId>-->
...@@ -89,11 +89,12 @@ ...@@ -89,11 +89,12 @@
<!--<version>1.0</version>--> <!--<version>1.0</version>-->
<!--<systemPath>${project.basedir}/src/main/resources/lib/httpmime-4.1.1.jar</systemPath>--> <!--<systemPath>${project.basedir}/src/main/resources/lib/httpmime-4.1.1.jar</systemPath>-->
<!--</dependency>--> <!--</dependency>-->
<dependency> <!--<dependency>-->
<groupId>org.apache.httpcomponents</groupId> <!--<groupId>org.apache.httpcomponents</groupId>-->
<artifactId>httpmime</artifactId> <!--<artifactId>httpmime</artifactId>-->
<version>4.1.1</version> <!--<version>4.1.1</version>-->
</dependency> <!--</dependency>-->
<!--<dependency>--> <!--<dependency>-->
<!--<groupId>commons-httpclient</groupId>--> <!--<groupId>commons-httpclient</groupId>-->
...@@ -114,6 +115,18 @@ ...@@ -114,6 +115,18 @@
</dependency> </dependency>
<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> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.72</version> <version>1.2.72</version>
......
...@@ -143,21 +143,5 @@ public class WebApi { ...@@ -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; package com.santos.iost.dao;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.santos.iost.utils.HttpClientUtil;
import com.santos.iost.utils.HttpUtil; import com.santos.iost.utils.HttpUtil;
import com.santos.iost.utils.JsonUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -34,26 +36,29 @@ public class SoSsDao { ...@@ -34,26 +36,29 @@ public class SoSsDao {
//请求主体 //请求主体
public String requestK3Api(String getMaterialUrl, String paramsMap) throws Exception { public String requestK3Api(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====head====="+paramsMap+"====head===="); 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(token);
// System.out.println("================response=============="+post+"=================response==================="); // System.out.println("================response=============="+post+"=================response===================");
return post; 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 { public String setK3Api(String getMaterialUrl, String paramsMap) throws Exception {
System.out.println("====head====="+paramsMap+"====head===="); 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(token);
// System.out.println("================response=============="+post+"=================response==================="); // System.out.println("================response=============="+post+"=================response===================");
return post; 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; ...@@ -8,17 +8,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.santos.iost.dao.SoSsDao; import com.santos.iost.dao.SoSsDao;
import com.santos.iost.dto.SoSsRequestData; import com.santos.iost.dto.SoSsRequestData;
import com.santos.iost.dto.SoSsResponseDate; import com.santos.iost.dto.SoSsResponseDate;
import com.santos.iost.utils.HttpUtil; import com.santos.iost.utils.*;
import com.santos.iost.utils.HttpUtils;
import com.santos.iost.utils.JsonUtil;
import com.santos.iost.utils.StringUtil;
import com.santos.iost.vo.SoSsRequestVo; import com.santos.iost.vo.SoSsRequestVo;
import kingdee.bos.webapi.client.K3CloudApiClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.ResponseHandler; import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
...@@ -70,7 +69,7 @@ class JintaiDomeApplicationTests { ...@@ -70,7 +69,7 @@ class JintaiDomeApplicationTests {
// //
// Map<String, String> hreader = new HashMap<>(); // Map<String, String> hreader = new HashMap<>();
// hreader.put("Content-Type", "application/json"); // 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); // String post = HttpUtil.post(getGetMaterialUrl + token, JsonUtil.Mapjson(paramsMap), hreader);
// System.out.println(post); // System.out.println(post);
} }
...@@ -116,13 +115,12 @@ class JintaiDomeApplicationTests { ...@@ -116,13 +115,12 @@ class JintaiDomeApplicationTests {
@Test @Test
void asd() throws Exception { 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) { 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)) if (TextUtils.isEmpty(formats))
formats = "yyyy-MM-dd HH:mm:ss"; formats = "yyyy-MM-dd HH:mm:ss";
Long timestamp = Long.parseLong(timestampString) * 1000; Long timestamp = Long.parseLong(timestampString) * 1000;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论