Commit 2523093f07cb50dbab756f4fd117448118b4fa72

Authored by 王通
1 parent ea83817a

1.应急预案url、协议变更,代码变更

src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
1 package com.bsth.controller.realcontrol; 1 package com.bsth.controller.realcontrol;
2 2
3 -import java.io.ByteArrayOutputStream;  
4 -import java.io.IOException;  
5 -import java.io.InputStream;  
6 -import java.io.OutputStream; 3 +import java.io.*;
7 import java.net.HttpURLConnection; 4 import java.net.HttpURLConnection;
8 import java.net.MalformedURLException; 5 import java.net.MalformedURLException;
9 import java.net.URL; 6 import java.net.URL;
@@ -15,17 +12,28 @@ import java.sql.ResultSet; @@ -15,17 +12,28 @@ import java.sql.ResultSet;
15 import java.util.*; 12 import java.util.*;
16 13
17 import com.bsth.data.forecast.entity.ArrivalEntity; 14 import com.bsth.data.forecast.entity.ArrivalEntity;
  15 +import com.bsth.data.maintenance_plan.MaintenancePlan;
  16 +import com.bsth.data.maintenance_plan.MtPlanCenter;
18 import com.bsth.entity.sys.SysUser; 17 import com.bsth.entity.sys.SysUser;
19 import com.bsth.security.util.SecurityUtils; 18 import com.bsth.security.util.SecurityUtils;
  19 +import com.bsth.util.HttpClientUtils;
20 import com.bsth.util.ReportUtils; 20 import com.bsth.util.ReportUtils;
21 import com.bsth.util.db.DBUtils_MS; 21 import com.bsth.util.db.DBUtils_MS;
22 import com.bsth.util.db.DBUtils_control; 22 import com.bsth.util.db.DBUtils_control;
23 import com.fasterxml.jackson.databind.ObjectMapper; 23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import org.apache.commons.io.IOUtils; 24 import org.apache.commons.io.IOUtils;
25 import org.apache.commons.lang3.StringEscapeUtils; 25 import org.apache.commons.lang3.StringEscapeUtils;
  26 +import org.apache.http.HttpEntity;
  27 +import org.apache.http.HttpResponse;
  28 +import org.apache.http.client.config.RequestConfig;
  29 +import org.apache.http.client.methods.CloseableHttpResponse;
  30 +import org.apache.http.client.methods.HttpGet;
  31 +import org.apache.http.impl.client.CloseableHttpClient;
26 import org.joda.time.DateTime; 32 import org.joda.time.DateTime;
27 import org.joda.time.format.DateTimeFormat; 33 import org.joda.time.format.DateTimeFormat;
28 import org.joda.time.format.DateTimeFormatter; 34 import org.joda.time.format.DateTimeFormatter;
  35 +import org.slf4j.Logger;
  36 +import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired; 37 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.beans.factory.annotation.Value; 38 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.web.bind.annotation.*; 39 import org.springframework.web.bind.annotation.*;
@@ -47,6 +55,8 @@ import com.bsth.service.realcontrol.ScheduleRealInfoService; @@ -47,6 +55,8 @@ import com.bsth.service.realcontrol.ScheduleRealInfoService;
47 @RequestMapping("/realSchedule") 55 @RequestMapping("/realSchedule")
48 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> { 56 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> {
49 57
  58 + private final static Logger log = LoggerFactory.getLogger(ScheduleRealInfoController.class);
  59 +
50 @Autowired 60 @Autowired
51 ScheduleRealInfoService scheduleRealInfoService; 61 ScheduleRealInfoService scheduleRealInfoService;
52 62
@@ -828,26 +838,30 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -828,26 +838,30 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
828 @RequestMapping(value = "ackCp", method = RequestMethod.POST) 838 @RequestMapping(value = "ackCp", method = RequestMethod.POST)
829 public Map<String, Object> ackCp(@RequestParam Map<String, Object> param){ 839 public Map<String, Object> ackCp(@RequestParam Map<String, Object> param){
830 Map<String, Object> res = new HashMap<>(); 840 Map<String, Object> res = new HashMap<>();
831 - InputStream in = null;  
832 - SysUser user = SecurityUtils.getCurrentUser();  
833 - DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); 841 + BufferedReader br = null;
834 StringBuilder url = new StringBuilder(cpUrl); 842 StringBuilder url = new StringBuilder(cpUrl);
835 - HttpURLConnection con = null;  
836 try { 843 try {
837 - con = (HttpURLConnection)new URL(url.append(param.get("id")).toString()).openConnection();  
838 - con.setDoInput(true);  
839 - con.setRequestMethod("GET");  
840 - con.setConnectTimeout(5000);  
841 - con.setReadTimeout(5000);  
842 - con.setRequestProperty("keep-alive", "true");  
843 - con.setRequestProperty("accept", "*/*");  
844 -  
845 - if (con.getResponseCode() == 200) {  
846 - in = con.getInputStream();  
847 - ByteArrayOutputStream bout = new ByteArrayOutputStream();  
848 - IOUtils.copy(in, bout);  
849 - Map<String, Object> map = new ObjectMapper().readValue(bout.toByteArray(), Map.class);  
850 - System.out.println(map); 844 + url.append(param.get("id"));
  845 + CloseableHttpClient httpClient = HttpClientUtils.defaultHttpClient(url.toString());
  846 + HttpGet get = new HttpGet(url.toString());
  847 + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5500).setConnectionRequestTimeout(5000).setSocketTimeout(5500).build();
  848 + get.setConfig(requestConfig);
  849 + CloseableHttpResponse response = httpClient.execute(get);
  850 +
  851 + int statusCode = response.getStatusLine().getStatusCode();
  852 + if(statusCode != 200){
  853 + log.error("http client status code: " + statusCode);
  854 + }
  855 + HttpEntity entity = response.getEntity();
  856 + if (null != entity) {
  857 + br = new BufferedReader(new InputStreamReader(entity.getContent()));
  858 + StringBuffer stringBuffer = new StringBuffer();
  859 + String str = "";
  860 + while ((str = br.readLine()) != null) {
  861 + stringBuffer.append(str);
  862 + }
  863 + br.close();
  864 + log.info(stringBuffer.toString());
851 } 865 }
852 } catch (MalformedURLException e) { 866 } catch (MalformedURLException e) {
853 // TODO Auto-generated catch block 867 // TODO Auto-generated catch block
@@ -855,10 +869,6 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -855,10 +869,6 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
855 } catch (IOException e) { 869 } catch (IOException e) {
856 // TODO Auto-generated catch block 870 // TODO Auto-generated catch block
857 e.printStackTrace(); 871 e.printStackTrace();
858 - } finally {  
859 - if (con != null) {  
860 - con.disconnect();  
861 - }  
862 } 872 }
863 873
864 return res; 874 return res;
src/main/java/com/bsth/util/HttpClientUtils.java
1 -package com.bsth.util;  
2 -  
3 -import org.apache.http.HttpEntity;  
4 -import org.apache.http.client.config.RequestConfig;  
5 -import org.apache.http.client.entity.EntityBuilder;  
6 -import org.apache.http.client.methods.CloseableHttpResponse;  
7 -import org.apache.http.client.methods.HttpGet;  
8 -import org.apache.http.client.methods.HttpPost;  
9 -import org.apache.http.entity.StringEntity;  
10 -import org.apache.http.impl.client.CloseableHttpClient;  
11 -import org.apache.http.impl.client.HttpClients;  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -  
15 -import java.io.BufferedReader;  
16 -import java.io.IOException;  
17 -import java.io.InputStreamReader;  
18 -  
19 -/**  
20 - * Created by panzhao on 2017/8/2.  
21 - */  
22 -public class HttpClientUtils {  
23 -  
24 - static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class);  
25 - public static StringBuilder get(String url) throws Exception {  
26 -  
27 - CloseableHttpClient httpClient = null;  
28 - CloseableHttpResponse response = null;  
29 - StringBuilder stringBuffer = null;  
30 - try {  
31 - httpClient = HttpClients.createDefault();  
32 - HttpGet get = new HttpGet(url);  
33 - //超时时间  
34 - RequestConfig requestConfig = RequestConfig.custom()  
35 - .setConnectTimeout(10500).setConnectionRequestTimeout(7000)  
36 - .setSocketTimeout(10500).build();  
37 - get.setConfig(requestConfig);  
38 - get.addHeader("Content-Encoding", "gzip");  
39 - response = httpClient.execute(get);  
40 - stringBuffer = getResult(response.getEntity());  
41 - } catch (Exception e) {  
42 - logger.error("", e);  
43 - } finally {  
44 - if (null != httpClient)  
45 - httpClient.close();  
46 - if (null != response)  
47 - response.close();  
48 - }  
49 - return stringBuffer;  
50 - }  
51 -  
52 - /**  
53 - * raw post data  
54 - * @param url  
55 - * @param data  
56 - * @return  
57 - */  
58 - public static StringBuilder post(String url, String data) throws Exception {  
59 - CloseableHttpClient httpClient = null;  
60 - CloseableHttpResponse response = null;  
61 - StringBuilder stringBuffer = null;  
62 - try {  
63 - httpClient = HttpClients.createDefault();  
64 - HttpPost post = new HttpPost(url);  
65 -  
66 - post.setHeader("Accept", "application/json");  
67 - post.setHeader("Content-Type", "application/json;charset=UTF-8");  
68 - //超时时间  
69 - RequestConfig requestConfig = RequestConfig.custom()  
70 - .setConnectTimeout(2500).setConnectionRequestTimeout(2000)  
71 - .setSocketTimeout(3500).build();  
72 - post.setConfig(requestConfig);  
73 - post.setEntity((new StringEntity(data, "UTF-8")));  
74 -  
75 - response = httpClient.execute(post);  
76 - stringBuffer = getResult(response.getEntity());  
77 - } catch (Exception e) {  
78 - logger.error("", e);  
79 - } finally {  
80 - if (null != httpClient)  
81 - httpClient.close();  
82 - if (null != response)  
83 - response.close();  
84 - }  
85 - return stringBuffer;  
86 - }  
87 -  
88 - private static StringBuilder getResult(HttpEntity entity) throws IOException {  
89 - StringBuilder stringBuffer = null;  
90 - if (null != entity) {  
91 - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
92 - stringBuffer = new StringBuilder();  
93 - String str = "";  
94 - while ((str = br.readLine()) != null)  
95 - stringBuffer.append(str);  
96 - }  
97 - return stringBuffer;  
98 - }  
99 -} 1 +package com.bsth.util;
  2 +
  3 +import org.apache.http.HttpEntity;
  4 +import org.apache.http.client.config.RequestConfig;
  5 +import org.apache.http.client.entity.EntityBuilder;
  6 +import org.apache.http.client.methods.CloseableHttpResponse;
  7 +import org.apache.http.client.methods.HttpGet;
  8 +import org.apache.http.client.methods.HttpPost;
  9 +import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
  10 +import org.apache.http.entity.StringEntity;
  11 +import org.apache.http.impl.client.CloseableHttpClient;
  12 +import org.apache.http.impl.client.HttpClients;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +
  16 +import javax.net.ssl.*;
  17 +import java.io.BufferedReader;
  18 +import java.io.IOException;
  19 +import java.io.InputStreamReader;
  20 +import java.security.cert.CertificateException;
  21 +import java.security.cert.X509Certificate;
  22 +
  23 +/**
  24 + * Created by panzhao on 2017/8/2.
  25 + */
  26 +public class HttpClientUtils {
  27 +
  28 + static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class);
  29 +
  30 + private final static String HTTPS = "https://";
  31 +
  32 + private static SSLConnectionSocketFactory sslConnectionSocketFactory;
  33 +
  34 + static {
  35 + try {
  36 + SSLContext sslCtx = SSLContext.getInstance("TLSv1.2");
  37 + sslCtx.init(null, new TrustManager[] {
  38 + new X509TrustManager() {
  39 + @Override
  40 + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
  41 + }
  42 +
  43 + @Override
  44 + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
  45 + }
  46 +
  47 + @Override
  48 + public X509Certificate[] getAcceptedIssuers() {
  49 + return null;
  50 + }
  51 + }
  52 + }, null);
  53 + sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslCtx, new HostnameVerifier() {
  54 +
  55 + @Override
  56 + public boolean verify(String hostname, SSLSession session) {
  57 + // TODO Auto-generated method stub
  58 + return true;
  59 + }
  60 + });
  61 + } catch (Exception e) {
  62 + logger.error("SSL context set fail: {}", e);
  63 + }
  64 + }
  65 +
  66 + public static CloseableHttpClient defaultHttpClient(String url) {
  67 + if (url.startsWith(HTTPS)) {
  68 + return HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build();
  69 + }
  70 + return HttpClients.createDefault();
  71 + }
  72 +
  73 + public static StringBuilder get(String url) throws Exception {
  74 +
  75 + CloseableHttpClient httpClient = null;
  76 + CloseableHttpResponse response = null;
  77 + StringBuilder stringBuffer = null;
  78 + try {
  79 + httpClient = HttpClients.createDefault();
  80 + HttpGet get = new HttpGet(url);
  81 + //超时时间
  82 + RequestConfig requestConfig = RequestConfig.custom()
  83 + .setConnectTimeout(10500).setConnectionRequestTimeout(7000)
  84 + .setSocketTimeout(10500).build();
  85 + get.setConfig(requestConfig);
  86 + get.addHeader("Content-Encoding", "gzip");
  87 + response = httpClient.execute(get);
  88 + stringBuffer = getResult(response.getEntity());
  89 + } catch (Exception e) {
  90 + logger.error("", e);
  91 + } finally {
  92 + if (null != httpClient)
  93 + httpClient.close();
  94 + if (null != response)
  95 + response.close();
  96 + }
  97 + return stringBuffer;
  98 + }
  99 +
  100 + /**
  101 + * raw post data
  102 + * @param url
  103 + * @param data
  104 + * @return
  105 + */
  106 + public static StringBuilder post(String url, String data) throws Exception {
  107 + CloseableHttpClient httpClient = null;
  108 + CloseableHttpResponse response = null;
  109 + StringBuilder stringBuffer = null;
  110 + try {
  111 + httpClient = HttpClients.createDefault();
  112 + HttpPost post = new HttpPost(url);
  113 +
  114 + post.setHeader("Accept", "application/json");
  115 + post.setHeader("Content-Type", "application/json;charset=UTF-8");
  116 + //超时时间
  117 + RequestConfig requestConfig = RequestConfig.custom()
  118 + .setConnectTimeout(2500).setConnectionRequestTimeout(2000)
  119 + .setSocketTimeout(3500).build();
  120 + post.setConfig(requestConfig);
  121 + post.setEntity((new StringEntity(data, "UTF-8")));
  122 +
  123 + response = httpClient.execute(post);
  124 + stringBuffer = getResult(response.getEntity());
  125 + } catch (Exception e) {
  126 + logger.error("", e);
  127 + } finally {
  128 + if (null != httpClient)
  129 + httpClient.close();
  130 + if (null != response)
  131 + response.close();
  132 + }
  133 + return stringBuffer;
  134 + }
  135 +
  136 + private static StringBuilder getResult(HttpEntity entity) throws IOException {
  137 + StringBuilder stringBuffer = null;
  138 + if (null != entity) {
  139 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  140 + stringBuffer = new StringBuilder();
  141 + String str = "";
  142 + while ((str = br.readLine()) != null)
  143 + stringBuffer.append(str);
  144 + }
  145 + return stringBuffer;
  146 + }
  147 +}
src/main/resources/application-cloud.properties
@@ -13,7 +13,7 @@ spring.jpa.show-sql= false @@ -13,7 +13,7 @@ spring.jpa.show-sql= false
13 13
14 #DATABASE 14 #DATABASE
15 spring.datasource.driver-class-name= com.mysql.jdbc.Driver 15 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
16 -spring.datasource.url= jdbc:mysql://192.170.100.132/control?useUnicode=true&characterEncoding=utf-8&useSSL=false 16 +spring.datasource.url= jdbc:mysql://192.170.100.132/pd_control?useUnicode=true&characterEncoding=utf-8&useSSL=false
17 spring.datasource.username= root 17 spring.datasource.username= root
18 spring.datasource.password= root2jsp 18 spring.datasource.password= root2jsp
19 spring.datasource.type= com.zaxxer.hikari.HikariDataSource 19 spring.datasource.type= com.zaxxer.hikari.HikariDataSource
@@ -51,7 +51,7 @@ ms.fl.generate=true @@ -51,7 +51,7 @@ ms.fl.generate=true
51 ## dsm ack interface 51 ## dsm ack interface
52 dsm.ack.url= http://211.95.61.66:9008/modules/dsmCheckTheRecord/addDsm? 52 dsm.ack.url= http://211.95.61.66:9008/modules/dsmCheckTheRecord/addDsm?
53 ## cp ack interface 53 ## cp ack interface
54 -cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/ 54 +cp.ack.url= https://58.247.254.118:4003/prod-api/serverApi/instructionsIssue/confirm/
55 ## admin mail 55 ## admin mail
56 admin.mail= 3090342880@qq.com 56 admin.mail= 3090342880@qq.com
57 ## enabled 57 ## enabled
src/main/resources/application.properties
1 -spring.profiles.active = dev 1 +spring.profiles.active = cloud
2 2
3 spring.view.suffix=.html 3 spring.view.suffix=.html
4 server.session-timeout=-1 4 server.session-timeout=-1