Commit f28a66c9b92f00b747fe12d0bf9dc0da37c5dfa4

Authored by 王通
1 parent 984f37d3

1.加入白名单机制,避免非调度系统消费GPS情况

src/main/java/com/bsth/controller/GpsRealDataController.java
1   -package com.bsth.controller;
2   -
3   -import com.bsth.client.GpsBeforeBuffer;
4   -import com.bsth.entity.GpsEntity;
5   -import org.springframework.web.bind.annotation.RequestMapping;
6   -import org.springframework.web.bind.annotation.RestController;
7   -
8   -import java.util.List;
9   -
10   -/**
11   - * Created by panzhao on 2017/5/12.
12   - */
13   -@RestController
14   -@RequestMapping("realGps")
15   -public class GpsRealDataController {
16   -
17   -
18   - @RequestMapping("/all")
19   - public List<GpsEntity> all(){
20   - return GpsBeforeBuffer.pollAll();
21   - }
22   -}
  1 +package com.bsth.controller;
  2 +
  3 +import com.bsth.client.GpsBeforeBuffer;
  4 +import com.bsth.entity.GpsEntity;
  5 +import com.bsth.util.ConfigUtil;
  6 +
  7 +import org.apache.commons.lang3.StringUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RestController;
  12 +
  13 +import java.util.ArrayList;
  14 +import java.util.Arrays;
  15 +import java.util.List;
  16 +
  17 +import javax.servlet.http.HttpServletRequest;
  18 +
  19 +/**
  20 + * Created by panzhao on 2017/5/12.
  21 + */
  22 +@RestController
  23 +@RequestMapping("realGps")
  24 +public class GpsRealDataController {
  25 +
  26 + private static List<String> access = new ArrayList<>();
  27 +
  28 + static {
  29 + String accessWhite = ConfigUtil.get("access.white");
  30 + if (StringUtils.isNotBlank(accessWhite)) {
  31 + access = Arrays.asList(accessWhite.split(","));
  32 + }
  33 + }
  34 +
  35 + static Logger log = LoggerFactory.getLogger(GpsRealDataController.class);
  36 + @RequestMapping("/all")
  37 + public List<GpsEntity> all(HttpServletRequest request){
  38 + if (access.contains(request.getRemoteHost())) {
  39 + return GpsBeforeBuffer.pollAll();
  40 + } else {
  41 + return new ArrayList<>();
  42 + }
  43 + }
  44 +}
... ...