liujie
2023-10-15 1707d15796d7dc78812f19b9c34868c8cb38a714
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.stylefeng.guns.modular.system.utils.PortUtil;
 
import cn.hutool.http.HttpRequest;
import com.intuit.ipp.exception.ServiceException;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
 
public class FMSStrategy implements WharfStrategy {
 
 
 
    @Override
    public TerminaleDataWarpper executeLogic(String... params) {
        String enums = "";
        if (params.length == 0) {
            throw new GunsException(BizExceptionEnum.REQUEST_EMPTY_ERROR);
        } else {
            enums = params[0];
        }
        HttpRequest httpRequest = HttpRequest.get("http://n4.fenixmarineservices.com:9081/apex/api/codeextension?extensionname=FenixCheckCtrAvailability&operatorId=FMS&complexId=USSPQ&facilityId=FMS&yardId=FMS&PARM_filterName=UNIT_FINDER_QUERY&PARM_CTRNBR=" + enums);
 
        System.out.println(httpRequest);
 
        return null;
    }
 
 
    public static void main(String[] args) throws ServiceException {
        String post = post("http://n4.fenixmarineservices.com:9081/apex/api/codeextension?extensionname=FenixCheckCtrAvailability&operatorId=FMS&complexId=USSPQ&facilityId=FMS&yardId=FMS&PARM_filterName=UNIT_FINDER_QUERY&PARM_CTRNBR=" + "TGHU9229633", "");
        System.out.println(post);
 
 
    }
 
    public static String post(String strURL, String params) throws ServiceException {
        System.out.println(strURL);
        System.out.println(params);
        String result = "";
        BufferedReader reader = null;
        try {
            URL url = new URL(strURL);// 创建连接
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestMethod("GET"); // 设置请求方式
            connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式
            connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式
            connection.connect();
            if (connection.getResponseCode() == 200) {
                reader = new BufferedReader(
                        new InputStreamReader(connection.getInputStream()));
                result = reader.readLine();
            } else {
                throw new ServiceException(connection.getResponseMessage());
            }
        } catch (Exception e) {
            throw new ServiceException("http的post请求异常!" + e.getMessage());
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}