format code

pull/300/head
weihu 3 years ago
parent 97cfb49e8f
commit f91a043a4b

@ -25,5 +25,5 @@ import org.springframework.web.client.ResponseErrorHandler;
* @description: errorHandler {@link ResponseErrorHandler}
*/
public interface PolarisResponseErrorHandler extends ResponseErrorHandler {
}

@ -19,6 +19,7 @@ package com.tencent.cloud.polaris.circuitbreaker;
import com.tencent.cloud.polaris.context.PolarisContextAutoConfiguration;
import com.tencent.polaris.api.core.ConsumerAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;

@ -17,6 +17,8 @@
package com.tencent.cloud.polaris.circuitbreaker;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
@ -25,8 +27,6 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
/**
* @author : wh
* @date : 2022/6/21 21:20
@ -57,7 +57,7 @@ public class PolarisRestTemplateRegisterAutoConfiguration implements Application
RestTemplate restTemplate = (RestTemplate) bean;
restTemplate.setErrorHandler(polarisRestTemplateResponseErrorHandler);
}
}
@Override

@ -17,6 +17,12 @@
package com.tencent.cloud.polaris.circuitbreaker;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.Objects;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.util.ReflectionUtils;
import com.tencent.polaris.api.core.ConsumerAPI;
@ -26,16 +32,11 @@ import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.api.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.Objects;
/**
* @author : wh
* @date : 2022/6/21 17:25
@ -63,7 +64,7 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
}
@Override
public void handleError(ClientHttpResponse response) throws IOException{
public void handleError(ClientHttpResponse response) throws IOException {
if (Objects.nonNull(polarisResponseErrorHandler)) {
if (polarisResponseErrorHandler.hasError(response)) {
polarisResponseErrorHandler.handleError(response);
@ -75,10 +76,12 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
ServiceCallResult resultRequest = null;
try {
resultRequest = builderServiceCallResult(url, response);
} catch (IOException e) {
}
catch (IOException e) {
LOG.error("Will report response of {} url {}", response, url, e);
throw new RuntimeException(e);
} finally {
}
finally {
consumerAPI.updateServiceCallResult(resultRequest);
}
}

@ -23,18 +23,19 @@ package com.tencent.cloud.polaris.circuitbreaker;
* @description:
*/
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import com.tencent.polaris.api.core.ConsumerAPI;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit4.SpringRunner;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -47,9 +48,9 @@ import static org.mockito.Mockito.when;
@SpringBootTest(classes = PolarisRestTemplateResponseErrorHandlerTest.TestApplication.class,
properties = {"spring.cloud.polaris.namespace=Test", "spring.cloud.polaris.service=TestApp"})
public class PolarisRestTemplateResponseErrorHandlerTest {
@Test
public void handleError() throws Exception{
public void handleError() throws Exception {
ConsumerAPI consumerAPI = mock(ConsumerAPI.class);
PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler = new PolarisRestTemplateResponseErrorHandler(consumerAPI, null);
URI uri = mock(URI.class);

@ -50,7 +50,7 @@ public class ServiceAController {
@GetMapping("/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