kongdeqiang
2023-06-08 3fba1d84220268d871c3c28e0e25f6eab3526f46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.boying.util;
 
import com.boying.common.ReturnData;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
 
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
 
/**
 * @author kdq
 * @version 1.0.0
 * @ClassName HTTPEntityUtil.java
 * @Description TODO
 * @createTime 2022年11月02日 14:49:00
 */
public class HTTPEntityUtil {
    private static Logger logger = Logger.getLogger(HTTPEntityUtil.class.getName());
 
    //map类型使用
    public static HttpEntity setEntity(Map<String, Object> map) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType("application/json; charset=UTF-8"));
        ReturnData returnData = new ReturnData();
        try {
            if (map != null) {
                HttpEntity<Map<String, Object>> httpEntity = new
                        HttpEntity<>(map, headers);
                return httpEntity;
            }
        } catch (Exception e) {
            returnData.setCode(-1);
            returnData.setMsg("系统内部出错!FASP-HESSIAN-1001: 请求 网关出现异常!");
        }
        HttpEntity<String> httpEntity = new HttpEntity<>(headers);
        return httpEntity;
    }
 
    //list类型使用
    public static HttpEntity setEntityForList(List<Map<String, Object>> list){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType("application/json; charset=UTF-8"));
        ReturnData returnData = new ReturnData(); try {
            if (list != null) {
                HttpEntity<List<Map<String, Object>>> httpEntity = new
                        HttpEntity<>(list, headers); return httpEntity;
            }
        }catch (Exception e) {
                returnData.setCode(-1);
                returnData.setMsg("系统内部出错!FASP-HESSIAN-1001: 请求 网关出现异常!");
 
            }
            HttpEntity<String> httpEntity = new HttpEntity<>(headers); return httpEntity;
        }
    }