diff --git a/server/api-service/lowcoder-plugins/graphqlPlugin/src/main/java/org/lowcoder/plugin/graphql/GraphQLExecutor.java b/server/api-service/lowcoder-plugins/graphqlPlugin/src/main/java/org/lowcoder/plugin/graphql/GraphQLExecutor.java index bd19bb67a..fdfb540ac 100644 --- a/server/api-service/lowcoder-plugins/graphqlPlugin/src/main/java/org/lowcoder/plugin/graphql/GraphQLExecutor.java +++ b/server/api-service/lowcoder-plugins/graphqlPlugin/src/main/java/org/lowcoder/plugin/graphql/GraphQLExecutor.java @@ -244,6 +244,7 @@ public Mono executeQuery(Object o, GraphQLQueryExecutionCo .then(Mono.defer(() -> { URI uri = RestApiUriBuilder.buildUri(context.getUrl(), new HashMap<>(), context.getUrlParams()); WebClient.Builder webClientBuilder = WebClientBuildHelper.builder() + .systemProxy() .disallowedHosts(commonConfig.getDisallowedHosts()) .toWebClientBuilder(); diff --git a/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java b/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java index fdb5d4736..c5352c2fe 100644 --- a/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java +++ b/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java @@ -218,6 +218,7 @@ public Mono executeQuery(Object webClientFilter, RestApiQu return Mono.defer(() -> authByOauth2InheritFromLogin(context)) .then(Mono.defer(() -> { WebClient.Builder webClientBuilder = WebClientBuildHelper.builder() + .systemProxy() .disallowedHosts(commonConfig.getDisallowedHosts()) .sslConfig(context.getSslConfig()) .timeoutMs(context.getTimeoutMs()) diff --git a/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/webclient/WebClientBuildHelper.java b/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/webclient/WebClientBuildHelper.java index 0610b6927..85e1e38b9 100644 --- a/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/webclient/WebClientBuildHelper.java +++ b/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/webclient/WebClientBuildHelper.java @@ -10,11 +10,13 @@ import org.lowcoder.sdk.plugin.common.ssl.SslConfig; import org.lowcoder.sdk.plugin.common.ssl.SslHelper; import org.lowcoder.sdk.plugin.common.ssl.VerifySelfSignedCertSslConfig; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.Builder; import reactor.netty.http.client.HttpClient; import reactor.netty.tcp.SslProvider; +import reactor.netty.transport.ProxyProvider; import reactor.netty.transport.ProxyProvider.Proxy; import javax.net.ssl.SSLException; @@ -28,6 +30,8 @@ public class WebClientBuildHelper { private static final String proxyHost; private static final String proxyPortStr; + private static final String proxyUsername; + private static final String proxyPassword; private SslConfig sslConfig; private Set disallowedHosts; @@ -39,6 +43,8 @@ public class WebClientBuildHelper { static { proxyHost = System.getProperty("http.proxyHost"); proxyPortStr = System.getProperty("http.proxyPort"); + proxyUsername = System.getProperty("http.proxyUsername"); + proxyPassword = System.getProperty("http.proxyPassword"); } private WebClientBuildHelper() { @@ -92,10 +98,23 @@ public Builder toWebClientBuilder() { httpClient = httpClient.secure(sslProviderWithSelfSignedCert(verifySelfSignedCertSslConfig)); } } - if (systemProxy && StringUtils.isNoneBlank(proxyHost, proxyPortStr)) { - httpClient = httpClient.proxy(typeSpec -> typeSpec.type(Proxy.HTTP) - .host(proxyHost) - .port(Integer.parseInt(proxyPortStr))); + if (systemProxy && StringUtils.isNotBlank(proxyHost)) { + httpClient = httpClient.proxy(typeSpec -> { + ProxyProvider.Builder builder = typeSpec + .type(Proxy.HTTP) + .host(proxyHost); + PropertyMapper mapper = PropertyMapper.get(); + mapper.from(proxyPortStr) + .whenHasText() + .to(portStr -> builder.port(Integer.parseInt(portStr))); + mapper.from(proxyUsername) + .whenHasText() + .to(builder::username); + mapper.from(proxyPassword) + .whenHasText() + .to(password -> builder.password(s -> password)); + } + ); } if (CollectionUtils.isNotEmpty(disallowedHosts)) { httpClient = httpClient.resolver(new SafeHostResolverGroup(disallowedHosts));