Skip to content

Commit 28fa1f2

Browse files
committed
release 0.0.8-beta source code for java
1 parent e1d51e9 commit 28fa1f2

File tree

268 files changed

+41935
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+41935
-88
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 0.0.8-beta 2023-06-26
2+
3+
### G42Cloud SDK MPC
4+
5+
- _Features_
6+
- New Support MPC
7+
- _Bug Fix_
8+
- None
9+
- _Change_
10+
- None
11+
112
# 0.0.7-beta 2023-06-16
213

314
### G42Cloud SDK CCE

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
<parent>
77
<groupId>io.github.g42cloud-sdk</groupId>
8-
<version>0.0.7-beta</version>
8+
<version>0.0.8-beta</version>
99
<artifactId>g42cloud-sdk</artifactId>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>
1313
<packaging>jar</packaging>
1414
<artifactId>g42cloud-sdk-core</artifactId>
15-
<version>0.0.7-beta</version>
15+
<version>0.0.8-beta</version>
1616
<name>G42 Cloud SDK for Java Core</name>
1717
<description>Core library for G42 Cloud Java SDK</description>
1818
<url>https://github.com/g42cloud-sdk/g42cloud-sdk-java</url>

core/src/main/java/com/g42cloud/sdk/core/ClientBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.g42cloud.sdk.core.auth.BasicCredentials;
2626
import com.g42cloud.sdk.core.auth.CredentialProviderChain;
2727
import com.g42cloud.sdk.core.auth.ICredential;
28+
import com.g42cloud.sdk.core.exception.ExceptionHandler;
2829
import com.g42cloud.sdk.core.exception.SdkException;
2930
import com.g42cloud.sdk.core.http.HttpClient;
3031
import com.g42cloud.sdk.core.http.HttpConfig;
@@ -53,6 +54,8 @@ public class ClientBuilder<T> {
5354

5455
private List<String> endpoints;
5556

57+
private ExceptionHandler exceptionHandler;
58+
5659
private List<String> credentialType = new ArrayList<>(
5760
Collections.singletonList(BasicCredentials.class.getSimpleName()));
5861

@@ -101,6 +104,11 @@ public ClientBuilder<T> withEndpoints(List<String> endpoints) {
101104
return this;
102105
}
103106

107+
public ClientBuilder<T> withExceptionHandler(ExceptionHandler exceptionHandler) {
108+
this.exceptionHandler = exceptionHandler;
109+
return this;
110+
}
111+
104112
public T build() {
105113
if (Objects.isNull(httpConfig)) {
106114
httpConfig = HttpConfig.getDefaultHttpConfig();
@@ -148,6 +156,9 @@ public T build() {
148156
? endpoint : Constants.HTTPS_SCHEME + "://" + endpoint);
149157

150158
hcClient.withEndpoints(endpoints).withCredential(credential);
159+
if (Objects.nonNull(exceptionHandler)) {
160+
hcClient.withExceptionHandler(exceptionHandler);
161+
}
151162

152163
T t = creator.apply(hcClient);
153164
ClientCustomization clientCustomization = loadClientCustomization(t);

core/src/main/java/com/g42cloud/sdk/core/HcClient.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525
import com.g42cloud.sdk.core.auth.ICredential;
26+
import com.g42cloud.sdk.core.exception.DefaultExceptionHandler;
27+
import com.g42cloud.sdk.core.exception.ExceptionHandler;
2628
import com.g42cloud.sdk.core.exception.HostUnreachableException;
2729
import com.g42cloud.sdk.core.exception.SdkException;
2830
import com.g42cloud.sdk.core.exception.ServerResponseException;
@@ -89,6 +91,8 @@ public static Logger get() {
8991

9092
private final AtomicInteger endpointIndex = new AtomicInteger(0);
9193

94+
private ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
95+
9296
private List<String> endpoints;
9397

9498
private ICredential credential;
@@ -97,11 +101,13 @@ public static Logger get() {
97101

98102
private Map<String, String> extraHeader;
99103

100-
private HcClient(HttpConfig httpConfig, HttpClient httpClient, ICredential credential, List<String> endpoints) {
101-
this.httpConfig = httpConfig;
102-
this.httpClient = httpClient;
103-
this.credential = credential;
104-
this.endpoints = endpoints;
104+
private HcClient(HcClient hcClient) {
105+
this.extraHeader = hcClient.extraHeader;
106+
this.httpClient = hcClient.httpClient;
107+
this.endpoints = hcClient.endpoints;
108+
this.credential = hcClient.credential;
109+
this.httpConfig = hcClient.httpConfig;
110+
this.exceptionHandler = hcClient.exceptionHandler;
105111
}
106112

107113
HcClient(HttpConfig httpConfig, HttpClient httpClient) {
@@ -124,6 +130,11 @@ public HcClient withCredential(ICredential credential) {
124130
return this;
125131
}
126132

133+
protected HcClient withExceptionHandler(ExceptionHandler exceptionHandler) {
134+
this.exceptionHandler = exceptionHandler;
135+
return this;
136+
}
137+
127138
public ICredential getCredential() {
128139
return this.credential;
129140
}
@@ -133,16 +144,15 @@ public HttpConfig getHttpConfig() {
133144
}
134145

135146
public HcClient overrideEndpoints(List<String> endpoints) {
136-
return new HcClient(this.httpConfig, this.httpClient, this.credential, endpoints);
147+
return new HcClient(this).withEndpoints(endpoints);
137148
}
138149

139150
public HcClient overrideCredential(ICredential credential) {
140-
141-
return new HcClient(this.httpConfig, this.httpClient, credential, this.endpoints);
151+
return new HcClient(this).withCredential(credential);
142152
}
143153

144154
public HcClient preInvoke(Map<String, String> extraHeader) {
145-
HcClient client = new HcClient(this.httpConfig, this.httpClient, this.credential, this.endpoints);
155+
HcClient client = new HcClient(this);
146156
client.extraHeader = extraHeader;
147157
return client;
148158
}
@@ -189,7 +199,7 @@ public <ReqT, ResT> ResT syncInvokeHttp(ReqT request, HttpRequestDef<ReqT, ResT>
189199
}
190200
}
191201
printAccessLog(httpRequest, httpResponse, exchange);
192-
handleException(httpRequest, httpResponse);
202+
exceptionHandler.handleException(httpRequest, httpResponse);
193203
return extractResponse(httpRequest, httpResponse, reqDef);
194204
} finally {
195205
SdkExchangeCache.removeExchange(exchangeId);
@@ -237,7 +247,7 @@ public <ReqT, ResT> CompletableFuture<ResT> asyncInvokeHttp(ReqT request, HttpRe
237247

238248
return httpClient.asyncInvokeHttp(validHttpRequest).thenApplyAsync(httpResponse -> {
239249
printAccessLog(finalValidHttpRequest, httpResponse, exchange);
240-
handleException(finalValidHttpRequest, httpResponse);
250+
exceptionHandler.handleException(finalValidHttpRequest, httpResponse);
241251
return extractResponse(finalValidHttpRequest, httpResponse, reqDef);
242252
}, httpConfig.getExecutorService()).whenCompleteAsync((r, e) ->
243253
SdkExchangeCache.removeExchange(exchangeIdRef.get()), httpConfig.getExecutorService());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.g42cloud.sdk.core.exception;
2+
3+
import com.g42cloud.sdk.core.Constants;
4+
import com.g42cloud.sdk.core.http.HttpRequest;
5+
import com.g42cloud.sdk.core.http.HttpResponse;
6+
import com.g42cloud.sdk.core.utils.ExceptionUtils;
7+
8+
public class DefaultExceptionHandler implements ExceptionHandler {
9+
@Override
10+
public void handleException(HttpRequest httpRequest, HttpResponse httpResponse) {
11+
if (httpResponse.getStatusCode() >= Constants.StatusCode.CLIENT_ERROR) {
12+
throw ServiceResponseException.mapException(httpResponse.getStatusCode(),
13+
ExceptionUtils.extractErrorMessage(httpResponse));
14+
}
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.g42cloud.sdk.core.exception;
2+
3+
import com.g42cloud.sdk.core.http.HttpRequest;
4+
import com.g42cloud.sdk.core.http.HttpResponse;
5+
6+
public interface ExceptionHandler {
7+
void handleException(HttpRequest httpRequest, HttpResponse httpResponse) throws ServiceResponseException;
8+
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<packaging>pom</packaging>
88
<groupId>io.github.g42cloud-sdk</groupId>
99
<artifactId>g42cloud-sdk</artifactId>
10-
<version>0.0.7-beta</version>
10+
<version>0.0.8-beta</version>
1111
<name>G42 Cloud SDK for Java Parent</name>
1212
<description>G42 Cloud SDK for Java</description>
1313
<url>https://github.com/g42cloud-sdk/g42cloud-sdk-java</url>
@@ -36,11 +36,11 @@
3636

3737
<properties>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39-
<revision>0.0.7-beta</revision>
39+
<revision>0.0.8-beta</revision>
4040
<snakeyaml.version>2.0</snakeyaml.version>
4141
<jackson.version>2.14.2</jackson.version>
4242
<okhttp.version>4.11.0</okhttp.version>
43-
<bgmprovider.version>1.0.6</bgmprovider.version>
43+
<bgmprovider.version>1.0.7</bgmprovider.version>
4444
<junit.version>4.13.1</junit.version>
4545
<slf4j.version>1.7.36</slf4j.version>
4646
<logback.version>1.2.12</logback.version>

services/bms/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<parent>
55
<groupId>io.github.g42cloud-sdk</groupId>
6-
<version>0.0.7-beta</version>
6+
<version>0.0.8-beta</version>
77
<artifactId>g42cloud-sdk-services</artifactId>
88
<relativePath>..</relativePath>
99
</parent>
1010
<artifactId>g42cloud-sdk-bms</artifactId>
11-
<version>0.0.7-beta</version>
11+
<version>0.0.8-beta</version>
1212
<name>G42 Cloud SDK for BMS</name>
1313

1414
<modelVersion>4.0.0</modelVersion>
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>io.github.g42cloud-sdk</groupId>
1919
<artifactId>g42cloud-sdk-core</artifactId>
20-
<version>0.0.7-beta</version>
20+
<version>0.0.8-beta</version>
2121
</dependency>
2222
</dependencies>
2323

services/cbr/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<parent>
55
<groupId>io.github.g42cloud-sdk</groupId>
6-
<version>0.0.7-beta</version>
6+
<version>0.0.8-beta</version>
77
<artifactId>g42cloud-sdk-services</artifactId>
88
<relativePath>..</relativePath>
99
</parent>
1010
<artifactId>g42cloud-sdk-cbr</artifactId>
11-
<version>0.0.7-beta</version>
11+
<version>0.0.8-beta</version>
1212
<name>G42 Cloud SDK for CBR</name>
1313

1414
<modelVersion>4.0.0</modelVersion>
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>io.github.g42cloud-sdk</groupId>
1919
<artifactId>g42cloud-sdk-core</artifactId>
20-
<version>0.0.7-beta</version>
20+
<version>0.0.8-beta</version>
2121
</dependency>
2222
</dependencies>
2323

services/cce/pom.xml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<parent>
5-
<groupId>io.github.g42cloud-sdk</groupId>
6-
<version>0.0.7-beta</version>
7-
<artifactId>g42cloud-sdk-services</artifactId>
8-
<relativePath>..</relativePath>
9-
</parent>
10-
<artifactId>g42cloud-sdk-cce</artifactId>
11-
<version>0.0.7-beta</version>
12-
<name>G42 Cloud SDK for CCE</name>
13-
14-
<modelVersion>4.0.0</modelVersion>
15-
<packaging>jar</packaging>
16-
<dependencies>
17-
<dependency>
4+
<parent>
185
<groupId>io.github.g42cloud-sdk</groupId>
19-
<artifactId>g42cloud-sdk-core</artifactId>
20-
<version>0.0.7-beta</version>
21-
</dependency>
22-
</dependencies>
6+
<version>0.0.8-beta</version>
7+
<artifactId>g42cloud-sdk-services</artifactId>
8+
<relativePath>..</relativePath>
9+
</parent>
10+
<artifactId>g42cloud-sdk-cce</artifactId>
11+
<version>0.0.8-beta</version>
12+
<name>G42 Cloud SDK for CCE</name>
13+
14+
<modelVersion>4.0.0</modelVersion>
15+
<packaging>jar</packaging>
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.github.g42cloud-sdk</groupId>
19+
<artifactId>g42cloud-sdk-core</artifactId>
20+
<version>0.0.8-beta</version>
21+
</dependency>
22+
</dependencies>
2323

2424
</project>

0 commit comments

Comments
 (0)