|
@@ -2,6 +2,9 @@ package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Date;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@@ -19,6 +22,9 @@ import org.apache.http.util.EntityUtils;
|
|
import cn.hutool.core.lang.Tuple;
|
|
import cn.hutool.core.lang.Tuple;
|
|
import sun.misc.BASE64Encoder;
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
@SuppressWarnings("restriction")
|
|
@SuppressWarnings("restriction")
|
|
public class HttpClientUtil {
|
|
public class HttpClientUtil {
|
|
private static Map<String, HttpClientUtil> instanceMap = new ConcurrentHashMap<String, HttpClientUtil>();
|
|
private static Map<String, HttpClientUtil> instanceMap = new ConcurrentHashMap<String, HttpClientUtil>();
|
|
@@ -208,4 +214,44 @@ public class HttpClientUtil {
|
|
Tuple tuple = new Tuple(guid, imageBase64);
|
|
Tuple tuple = new Tuple(guid, imageBase64);
|
|
return tuple;
|
|
return tuple;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public synchronized void post_export(String url, String content, Integer timeout, Map<String, String> headerMap, HttpServletResponse response) throws Exception {
|
|
|
|
+ if (Constant.http_interval > 0) {
|
|
|
|
+ Thread.sleep(Constant.http_interval);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HttpPost httpost = new HttpPost(url);
|
|
|
|
+ if (headerMap != null) {
|
|
|
|
+ for (String key : headerMap.keySet()) {
|
|
|
|
+ httpost.setHeader(key, headerMap.get(key));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (timeout == null) {
|
|
|
|
+ timeout = 300000;
|
|
|
|
+ }
|
|
|
|
+ if (timeout != null) {
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
|
|
|
|
+ .setSocketTimeout(timeout).build();
|
|
|
|
+ httpost.setConfig(requestConfig);
|
|
|
|
+ }
|
|
|
|
+ StringEntity entity = new StringEntity(content, "UTF-8");
|
|
|
|
+ httpost.setEntity(entity);
|
|
|
|
+ entity.setContentType("application/json");
|
|
|
|
+ HttpResponse httpResponse = client.execute(httpost);
|
|
|
|
+ InputStream is = httpResponse.getEntity().getContent();
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS");
|
|
|
|
+ String xlsFileName = sdf.format(new Date()) + ".xlsx";
|
|
|
|
+ xlsFileName = URLEncoder.encode(xlsFileName, "UTF-8");
|
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + xlsFileName);
|
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
|
+ // 输出
|
|
|
|
+ int len = 1;
|
|
|
|
+ byte[] bytes = new byte[1024];
|
|
|
|
+ while ((len = is.read(bytes)) != -1) {
|
|
|
|
+ out.write(bytes, 0, len);
|
|
|
|
+ }
|
|
|
|
+ out.close();
|
|
|
|
+ is.close();
|
|
|
|
+ }
|
|
}
|
|
}
|