Skip to content

Commit 7511fed

Browse files
committed
add 1.4.13.dev
1. add rest header
1 parent 51f1926 commit 7511fed

File tree

7 files changed

+50
-32
lines changed

7 files changed

+50
-32
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>1.4.12</version>
15+
<version>1.4.13.dev</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>1.4.12</version>
8+
<version>1.4.13.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-id-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>1.4.12</version>
8+
<version>1.4.13.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-security-jwt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>1.4.12</version>
9+
<version>1.4.13.dev</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security-jwt</artifactId>

springboot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>1.4.12</version>
8+
<version>1.4.13.dev</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

springboot-starter/src/main/java/com/codingapi/springboot/framework/rest/HttpClient.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@
1414
import java.net.URI;
1515

1616
@Slf4j
17-
class HttpClient {
17+
public class HttpClient {
1818

1919
private final RestTemplate restTemplate;
2020

2121
private final String baseUrl;
2222

23+
public HttpClient(String baseUrl) {
24+
this(null,baseUrl);
25+
}
26+
2327
public HttpClient(RestApiProperties properties, String baseUrl) {
2428
this.baseUrl = baseUrl;
2529
this.restTemplate = RestTemplateContext.getInstance().getRestTemplate();
2630
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
2731
requestFactory.setConnectTimeout(3000);
28-
if(properties!=null) {
32+
if (properties != null) {
2933
if (properties.isEnableProxy()) {
3034
log.info("enable proxy {}//:{}:{}", properties.getProxyType(), properties.getProxyHost(), properties.getProxyPort());
3135
requestFactory.setProxy(new Proxy(properties.getProxyType(),
@@ -37,30 +41,35 @@ public HttpClient(RestApiProperties properties, String baseUrl) {
3741

3842

3943
private String buildUrl(String api) {
40-
return baseUrl+api;
44+
return baseUrl + api;
4145
}
4246

4347
public String post(String api, JSON jsonObject) {
44-
HttpHeaders headers = new HttpHeaders();
48+
return post(api, new HttpHeaders(), jsonObject);
49+
}
50+
51+
public String post(String api, HttpHeaders headers, JSON jsonObject) {
4552
headers.setContentType(MediaType.APPLICATION_JSON);
4653
String url = buildUrl(api);
4754
HttpEntity<String> httpEntity = new HttpEntity<>(jsonObject.toString(), headers);
4855
ResponseEntity<String> httpResponse = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
4956
return httpResponse.getBody();
5057
}
5158

52-
53-
public String get(String api, MultiValueMap<String, String> uriVariables) {
54-
HttpHeaders headers = new HttpHeaders();
59+
public String get(String api, HttpHeaders headers, MultiValueMap<String, String> uriVariables) {
5560
headers.setContentType(MediaType.APPLICATION_JSON);
5661
String url = buildUrl(api);
5762
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(url);
58-
if(uriVariables!=null){
63+
if (uriVariables != null) {
5964
uriComponentsBuilder = uriComponentsBuilder.queryParams(uriVariables);
6065
}
6166
URI uri = uriComponentsBuilder.build().toUri();
6267
HttpEntity<String> httpEntity = new HttpEntity<>(headers);
6368
ResponseEntity<String> httpResponse = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class);
6469
return httpResponse.getBody();
6570
}
71+
72+
public String get(String api, MultiValueMap<String, String> uriVariables) {
73+
return get(api, new HttpHeaders(), uriVariables);
74+
}
6675
}

springboot-starter/src/main/java/com/codingapi/springboot/framework/rest/RestClient.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codingapi.springboot.framework.rest.param.ApiPostParamBuilder;
66
import com.codingapi.springboot.framework.rest.properties.RestApiProperties;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.http.HttpHeaders;
89

910
@Slf4j
1011
public class RestClient {
@@ -24,52 +25,56 @@ public RestClient(String baseUrl) {
2425
}
2526

2627
private String _get(String api, ApiGetParamBuilder paramBuilder) {
27-
return httpClient.get(api, paramBuilder!=null?paramBuilder.build():null);
28+
return _get(api,new HttpHeaders(),paramBuilder);
2829
}
2930

30-
public String get(String api, ApiGetParamBuilder paramBuilder) {
31+
private String _get(String api,HttpHeaders headers, ApiGetParamBuilder paramBuilder) {
32+
return httpClient.get(api, headers,paramBuilder!=null?paramBuilder.build():null);
33+
}
34+
35+
public String get(String api,HttpHeaders headers, ApiGetParamBuilder paramBuilder) {
3136
for(int i=0; i< RETRY_COUNT; i++){
3237
try {
33-
return _get(api, paramBuilder);
38+
return _get(api,headers, paramBuilder);
3439
}catch (Exception e){
3540
log.warn("api:{},error:{}",api,e.getMessage());
3641
sleep();
3742
}
3843
}
3944
return EMPTY;
4045
}
46+
public String get(String api, ApiGetParamBuilder paramBuilder) {
47+
return get(api,new HttpHeaders(),paramBuilder);
48+
}
4149

4250
public String get(String api) {
43-
return get(api,null);
51+
return get(api,new HttpHeaders(),null);
4452
}
4553

46-
private String _post(String api, ApiPostParamBuilder paramBuilder) {
47-
return _post(api, paramBuilder.build());
54+
public String get(String api,HttpHeaders headers) {
55+
return get(api,headers,null);
4856
}
4957

50-
5158
private String _post(String api, JSONObject requestBody) {
52-
return httpClient.post(api, requestBody);
59+
return _post(api,new HttpHeaders(),requestBody);
5360
}
5461

62+
private String _post(String api, HttpHeaders headers, JSONObject requestBody) {
63+
return httpClient.post(api,headers, requestBody);
64+
}
5565

5666
public String post(String api, JSONObject requestBody) {
57-
for (int i=0;i< RETRY_COUNT;i++){
58-
try {
59-
return _post(api, requestBody);
60-
}catch (Exception e){
61-
log.warn("api:{},error:{}",api,e.getMessage());
62-
sleep();
63-
}
64-
}
65-
return EMPTY;
67+
return post(api,new HttpHeaders(),requestBody);
6668
}
6769

68-
6970
public String post(String api, ApiPostParamBuilder paramBuilder) {
71+
return post(api,new HttpHeaders(),paramBuilder.build());
72+
}
73+
74+
public String post(String api,HttpHeaders headers, JSONObject requestBody) {
7075
for (int i=0;i< RETRY_COUNT;i++){
7176
try {
72-
return _post(api, paramBuilder);
77+
return _post(api, headers, requestBody);
7378
}catch (Exception e){
7479
log.warn("api:{},error:{}",api,e.getMessage());
7580
sleep();
@@ -78,6 +83,10 @@ public String post(String api, ApiPostParamBuilder paramBuilder) {
7883
return EMPTY;
7984
}
8085

86+
public String post(String api,HttpHeaders headers, ApiPostParamBuilder paramBuilder) {
87+
return post(api, headers, paramBuilder.build());
88+
}
89+
8190

8291
private void sleep(){
8392
try {

0 commit comments

Comments
 (0)