1515import org .apache .http .client .methods .HttpGet ;
1616import org .apache .http .impl .client .HttpClientBuilder ;
1717import org .apache .http .util .EntityUtils ;
18+ import org .slf4j .Logger ;
19+ import org .slf4j .LoggerFactory ;
1820import org .springframework .beans .factory .annotation .Autowired ;
19- import org .springframework .beans .factory .annotation .Qualifier ;
2021import org .springframework .beans .factory .annotation .Value ;
2122import org .springframework .cloud .commons .util .InetUtils ;
2223import org .springframework .http .HttpStatus ;
3435@ Api (value = "/" , tags = {"入口应用" })
3536@ RestController
3637class AController {
37- private static final org . slf4j . Logger log = org . slf4j . LoggerFactory .getLogger (AController .class );
38+ private static final Logger log = LoggerFactory .getLogger (AController .class );
3839
3940 @ Autowired
40- @ Qualifier ("loadBalancedRestTemplate" )
41- private RestTemplate loadBalancedRestTemplate ;
41+ private RestTemplate restTemplate ;
4242
4343 @ Autowired
4444 private FeignClientTest feignClient ;
4545
46- @ Autowired
47- @ Qualifier ("restTemplate" )
48- private RestTemplate restTemplate ;
49-
5046 @ Autowired
5147 InetUtils inetUtils ;
5248
@@ -104,7 +100,7 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
104100 }
105101 }
106102 //这是rpc调用的方式
107- String result = loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
103+ String result = restTemplate .getForObject ("http://sc-B/b" , String .class );
108104
109105 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
110106 "[config=" + configValue + "]" + " -> " + result ;
@@ -125,9 +121,9 @@ public String a2bc(HttpServletRequest request) throws ExecutionException, Interr
125121 }
126122
127123 String resultB = "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
128- "[config=" + configValue + "]" + " -> " + loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
124+ "[config=" + configValue + "]" + " -> " + restTemplate .getForObject ("http://sc-B/b" , String .class );
129125 String resultA = "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
130- "[config=" + configValue + "]" + " -> " + loadBalancedRestTemplate .getForObject ("http://sc-C/c" , String .class );
126+ "[config=" + configValue + "]" + " -> " + restTemplate .getForObject ("http://sc-C/c" , String .class );
131127
132128 return resultA + "\n " + resultB ;
133129 }
@@ -156,7 +152,7 @@ public String aByFeign(HttpServletRequest request) throws ExecutionException, In
156152 @ GetMapping ("/flow" )
157153 public String flow (HttpServletRequest request ) throws ExecutionException , InterruptedException {
158154
159- ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/flow" , String .class );
155+ ResponseEntity <String > responseEntity = restTemplate .getForEntity ("http://sc-B/flow" , String .class );
160156 HttpStatus status = responseEntity .getStatusCode ();
161157 String result = responseEntity .getBody () + " code:" + status .value ();
162158
@@ -168,7 +164,7 @@ public String flow(HttpServletRequest request) throws ExecutionException, Interr
168164 @ ApiOperation (value = "测试热点规则" , tags = {"流量防护" })
169165 @ GetMapping ("/params/{hot}" )
170166 public String params (HttpServletRequest request ,@ PathVariable ("hot" ) String hot ) throws ExecutionException , InterruptedException {
171- ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/params/" + hot , String .class );
167+ ResponseEntity <String > responseEntity = restTemplate .getForEntity ("http://sc-B/params/" + hot , String .class );
172168
173169 HttpStatus status = responseEntity .getStatusCode ();
174170 String result = responseEntity .getBody () + " code:" + status .value ();
@@ -180,7 +176,7 @@ public String params(HttpServletRequest request,@PathVariable("hot") String hot)
180176 @ ApiOperation (value = "测试隔离规则" , tags = { "流量防护" })
181177 @ GetMapping ("/isolate" )
182178 public String isolate (HttpServletRequest request ) throws ExecutionException , InterruptedException {
183- ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/isolate" , String .class );
179+ ResponseEntity <String > responseEntity = restTemplate .getForEntity ("http://sc-B/isolate" , String .class );
184180
185181 HttpStatus status = responseEntity .getStatusCode ();
186182 String result = responseEntity .getBody () + " code:" + status .value ();
@@ -189,20 +185,11 @@ public String isolate(HttpServletRequest request) throws ExecutionException, Int
189185 "[config=" + configValue + "]" + " -> " + result ;
190186 }
191187
192-
193- @ GetMapping ("/spring_boot" )
194- public String spring_boot (HttpServletRequest request ) {
195- String result = restTemplate .getForObject ("http://sc-b:20002/spring_boot" , String .class );
196-
197- return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
198- " -> " + result ;
199- }
200-
201188 @ GetMapping ("/sql" )
202189 public String sql (HttpServletRequest request ) {
203190
204191 String url = "http://sc-B/sql?" + request .getQueryString ();
205- String result = loadBalancedRestTemplate .getForObject (url , String .class );
192+ String result = restTemplate .getForObject (url , String .class );
206193 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
207194 "[config=" + configValue + "]" + " -> " + result ;
208195 }
@@ -221,7 +208,7 @@ public String aZone(HttpServletRequest request) {
221208 }
222209 }
223210 return "A" + serviceTag + "[" + currentZone + "]" + " -> " +
224- loadBalancedRestTemplate .getForObject ("http://sc-B/b-zone" , String .class );
211+ restTemplate .getForObject ("http://sc-B/b-zone" , String .class );
225212 }
226213
227214 @ ApiOperation (value = "Dubbo 全链路灰度入口" , tags = {"入口应用" })
0 commit comments