add restTemplate Report Polaris

pull/304/head
weihu 3 years ago
parent 6c8e657f61
commit 066c7dff84

@ -40,8 +40,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
* *
* @author Haotian Zhang * @author Haotian Zhang
*/ */
@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled", havingValue = "true", @ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled", havingValue = "true", matchIfMissing = true)
matchIfMissing = true)
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.springframework.cloud.openfeign.FeignAutoConfiguration") @ConditionalOnClass(name = "org.springframework.cloud.openfeign.FeignAutoConfiguration")
@AutoConfigureAfter(PolarisContextAutoConfiguration.class) @AutoConfigureAfter(PolarisContextAutoConfiguration.class)

@ -49,7 +49,6 @@ public class PolarisRestTemplateModifier implements ApplicationContextAware, Sma
if (!ObjectUtils.isEmpty(beans)) { if (!ObjectUtils.isEmpty(beans)) {
beans.forEach(this::initRestTemplate); beans.forEach(this::initRestTemplate);
} }
} }
private void initRestTemplate(String beanName, Object bean) { private void initRestTemplate(String beanName, Object bean) {
@ -57,12 +56,10 @@ public class PolarisRestTemplateModifier implements ApplicationContextAware, Sma
RestTemplate restTemplate = (RestTemplate) bean; RestTemplate restTemplate = (RestTemplate) bean;
restTemplate.setErrorHandler(polarisRestTemplateResponseErrorHandler); restTemplate.setErrorHandler(polarisRestTemplateResponseErrorHandler);
} }
} }
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
} }

@ -72,14 +72,14 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
} }
} }
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) { public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ServiceCallResult resultRequest = null; ServiceCallResult resultRequest = null;
try { try {
resultRequest = builderServiceCallResult(url, response); resultRequest = builderServiceCallResult(url, response);
} }
catch (IOException e) { catch (IOException e) {
LOG.error("Will report response of {} url {}", response, url, e); LOG.error("Will report response of {} url {}", response, url, e);
throw new RuntimeException(e); throw e;
} }
finally { finally {
consumerAPI.updateServiceCallResult(resultRequest); consumerAPI.updateServiceCallResult(resultRequest);

@ -50,7 +50,7 @@ public class ServiceAController {
@GetMapping("/getBServiceInfoByRestTemplate") @GetMapping("/getBServiceInfoByRestTemplate")
public String getBServiceInfoByRestTemplate() { public String getBServiceInfoByRestTemplate() {
return restTemplate.getForObject("http://polaris-circuitbreaker-example-b//example/service/b/info", String.class); return restTemplate.getForObject("http://polaris-circuitbreaker-example-b/example/service/b/info", String.class);
} }
/** /**

Loading…
Cancel
Save