Commit 7d98d1288db027988790bbeea236d5bc10e542a8

Authored by 王通
1 parent acdf9f10

1.

Too many changes to show.

To preserve performance only 5 of 21 files are displayed.

src/main/java/com/bsth/XDApplication.java
... ... @@ -194,7 +194,7 @@ public class XDApplication implements CommandLineRunner {
194 194 ScheduledExecutorService sexec = Application.mainServices;
195 195 //安全驾驶
196 196 sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 180, 10, TimeUnit.SECONDS);
197   - sexec.scheduleWithFixedDelay(mtPlanDataLoadThread, 180, 10, TimeUnit.SECONDS);
  197 + //sexec.scheduleWithFixedDelay(mtPlanDataLoadThread, 180, 10, TimeUnit.SECONDS);
198 198  
199 199 GpsDataLoaderThread.setFlag(-1);
200 200 /** 线调业务 */
... ...
src/main/java/com/bsth/data/directive/GatewayHttpUtils.java
1   -package com.bsth.data.directive;
2   -
3   -import com.alibaba.fastjson.JSONObject;
4   -import com.bsth.util.ConfigUtil;
5   -import org.apache.http.client.config.RequestConfig;
6   -import org.apache.http.client.methods.CloseableHttpResponse;
7   -import org.apache.http.client.methods.HttpPost;
8   -import org.apache.http.entity.StringEntity;
9   -import org.apache.http.impl.client.CloseableHttpClient;
10   -import org.apache.http.impl.client.HttpClients;
11   -import org.apache.http.util.EntityUtils;
12   -import org.slf4j.Logger;
13   -import org.slf4j.LoggerFactory;
14   -
15   -/**
16   - * @author PanZhao
17   - * @ClassName: GatewayHttpUtils
18   - * @Description: TODO(和网关HTTP通讯工具类)
19   - * @date 2016年8月14日 下午9:50:46
20   - */
21   -public class GatewayHttpUtils {
22   - static Logger logger = LoggerFactory.getLogger(GatewayHttpUtils.class);
23   -
24   - static String url;
25   - static CloseableHttpClient httpClient = null;
26   - static HttpPost post;
27   - static RequestConfig requestConfig;
28   - static CloseableHttpResponse response;
29   -
30   - static {
31   - url = ConfigUtil.get("http.send.directive");
32   - httpClient = HttpClients.createDefault();
33   - post = new HttpPost(url);
34   - requestConfig = RequestConfig.custom()
35   - .setConnectTimeout(3000).setConnectionRequestTimeout(2000)
36   - .setSocketTimeout(3000).build();
37   - post.setConfig(requestConfig);
38   - }
39   -
40   - public static int postJson(String jsonStr) {
41   - logger.info("send : " + jsonStr);
42   -
43   - int code = -1;
44   - try {
45   - post.setEntity(new StringEntity(jsonStr, "utf-8"));
46   -
47   - response = httpClient.execute(post);
48   -
49   - int statusCode = response.getStatusLine().getStatusCode();
50   - if(statusCode != 200){
51   - logger.error("http client status code: " + statusCode);
52   - }
53   -
54   - JSONObject json = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
55   - if (null != json && json.getInteger("errCode") == 0)
56   - code = 0;
57   - else
58   - logger.error("和网关http通讯失败,rs: " + json);
59   -
60   - if (null != response)
61   - response.close();
62   - } catch (Exception e) {
63   - logger.error("", e);
64   - }
65   - return code;
66   - }
67   -}
  1 +package com.bsth.data.directive;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import org.apache.http.client.config.RequestConfig;
  5 +import org.apache.http.client.methods.CloseableHttpResponse;
  6 +import org.apache.http.client.methods.HttpPost;
  7 +import org.apache.http.entity.StringEntity;
  8 +import org.apache.http.impl.client.CloseableHttpClient;
  9 +import org.apache.http.impl.client.HttpClients;
  10 +import org.apache.http.util.EntityUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.InitializingBean;
  14 +import org.springframework.beans.factory.annotation.Value;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +/**
  18 + * @author PanZhao
  19 + * @ClassName: GatewayHttpUtils
  20 + * @Description: TODO(和网关HTTP通讯工具类)
  21 + * @date 2016年8月14日 下午9:50:46
  22 + */
  23 +@Component
  24 +public class GatewayHttpUtils implements InitializingBean {
  25 + static Logger logger = LoggerFactory.getLogger(GatewayHttpUtils.class);
  26 +
  27 + static String url;
  28 + static CloseableHttpClient httpClient = null;
  29 + static HttpPost post;
  30 + static RequestConfig requestConfig;
  31 + static CloseableHttpResponse response;
  32 +
  33 + public static int postJson(String jsonStr) {
  34 + logger.info("send : " + jsonStr);
  35 +
  36 + int code = -1;
  37 + try {
  38 + post.setEntity(new StringEntity(jsonStr, "utf-8"));
  39 +
  40 + response = httpClient.execute(post);
  41 +
  42 + int statusCode = response.getStatusLine().getStatusCode();
  43 + if(statusCode != 200){
  44 + logger.error("http client status code: " + statusCode);
  45 + }
  46 +
  47 + JSONObject json = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
  48 + if (null != json && json.getInteger("errCode") == 0)
  49 + code = 0;
  50 + else
  51 + logger.error("和网关http通讯失败,rs: " + json);
  52 +
  53 + if (null != response)
  54 + response.close();
  55 + } catch (Exception e) {
  56 + logger.error("", e);
  57 + }
  58 + return code;
  59 + }
  60 +
  61 + @Value("${http.send.directive}")
  62 + public void setUrl(String url) {
  63 + GatewayHttpUtils.url = url;
  64 + }
  65 +
  66 + @Override
  67 + public void afterPropertiesSet() throws Exception {
  68 + httpClient = HttpClients.createDefault();
  69 + post = new HttpPost(url);
  70 + requestConfig = RequestConfig.custom()
  71 + .setConnectTimeout(3000).setConnectionRequestTimeout(2000)
  72 + .setSocketTimeout(3000).build();
  73 + post.setConfig(requestConfig);
  74 + }
  75 +}
... ...
src/main/java/com/bsth/data/gpsdata_v2/load/GatewayHttpLoader.java
... ... @@ -5,7 +5,6 @@ import com.bsth.data.BasicData;
5 5 import com.bsth.data.gpsdata_v2.GpsRealData;
6 6 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
7 7 import com.bsth.data.gpsdata_v2.utils.GpsDataUtils;
8   -import com.bsth.util.ConfigUtil;
9 8 import org.apache.commons.lang3.StringUtils;
10 9 import org.apache.http.HttpEntity;
11 10 import org.apache.http.client.config.RequestConfig;
... ...
src/main/java/com/bsth/data/gpsdata_v2/load/SocketClientLoader.java
... ... @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
4 4 import com.bsth.data.BasicData;
5 5 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
6 6 import com.bsth.data.gpsdata_v2.utils.GpsDataUtils;
7   -import com.bsth.util.ConfigUtil;
8 7 import org.apache.http.HttpEntity;
9 8 import org.apache.http.client.config.RequestConfig;
10 9 import org.apache.http.client.methods.CloseableHttpResponse;
... ...
src/main/java/com/bsth/data/gpsdata_v2/rfid/RfidHttpLoader.java
1 1 package com.bsth.data.gpsdata_v2.rfid;
2 2  
3 3 import com.bsth.data.gpsdata_v2.rfid.entity.RfidInfo;
4   -import com.bsth.util.ConfigUtil;
5 4 import com.fasterxml.jackson.databind.ObjectMapper;
6 5 import org.apache.commons.io.IOUtils;
7 6 import org.slf4j.Logger;
8 7 import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Value;
  9 +import org.springframework.stereotype.Component;
9 10  
10 11 import java.io.ByteArrayOutputStream;
11 12 import java.io.IOException;
... ... @@ -20,11 +21,12 @@ import java.util.List;
20 21 * @author hill
21 22 * @date
22 23 */
  24 +@Component
23 25 public class RfidHttpLoader {
24 26  
25 27 private final static Logger log = LoggerFactory.getLogger(RfidHttpLoader.class);
26 28  
27   - private static String RFID_URL = ConfigUtil.get("http.rfid.url");
  29 + private static String RFID_URL;
28 30  
29 31 public static List<RfidInfo> load() {
30 32 List<RfidInfo> result = new ArrayList<>();
... ... @@ -75,4 +77,9 @@ public class RfidHttpLoader {
75 77  
76 78 return result;
77 79 }
  80 +
  81 + @Value("${http.rfid.url}")
  82 + public void setRfidUrl(String rfidUrl) {
  83 + RFID_URL = rfidUrl;
  84 + }
78 85 }
... ...