Explorar o código

update:添加网络请求方式,OKHTTP

zhangweixin %!s(int64=2) %!d(string=hai) anos
pai
achega
a44eab4f87

+ 6 - 0
ibms-data-sdk/pom.xml

@@ -222,6 +222,12 @@
 			<artifactId>sailfish</artifactId>
 			<version>0.0.52</version>
 		</dependency>
+		<dependency>
+			<groupId>com.squareup.okhttp3</groupId>
+			<artifactId>okhttp</artifactId>
+			<version>3.10.0</version>
+		</dependency>
+
 	</dependencies>
 
 	<build>

+ 1 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectApi.java

@@ -1,8 +1,6 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.persagy.ibms.data.sdk.util.ExportUtil;
+
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;

+ 14 - 7
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectUtil.java

@@ -7,13 +7,16 @@ import java.util.concurrent.ConcurrentHashMap;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.core.util.LogUtil;
 import com.persagy.ibms.data.sdk.util.ConfigRedirect;
 import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.HttpClientUtil;
 
+import com.persagy.ibms.data.sdk.util.OkHttpUtils;
 import lombok.extern.slf4j.Slf4j;
+import okhttp3.Call;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -65,7 +68,7 @@ public class RedirectUtil {
     }
 
     public static Object redirectInner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap,HttpServletRequest request,HttpServletResponse response) throws Exception {
-        String resultString;
+        final String[] resultString = new String[1];
         String url = ConfigRedirect.url;
         String url_ori = url;
         JSONObject urlParams = sql_json.getJSONObject("urlParams");
@@ -93,7 +96,8 @@ public class RedirectUtil {
         otherMap.put("Url", url_ori);
         log.warn(url_ori);
         if (ConfigRedirect.http_request_type.equals("get")) {
-            resultString = HttpClientUtil.instance("redirect").get(url, null, ConfigRedirect.headerMap);
+
+            resultString[0] = HttpClientUtil.instance("redirect").get(url, null, ConfigRedirect.headerMap);
         } else {
             Object postBody = sql_json.get("postBody");
             String postString;
@@ -108,22 +112,25 @@ public class RedirectUtil {
             try {
                 if(url.contains("login"))
                 {
-                    resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,null);
+                    resultString[0] = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,null);
                 }
                 else
                 {
-                    resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
+//                    Map<String, String> map = JSONObject.parseObject(postString, new TypeReference<Map<String, String>>() {});
+                    resultString[0] = OkHttpUtils.builder().url(url).post(false, postString).sync();
+
+//                    resultString[0] = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
                 }
             } catch (Exception e) {
                 log.error("redirect异常", e);
-                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,request);
+                resultString[0] = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,request);
             }
         }
         Object result;
         try {
-            result = JSON.parse(resultString);
+            result = JSON.parse(resultString[0]);
         } catch (Exception e) {
-            result = resultString;
+            result = resultString[0];
         }
         return result;
     }

+ 3 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -19,6 +19,7 @@ import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.EntityUtils;
 
@@ -33,9 +34,8 @@ import javax.servlet.http.HttpServletResponse;
 public class HttpClientUtil {
     private static Map<String, HttpClientUtil> instanceMap = new ConcurrentHashMap<String, HttpClientUtil>();
 
-    private HttpClient client;
-
-    public static HttpClientUtil instance() {
+    private  HttpClient client;
+    public HttpClientUtil instance() {
         HttpClientUtil result = instance("default");
         return result;
     }

+ 447 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/OkHttpUtils.java

@@ -0,0 +1,447 @@
+package com.persagy.ibms.data.sdk.util;
+
+import com.alibaba.fastjson.JSON;
+import okhttp3.*;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.lang.reflect.Field;
+
+
+/**
+ * OkHttp
+ */
+public class OkHttpUtils {
+
+    private static volatile OkHttpClient okHttpClient = null;
+    private static volatile Semaphore semaphore = null;
+    private Map<String, String> headerMap;
+    private Map<String, String> paramMap;
+    private String url;
+    private Request.Builder request;
+    private ConnectionPool connectionPool = new ConnectionPool(1500,5L, TimeUnit.MINUTES);
+//   MediaType.parse("application/json; charset=utf-8");
+
+    /**
+     * 初始化okHttpClient,并且允许https访问
+     */
+    private OkHttpUtils() {
+        if (okHttpClient == null) {
+            synchronized (OkHttpUtils.class) {
+                if (okHttpClient == null) {
+                    TrustManager[] trustManagers = buildTrustManagers();
+                    okHttpClient = new OkHttpClient.Builder()
+                            .connectTimeout(15, TimeUnit.SECONDS)
+                            .writeTimeout(20, TimeUnit.SECONDS)
+                            .readTimeout(20, TimeUnit.SECONDS)
+                            .sslSocketFactory(createSSLSocketFactory(trustManagers), (X509TrustManager) trustManagers[0])
+                            .hostnameVerifier((hostName, session) -> true)
+                            .retryOnConnectionFailure(true)
+                            .connectionPool(connectionPool)
+                            .build();
+                    addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 用于异步请求时,控制访问线程数,返回结果
+     *
+     * @return
+     */
+    private static Semaphore getSemaphoreInstance() {
+        //只能1个线程同时访问
+        synchronized (OkHttpUtils.class) {
+            if (semaphore == null) {
+                semaphore = new Semaphore(0);
+            }
+        }
+        return semaphore;
+    }
+
+
+    /**
+     * 创建OkHttpUtils
+     *
+     * @return
+     */
+    public static OkHttpUtils builder() {
+        return new OkHttpUtils();
+    }
+
+
+    /**
+     * 添加url
+     *
+     * @param url
+     * @return
+     */
+    public OkHttpUtils url(String url) {
+        this.url = url;
+        return this;
+    }
+
+
+    /**
+     * 添加参数
+     *
+     * @param key   参数名
+     * @param value 参数值
+     * @return
+     */
+    public OkHttpUtils addParam(String key, String value) {
+        if (paramMap == null) {
+            paramMap = new LinkedHashMap<>(16);
+        }
+        paramMap.put(key, value);
+        return this;
+    }
+
+
+    /**
+     * 添加请求头
+     *
+     * @param key   参数名
+     * @param value 参数值
+     * @return
+     */
+    public OkHttpUtils addHeader(String key, String value) {
+        if (headerMap == null) {
+            headerMap = new LinkedHashMap<>(16);
+        }
+        headerMap.put(key, value);
+        return this;
+    }
+
+
+    /**
+     * 初始化get方法
+     *
+     * @return
+     */
+    public OkHttpUtils get() {
+        request = new Request.Builder().get();
+        StringBuilder urlBuilder = new StringBuilder(url);
+        if (paramMap != null) {
+            urlBuilder.append("?");
+            try {
+                for (Map.Entry<String, String> entry : paramMap.entrySet()) {
+                    urlBuilder.append(URLEncoder.encode(entry.getKey(), "utf-8")).
+                            append("=").
+                            append(URLEncoder.encode(entry.getValue(), "utf-8")).
+                            append("&");
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            urlBuilder.deleteCharAt(urlBuilder.length() - 1);
+        }
+        request.url(urlBuilder.toString());
+        return this;
+    }
+
+
+    /**
+     * 初始化post方法
+     *
+     * @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw
+     *                   false等于普通的表单提交
+     * @return
+     */
+    public OkHttpUtils post(boolean isJsonPost) {
+        RequestBody requestBody;
+        if (isJsonPost) {
+            String json = "";
+            if (paramMap != null) {
+                json = JSON.toJSONString(paramMap);
+            }
+            requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
+        } else {
+            FormBody.Builder formBody = new FormBody.Builder();
+            if (paramMap != null) {
+                paramMap.forEach(formBody::add);
+            }
+            requestBody = formBody.build();
+        }
+        request = new Request.Builder().post(requestBody).url(url);
+        return this;
+    }
+
+    /**
+     * 初始化post方法
+     *
+     * @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw
+     *                   false等于普通的表单提交
+     * @return
+     */
+    public OkHttpUtils post(boolean isJsonPost,Map<String, String> paramMap) {
+        RequestBody requestBody;
+        if (isJsonPost) {
+            String json = "";
+            if (paramMap != null) {
+                json = JSON.toJSONString(paramMap);
+            }
+            requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
+        } else {
+            FormBody.Builder formBody = new FormBody.Builder();
+            if (paramMap != null) {
+                paramMap.forEach(formBody::add);
+            }
+            requestBody = formBody.build();
+        }
+        request = new Request.Builder().post(requestBody).url(url);
+        return this;
+    }
+
+    /**
+     * 初始化post方法
+     *
+     * @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw
+     *                   false等于普通的表单提交
+     * @return
+     */
+    public OkHttpUtils post(boolean isJsonPost,String paramMap) {
+        RequestBody requestBody;
+        if (isJsonPost) {
+            String json = "";
+            if (paramMap != null) {
+                json = JSON.toJSONString(paramMap);
+            }
+            requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
+        } else {
+            MediaType JSON = MediaType.parse("application/json; charset=utf-8");
+            requestBody = FormBody.create(JSON, paramMap);
+//            FormBody.Builder formBody = new FormBody.Builder();
+//            if (paramMap != null) {
+//                paramMap.forEach(formBody::add);
+//            }
+//            requestBody = formBody.build();
+        }
+        request = new Request.Builder().post(requestBody).url(url);
+        return this;
+    }
+
+
+    /**
+     * 同步请求
+     *
+     * @return
+     */
+    public String sync() {
+        setHeader(request);
+        try {
+            Response response = okHttpClient.newCall(request.build()).execute();
+            assert response.body() != null;
+            return response.body().string();
+        } catch (IOException e) {
+            e.printStackTrace();
+            return "请求失败:" + e.getMessage();
+        }
+    }
+
+
+    /**
+     * 异步请求,有返回值
+     */
+    public String async() {
+        StringBuilder buffer = new StringBuilder("");
+        setHeader(request);
+        okHttpClient.newCall(request.build()).enqueue(new Callback() {
+            @Override
+            public void onFailure(Call call, IOException e) {
+                buffer.append("请求出错:").append(e.getMessage());
+            }
+
+
+            @Override
+            public void onResponse(Call call, Response response) throws IOException {
+                assert response.body() != null;
+                buffer.append(response.body().string());
+                getSemaphoreInstance().release();
+            }
+        });
+        try {
+            getSemaphoreInstance().acquire();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        return buffer.toString();
+    }
+
+
+    /**
+     * 异步请求,带有接口回调
+     *
+     * @param callBack
+     */
+    public void async(ICallBack callBack) {
+        setHeader(request);
+        okHttpClient.newCall(request.build()).enqueue(new Callback() {
+            @Override
+            public void onFailure(Call call, IOException e) {
+                callBack.onFailure(call, e.getMessage());
+            }
+
+
+            @Override
+            public void onResponse(Call call, Response response) throws IOException {
+                assert response.body() != null;
+                callBack.onSuccessful(call, response.body().string());
+            }
+        });
+    }
+
+
+    /**
+     * 为request添加请求头
+     *
+     * @param request
+     */
+    private void setHeader(Request.Builder request) {
+        if (headerMap != null) {
+            try {
+                for (Map.Entry<String, String> entry : headerMap.entrySet()) {
+                    request.addHeader(entry.getKey(), entry.getValue());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+
+
+    /**
+     * 生成安全套接字工厂,用于https请求的证书跳过
+     *
+     * @return
+     */
+    private static SSLSocketFactory createSSLSocketFactory(TrustManager[] trustAllCerts) {
+        SSLSocketFactory ssfFactory = null;
+        try {
+            SSLContext sc = SSLContext.getInstance("SSL");
+            sc.init(null, trustAllCerts, new SecureRandom());
+            ssfFactory = sc.getSocketFactory();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ssfFactory;
+    }
+
+
+    private static TrustManager[] buildTrustManagers() {
+        return new TrustManager[]{
+                new X509TrustManager() {
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] chain, String authType) {
+                    }
+
+
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] chain, String authType) {
+                    }
+
+
+                    @Override
+                    public X509Certificate[] getAcceptedIssuers() {
+                        return new X509Certificate[]{};
+                    }
+                }
+        };
+    }
+
+    /**
+     * 将Object对象里面的属性和值转化成Map对象
+     *
+     * @param obj
+     * @return
+     * @throws IllegalAccessException
+     */
+    public static Map<String, String> objectToMap(Object obj) throws IllegalAccessException {
+        Map<String, String> map = new HashMap<String,String>();
+        Class<?> clazz = obj.getClass();
+        for (Field field : clazz.getDeclaredFields()) {
+            field.setAccessible(true);
+            String fieldName = field.getName();
+            Object value = field.get(obj);
+            map.put(fieldName, value.toString());
+        }
+        return map;
+    }
+
+
+    /**
+     * 自定义一个接口回调
+     */
+    public interface ICallBack {
+
+
+        void onSuccessful(Call call, String data);
+
+
+        void onFailure(Call call, String errorMsg);
+
+
+    }
+}
+//使用教程
+//public static void main(String[] args) {
+//        // get请求,方法顺序按照这种方式,切记选择post/get一定要放在倒数第二,同步或者异步倒数第一,才会正确执行
+//        OkHttpUtils.builder().url("请求地址,http/https都可以")
+//        // 有参数的话添加参数,可多个
+//        .addParam("参数名", "参数值")
+//        .addParam("参数名", "参数值")
+//        // 也可以添加多个
+//        .addHeader("Content-Type", "application/json; charset=utf-8")
+//        .get()
+//        // 可选择是同步请求还是异步请求
+//        //.async();
+//        .sync();
+//
+//
+//        // post请求,分为两种,一种是普通表单提交,一种是json提交
+//        OkHttpUtils.builder().url("请求地址,http/https都可以")
+//        // 有参数的话添加参数,可多个
+//        .addParam("参数名", "参数值")
+//        .addParam("参数名", "参数值")
+//        // 也可以添加多个
+//        .addHeader("Content-Type", "application/json; charset=utf-8")
+//        // 如果是true的话,会类似于postman中post提交方式的raw,用json的方式提交,不是表单
+//        // 如果是false的话传统的表单提交
+//        .post(true)
+//        .sync();
+//
+//        // 选择异步有两个方法,一个是带回调接口,一个是直接返回结果
+//        OkHttpUtils.builder().url("")
+//        .post(false)
+//        .async();
+//
+//
+//        OkHttpUtils.builder().url("").post(false).async(new OkHttpUtils.ICallBack() {
+//@Override
+//public void onSuccessful(Call call, String data) {
+//        // 请求成功后的处理
+//        }
+//
+//
+//@Override
+//public void onFailure(Call call, String errorMsg) {
+//        // 请求失败后的处理
+//        }
+//        });
+
+//        }

+ 268 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/OkhttpUtil.kt

@@ -0,0 +1,268 @@
+///*
+// * ********************************************************************************************************************
+// *                     :*$@@%$*:                         ;:                ;;    ;;
+// *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+// *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+// *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+// *                  =@*                                  %!              @ $= % %@=   =%@!      %=
+// *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+// *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+// *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+// *         $@*   ;@@@%=!:                *@*
+// *         =@$    ;;;!=%@@@@=!           =@!
+// *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2018.  北京上格云技术有限公司
+// *           ;%@@$=$@@%*       *@@@$=%@@%;
+// *              ::;::             ::;::                                              All rights reservad.
+// * ********************************************************************************************************************
+// */
+//
+//package com.persagy.ibms.data.sdk.util
+//
+//import okhttp3.*
+//import java.io.File
+//import java.util.concurrent.TimeUnit
+//
+//
+///**
+// * Created by mengxy on 2018/10/16.
+// * 创建日期:2018/10/16on ${time}
+// * 描述:
+// * 作者:zwx
+// */
+//object OkhttpUtil {
+//
+//    /** http客户端 */
+//    private val httpClient: OkHttpClient by lazy {
+//        val client = OkHttpClient().newBuilder()
+//                .readTimeout(600, TimeUnit.SECONDS)
+//                .writeTimeout(600 , TimeUnit.SECONDS)
+//                .connectTimeout(600 , TimeUnit.SECONDS)
+//                .cache(cache).build()
+//        client
+//    }
+//
+//    /** 缓存 路径 */
+//    private val cacheFile = File(getContext().cacheDir, "cache")
+//    /**  缓存时间*/
+//    private val cache = Cache(cacheFile, (1024 * 1024 * 100).toLong()) //100Mb
+//    private val JSON = MediaType.parse("application/json; charset=utf-8")
+//
+//    /**
+//     * post请求 json
+//     *
+//     * 不能私有
+//     */
+//    fun postRequestJson(url: String, json: String): String {
+//        val jsonBody = FormBody.create(JSON, json)
+//        val request = Request.Builder()
+//                .url(url)
+//                .post(jsonBody)
+//                .build()
+//        val call = httpClient.newCall(request)
+//        try {
+//            val response = call.execute()
+//            response.code()
+//            if (response.isSuccessful) {
+////                LogUtils.e("请求成功code${response.code()},url=${url}")
+//            } else {
+////                LogUtils.e("请求成功code${response.code()},url=${url}")
+//            }
+//            return response.body()!!.string()
+//        } catch (e: Throwable) {
+//            e.printStackTrace()
+//            return ""
+//        }
+//        return ""
+//    } // Function postRequest()
+//
+//    /**
+//     * post请求 json
+//     *
+//     * 不能私有
+//     */
+//    fun postRequestJson(url: String, json: String,projectId:String): String {
+//        try {
+////        val JSON = MediaType.parse("application/json;")
+//        val jsonBody = FormBody.create(JSON, json)
+//        val request = Request.Builder()
+//                .url(url)
+//                .post(jsonBody)
+//                .addHeader("projectId",projectId)
+//                .addHeader("appId","app")
+//                .addHeader("userId",Opt.account)
+//                .build()
+//
+//        val response = httpClient.newCall(request).execute()
+////            LogUtils.e("请求成功code1${response.toJson()}")
+////            val response = call.execute()
+//            response.code()
+//            if (response.isSuccessful) {
+////                LogUtils.e("请求成功code2${response.code()},url=${url}")
+//            } else {
+////                LogUtils.e("请求成功code3${response.code()},url=${url}")
+//            }
+//            return response.body()!!.string()
+//        } catch (e: Throwable) {
+//            e.printStackTrace()
+//            return ""
+//        }
+//        return ""
+//    } // Function postRequest()
+//
+//    fun postRequestJsonNoBody(url: String,projectId:String): String {
+//        try {
+////        val JSON = MediaType.parse("application/json;")
+////            val jsonBody = FormBody.create(JSON, json)
+//
+//            val body = FormBody.Builder().build()
+//            val request = Request.Builder()
+//                    .url(url)
+////                    .post(jsonBody)
+//                    .post(body)
+//                    .addHeader("projectId",projectId)
+//                    .addHeader("appId","app")
+//                    .addHeader("userId",Opt.account)
+//                    .build()
+//
+//            val response = httpClient.newCall(request).execute()
+//            LogUtils.e("请求成功code1${response.toJson()}")
+////            val response = call.execute()
+//            response.code()
+//            if (response.isSuccessful) {
+//                LogUtils.e("请求成功code2${response.code()},url=${url}")
+//            } else {
+//                LogUtils.e("请求成功code3${response.code()},url=${url}")
+//            }
+//            return response.body()!!.string()
+//        } catch (e: Throwable) {
+//            e.printStackTrace()
+//            return ""
+//        }
+//        return ""
+//    } // Function postRequest()
+//
+//    /**
+//     * post 对象
+//     */
+//    inline fun <reified T> postObj(url: String, requestBody: Any, namingPolicy: FieldNamingPolicy? = null): T {
+//        val responseJson = postRequestJson(url, requestBody.toJson())
+////        LogUtils.e("数据 :${ responseJson.toJson()}")
+//        return SJsonUtil.fromJson<T>(responseJson)
+//    } // Function postObj()
+//
+//    /**
+//     * post 对象
+//     */
+//    inline fun <reified T> postObj(url: String, requestBody: Any?, projectId: String,namingPolicy: FieldNamingPolicy? = null): T {
+//
+//        var responseJson: String
+//        if (requestBody!=null){
+////            LogUtils.e("requestBody数据 :${ requestBody.toJson()}")
+//            responseJson = postRequestJson(url, requestBody!!.toJson(),projectId)
+//        }else{
+//            responseJson = postRequestJsonNoBody(url,projectId)
+//        }
+////        val responseJson = postRequestJson(url, requestBody!!.toJson(),projectId)
+////        LogUtils.e("数据 :${ responseJson.toJson()}")
+//        return SJsonUtil.fromJson<T>(responseJson)
+//    } // Function postObj()
+//
+//
+//    /**
+//     * get 对象
+//     */
+//    inline fun <reified T> getObj(url: String, namingPolicy: FieldNamingPolicy? = null): T {
+//        val responseJson = getRequest(url)
+//        return SJsonUtil.fromJson(responseJson)
+//    } // Function postObj()
+//
+//    /**
+//     * get 对象
+//     */
+//    inline fun <reified T> getObj(url: String,projectId: String, namingPolicy: FieldNamingPolicy? = null): T {
+//        val responseJson = getRequest(url,projectId)
+//        LogUtils.e("请求的数据${responseJson}")
+//        return SJsonUtil.fromJson(responseJson)
+//    } // Function postObj()
+//
+//    /**
+//     *  get 请求
+//     */
+//    fun getRequest(url: String): String {
+//        val request = Request.Builder()
+//                .url(url)
+//                .get()
+//                .build()
+//        val call = httpClient.newCall(request)
+//        try {
+//            val response = call.execute()
+//            if (response.isSuccessful) {
+////                LogUtils.e("请求成功code${response.code()},url=${url}")
+//            } else {
+////                LogUtils.e("请求失败code${response.code()},url=${url}")
+//            }
+//            return response.body()!!.string()
+//        } catch (e: Throwable) {
+//            e.printStackTrace()
+//        }
+//        return ""
+//    }
+//
+//    /**
+//     *  get 请求
+//     */
+//    fun getRequest(url: String,projectId: String): String {
+//        val request = Request.Builder()
+//                .url(url)
+//                .addHeader("ProjectId",projectId)
+//                .get()
+//                .build()
+//        val call = httpClient.newCall(request)
+//        try {
+//            val response = call.execute()
+//            if (response.isSuccessful) {
+////                LogUtils.e("请求成功code${response.code()},url=${url}")
+//            } else {
+////                LogUtils.e("请求失败code${response.code()},url=${url}")
+//            }
+//            return response.body()!!.string()
+//        } catch (e: Throwable) {
+//            e.printStackTrace()
+//        }
+//        return ""
+//    }
+//
+//    //http://prod-data.oss-cn-beijing.aliyuncs.com/test%2Ffiles%2Frevit%2FFl110108000327d8f006c39f49feb40e24a7ef22323220181119025802bim.jsonz?OSSAccessKeyId=LTAIHLlfCwmMRbV4&Expires=1542614466&Signature=RqDeGJn2DvnoqQOoUdQAyihvf1A%3D
+//
+//
+//    /**
+//     * 下载图形文件Gzip
+//     */
+//    fun getGzipMap(url: String): String {
+//        try {
+//            var isGzip = false
+//            val request = Request.Builder()
+//                    .url(url)
+//                    .get()
+//                    .header("Accept-Encoding", "gzip")
+//                    .build()
+//            val call = httpClient.newCall(request)
+//
+//            val response = call.execute()
+//            if (response.isSuccessful) {
+////                LogUtils.e("请求成功code${response.code()},url=${url}")
+//            } else {
+////                LogUtils.e("请求失败code${response.code()},url=${url}")
+//            }
+//            return  GzipUtil.uncompressToString(response.body()!!.bytes())
+//        } catch (e: Exception) {
+//            e.printStackTrace()
+//            return ""
+//        }
+//        return ""
+//
+//    }
+//
+//
+//
+//}

+ 2 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDDownloadUtil.java

@@ -1032,6 +1032,7 @@ public class RWDDownloadUtil {
         try {
             String post_result = HttpClientUtil.instance("rwd").post_compress(post_url, param.toJSONString());
             try {
+
                 JSONObject resultJSON = JSON.parseObject(post_result);
                 if (!resultJSON.getString("result").equals("success")) {
                     throw new Exception(post_url + "\n" + param.toJSONString() + "\n" + post_result);
@@ -1039,6 +1040,7 @@ public class RWDDownloadUtil {
                 result = resultJSON.getJSONArray("data");
                 result = result == null ? new JSONArray() : result;
             } catch (Exception e) {
+                e.printStackTrace();
                 throw new Exception(post_url + "\n" + param.toJSONString() + "\n" + post_result);
             }
         } catch (Exception e) {