Skip to content

Commit e26558b

Browse files
Thomas-EliotCH3CHO
andauthored
fix: support jdk 8 (higress-group#497)
Co-authored-by: Kent Dong <ch3cho@qq.com>
1 parent 432ae9e commit e26558b

35 files changed

+469
-384
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ build/
3535
!**/src/test/**/build/
3636

3737
### VS Code ###
38-
.vscode/
38+
.vscode/
39+
/backend/console/src/main/resources/application-local.yml

backend/console/src/main/java/com/alibaba/higress/console/aop/ApiStandardizationAspect.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,6 @@
1212
*/
1313
package com.alibaba.higress.console.aop;
1414

15-
import java.util.HashSet;
16-
import java.util.Set;
17-
import java.util.UUID;
18-
import java.util.function.BiConsumer;
19-
20-
import javax.annotation.Resource;
21-
22-
import org.aspectj.lang.ProceedingJoinPoint;
23-
import org.aspectj.lang.Signature;
24-
import org.aspectj.lang.annotation.Around;
25-
import org.aspectj.lang.annotation.Aspect;
26-
import org.slf4j.MDC;
27-
import org.springframework.http.HttpMethod;
28-
import org.springframework.http.HttpStatus;
29-
import org.springframework.http.ResponseEntity;
30-
import org.springframework.stereotype.Component;
31-
import org.springframework.web.context.request.RequestContextHolder;
32-
import org.springframework.web.context.request.ServletRequestAttributes;
33-
3415
import com.alibaba.higress.console.context.HttpContext;
3516
import com.alibaba.higress.console.controller.HealthzController;
3617
import com.alibaba.higress.console.controller.LandingController;
@@ -45,9 +26,25 @@
4526
import com.alibaba.higress.sdk.exception.NotFoundException;
4627
import com.alibaba.higress.sdk.exception.ResourceConflictException;
4728
import com.alibaba.higress.sdk.exception.ValidationException;
48-
4929
import io.kubernetes.client.openapi.ApiException;
5030
import lombok.extern.slf4j.Slf4j;
31+
import org.aspectj.lang.ProceedingJoinPoint;
32+
import org.aspectj.lang.Signature;
33+
import org.aspectj.lang.annotation.Around;
34+
import org.aspectj.lang.annotation.Aspect;
35+
import org.slf4j.MDC;
36+
import org.springframework.http.HttpMethod;
37+
import org.springframework.http.HttpStatus;
38+
import org.springframework.http.ResponseEntity;
39+
import org.springframework.stereotype.Component;
40+
import org.springframework.web.context.request.RequestContextHolder;
41+
import org.springframework.web.context.request.ServletRequestAttributes;
42+
43+
import javax.annotation.Resource;
44+
import java.util.HashSet;
45+
import java.util.Set;
46+
import java.util.UUID;
47+
import java.util.function.BiConsumer;
5148

5249
/**
5350
* @author CH3CHO
@@ -86,8 +83,8 @@ public Object intercept(ProceedingJoinPoint point) {
8683
SessionUserHelper.setCurrentUser(user);
8784
}
8885
Object result = point.proceed();
89-
if (requestAttributes != null && requestAttributes.getResponse() != null
90-
&& HttpMethod.DELETE.name().equals(requestAttributes.getRequest().getMethod())) {
86+
if (requestAttributes != null && requestAttributes.getResponse() != null && HttpMethod.DELETE.name()
87+
.equals(requestAttributes.getRequest().getMethod())) {
9188
requestAttributes.getResponse().setStatus(HttpStatus.NO_CONTENT.value());
9289
}
9390
return result;
@@ -98,8 +95,7 @@ public Object intercept(ProceedingJoinPoint point) {
9895
String msg = t.getClass().getSimpleName() + " occurs when calling " + objectName + "." + methodName;
9996
if (t instanceof AuthException) {
10097
// No logging for AuthException
101-
} else if (t instanceof ValidationException || t instanceof NotFoundException
102-
|| t instanceof ResourceConflictException) {
98+
} else if (t instanceof ValidationException || t instanceof NotFoundException || t instanceof ResourceConflictException) {
10399
logException(log::warn, msg, t);
104100
} else {
105101
logException(log::error, msg, t);
@@ -116,14 +112,16 @@ public Object intercept(ProceedingJoinPoint point) {
116112
private static void logException(BiConsumer<String, Object> logFunction, String msg, Throwable t) {
117113
logFunction.accept(msg, t);
118114
Set<Throwable> loggedThrowables = new HashSet<>();
119-
for (Throwable t1 = t; t1!= null; t1 = t1.getCause()) {
115+
for (Throwable t1 = t; t1 != null; t1 = t1.getCause()) {
120116
if (!loggedThrowables.add(t1)) {
121117
break;
122118
}
123-
if (!(t1 instanceof ApiException apiException)){
119+
if (!(t1 instanceof ApiException)) {
124120
continue;
125121
}
126-
String message = String.format("Related K8s API response: Code=%s Body=%s", apiException.getCode(), apiException.getResponseBody());
122+
ApiException apiException = (ApiException)t1;
123+
String message = String.format("Related K8s API response: Code=%s Body=%s", apiException.getCode(),
124+
apiException.getResponseBody());
127125
logFunction.accept(message, null);
128126
}
129127
}

backend/console/src/main/java/com/alibaba/higress/console/controller/WasmPluginInstancesController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.alibaba.higress.console.controller;
1414

1515
import java.util.List;
16+
import java.util.stream.Collectors;
1617

1718
import javax.annotation.Resource;
1819
import javax.validation.constraints.NotBlank;
@@ -246,7 +247,7 @@ public void deleteServiceInstance(@PathVariable("serviceName") @NotBlank String
246247
private ResponseEntity<PaginatedResponse<WasmPluginInstance>> listInstances(WasmPluginInstanceScope scope,
247248
String target) {
248249
List<WasmPluginInstance> instances = wasmPluginInstanceService.list(scope, target).
249-
stream().filter(instance -> !instance.isInternal()).toList();
250+
stream().filter(instance -> !instance.isInternal()).collect(Collectors.toList());
250251
return ControllerUtil.buildResponseEntity(PaginatedResult.createFromFullList(instances, null));
251252
}
252253

backend/console/src/main/java/com/alibaba/higress/console/controller/dto/PaginatedResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.util.List;
1616
import java.util.function.Function;
17+
import java.util.stream.Collectors;
1718

1819
import com.alibaba.higress.sdk.model.PaginatedResult;
1920

@@ -53,7 +54,7 @@ public static <T, V> PaginatedResponse<V> success(PaginatedResult<T> result, Fun
5354
response.setPageNum(result.getPageNum());
5455
response.setPageSize(result.getPageSize());
5556
response.setTotal(result.getTotal());
56-
response.setData(result.getData().stream().map(converter).toList());
57+
response.setData(result.getData().stream().map(converter).collect(Collectors.toList()));
5758
return response;
5859
}
5960
}

backend/console/src/main/java/com/alibaba/higress/console/service/SystemServiceImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
import com.alibaba.higress.sdk.service.RouteService;
5757
import com.alibaba.higress.sdk.service.TlsCertificateService;
5858
import com.alibaba.higress.sdk.service.kubernetes.KubernetesClientService;
59+
import com.alibaba.higress.sdk.util.MapUtil;
60+
import com.google.common.collect.Lists;
61+
import com.google.common.collect.Sets;
5962

6063
import io.kubernetes.client.openapi.ApiException;
6164
import io.kubernetes.client.openapi.models.V1ConfigMap;
@@ -75,7 +78,7 @@ public class SystemServiceImpl implements SystemService {
7578
private static final String UNKNOWN = "unknown";
7679
private static final String COMMIT_ID;
7780
private static final String HIGRESS_CONFIG = "higress-config";
78-
private static final Set<String> REQUIRED_HIGRESS_CONFIG_KEYS = Set.of("higress", "mesh", "meshNetworks");
81+
private static final Set<String> REQUIRED_HIGRESS_CONFIG_KEYS = Sets.newHashSet("higress", "mesh", "meshNetworks");
7982

8083
static {
8184
String commitId = null;
@@ -161,7 +164,7 @@ private void initInternalState() {
161164
}
162165
this.capabilities = capabilities;
163166

164-
Map<String, Object> configs = Map.of(UserConfigKey.SYSTEM_INITIALIZED, sessionService.isAdminInitialized(),
167+
Map<String, Object> configs = MapUtil.of(UserConfigKey.SYSTEM_INITIALIZED, sessionService.isAdminInitialized(),
165168
UserConfigKey.DASHBOARD_BUILTIN, dashboardService.isBuiltIn());
166169
configService.setConfigs(configs);
167170

@@ -211,7 +214,7 @@ private void initDefaultRoutes() {
211214

212215
TlsCertificate defaultCertificate = new TlsCertificate();
213216
defaultCertificate.setName(DEFAULT_TLS_CERTIFICATE_NAME);
214-
defaultCertificate.setDomains(List.of(DEFAULT_TLS_CERTIFICATE_HOST));
217+
defaultCertificate.setDomains(Lists.newArrayList(DEFAULT_TLS_CERTIFICATE_HOST));
215218
defaultCertificate.setKey(
216219
CertificateUtil.toPem(CertificateUtil.RSA_PRIVATE_KEY_PEM_TYPE, keyPair.getPrivate().getEncoded()));
217220
defaultCertificate
@@ -235,7 +238,8 @@ private void initDefaultRoutes() {
235238
RoutePredicate routePredicate =
236239
RoutePredicate.builder().matchType(RoutePredicateTypeEnum.EQUAL.name()).matchValue("/").build();
237240
route.setPath(routePredicate);
238-
route.setServices(List.of(new UpstreamService(consoleServiceHost, consoleServicePort, null, null)));
241+
route.setServices(
242+
Lists.newArrayList(new UpstreamService(consoleServiceHost, consoleServicePort, null, null)));
239243
route.setRewrite(new RewriteConfig(true, "/landing", null));
240244
routeService.add(route);
241245

backend/console/src/test/java/com/alibaba/higress/console/FrontEndI18nResourceChecker.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import com.alibaba.fastjson.JSON;
3535
import com.alibaba.fastjson.JSONObject;
36+
import com.google.common.collect.Sets;
3637

3738
@Disabled
3839
public class FrontEndI18nResourceChecker {
@@ -42,9 +43,9 @@ public class FrontEndI18nResourceChecker {
4243
private static final String I18N_RESOURCE_FILE_NAME = "translation.json";
4344
private static final List<String> TS_FILE_EXTENSIONS = Arrays.asList(".ts", ".tsx");
4445

45-
private static final Set<String> IMPLICITLY_USED_RESOURCE_KEYS = Set.of("index.title", "init.title", "login.title",
46-
"aiRoute.edit", "tlsCertificate.editTlsCertificate", "serviceSource.editServiceSource", "llmProvider.edit",
47-
"plugins.editPlugin", "route.editRoute", "domain.editDomain", "consumer.edit");
46+
private static final Set<String> IMPLICITLY_USED_RESOURCE_KEYS = Sets.newHashSet("index.title", "init.title",
47+
"login" + ".title", "aiRoute.edit", "tlsCertificate.editTlsCertificate", "serviceSource.editServiceSource",
48+
"llmProvider.edit", "plugins.editPlugin", "route.editRoute", "domain.editDomain", "consumer.edit");
4849
private static final List<String> IMPLICITLY_USED_RESOURCE_KEY_PREFIXES =
4950
Arrays.asList("menu.", "request.error.", "serviceSource.types.", "llmProvider.providerTypes.",
5051
"route.factorGroup.required.", "route.keyValueGroup.required.", "plugins.configForm.", "plugins.subTitle.");
@@ -69,7 +70,7 @@ public void checkI18nResourceUsages() throws IOException {
6970
}).forEach(p -> {
7071
String content;
7172
try {
72-
content = Files.readString(p, StandardCharsets.UTF_8);
73+
content = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
7374
} catch (IOException e) {
7475
System.out.println("Failed to read file: " + p);
7576
return;
@@ -167,7 +168,7 @@ private static Set<String> getReferredResources(String content) {
167168

168169
private static Map<String, String> loadI18nResources(String language) throws IOException {
169170
Path resourceFilePath = Paths.get(FRONTEND_PROJECT_PATH, I18N_RESOURCE_PATH, language, I18N_RESOURCE_FILE_NAME);
170-
String json = Files.readString(resourceFilePath, StandardCharsets.UTF_8);
171+
String json = new String(Files.readAllBytes(resourceFilePath), StandardCharsets.UTF_8);
171172
JSONObject obj = JSON.parseObject(json);
172173
Map<String, String> resources = new LinkedHashMap<>();
173174
addI18nResources(resources, obj, "");

backend/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
</developers>
5151

5252
<properties>
53-
<java.version>17</java.version>
53+
<!--Declare the minimum JDK version for dependency.-->
54+
<java.version>1.8</java.version>
5455

5556
<retrofit.version>2.9.0</retrofit.version>
5657
<guava.version>31.1-jre</guava.version>
@@ -172,7 +173,8 @@
172173
<configuration>
173174
<source>${maven.compiler.source}</source>
174175
<target>${maven.compiler.target}</target>
175-
<compilerVersion>${maven.compiler.source}</compilerVersion>
176+
<compilerVersion>${maven.compiler.target}</compilerVersion>
177+
<release>8</release>
176178
<showDeprecation>true</showDeprecation>
177179
<showWarnings>true</showWarnings>
178180
</configuration>

backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/HigressConstants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package com.alibaba.higress.sdk.constant;
1414

15+
import com.google.common.collect.Sets;
16+
1517
import java.util.Set;
1618

1719
public class HigressConstants {
@@ -28,5 +30,5 @@ public class HigressConstants {
2830
public static final String FALLBACK_FROM_HEADER = "x-higress-fallback-from";
2931
public static final String MODEL_ROUTING_HEADER = "x-higress-llm-model";
3032
public static final String INTERNAL_RESOURCE_COMMENT = "PLEASE DO NOT EDIT DIRECTLY. This resource is managed by Higress.";
31-
public static final Set<String> VALID_FALLBACK_RESPONSE_CODES = Set.of("4xx", "5xx");
33+
public static final Set<String> VALID_FALLBACK_RESPONSE_CODES = Sets.newHashSet("4xx", "5xx");
3234
}

backend/sdk/src/main/java/com/alibaba/higress/sdk/model/PaginatedResult.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public static <T, V> PaginatedResult<V> createFromFullList(List<T> list, CommonP
6969
} else {
7070
result.data = data.stream().map(converter).collect(Collectors.toList());
7171
}
72-
7372
return result;
7473
}
7574
}

backend/sdk/src/main/java/com/alibaba/higress/sdk/model/ServiceSource.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,26 @@ private boolean validateMcpConfigs() {
135135

136136
Object rawExportDomains = properties.get(V1McpBridge.MCP_SERVER_EXPORT_DOMAINS);
137137
if (rawExportDomains != null) {
138-
if (!(rawExportDomains instanceof List<?> exportDomains)) {
138+
if (!(rawExportDomains instanceof List)) {
139139
return false;
140140
}
141+
List<?> exportDomains = (List<?>) rawExportDomains;
141142
for (Object rawExportDomain : exportDomains) {
142-
if (!(rawExportDomain instanceof String exportDomain)) {
143+
if (!(rawExportDomain instanceof String)) {
143144
return false;
144145
}
146+
String exportDomain = (String) rawExportDomain;
145147
if (!ValidateUtil.checkDomain(exportDomain)) {
146148
return false;
147149
}
148150
}
149151
}
150152

151153
Object rawServerBaseUrl = properties.get(V1McpBridge.MCP_SERVER_BASE_URL);
152-
if (!(rawServerBaseUrl instanceof String serverBaseUrl)) {
154+
if (!(rawServerBaseUrl instanceof String)) {
153155
return false;
154156
}
157+
String serverBaseUrl= (String) rawServerBaseUrl;
155158
if (!ValidateUtil.checkUrlPath(serverBaseUrl)) {
156159
return false;
157160
}

0 commit comments

Comments
 (0)