Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
| 版本 | 发版日期 | 变更内容 |
| --- | ------------ | ------------------------------------------ |
| 4.4.10| 2024-04-22 | yos文件上传支持自定义文件名 |
| 4.4.11| 2024-04-25 | 路由切换功能单独分包,默认熔断时长10min,默认连接超时3s |
| 4.4.10| 2024-04-22 | yos文件上传支持自定义扩展名 |
| 4.4.9 | 2024-01-23 | 支持多环境混合调用 |
| 4.4.8 | 2023-12-15 | 域名切换逻辑抽离&优化,方便复用与扩展,切换更灵敏 |
| 4.4.7 | 2023-11-14 | 修复json请求类型判断(影响业务SDK) |
Expand Down
18 changes: 12 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<module>yop-java-sdk-invoke-api</module>
<module>yop-java-sdk-invoke-base</module>
<module>yop-java-sdk-api</module>
<module>yop-java-sdk-router</module>
<module>yop-java-sdk-utils</module>
</modules>

<name>yop-java-sdk-parent</name>
Expand Down Expand Up @@ -119,6 +121,16 @@
<artifactId>yop-java-sdk-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yeepay.yop.sdk</groupId>
<artifactId>yop-java-sdk-router</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yeepay.yop.sdk</groupId>
<artifactId>yop-java-sdk-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -238,12 +250,6 @@
<version>${slf4j-api.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>${sentinel.version}</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
50 changes: 4 additions & 46 deletions yop-java-sdk-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,23 @@
<artifactId>yop-java-sdk-invoke-base</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>com.yeepay.yop.sdk</groupId>
<artifactId>yop-java-sdk-router</artifactId>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<groupId>com.yeepay.yop.sdk</groupId>
<artifactId>yop-java-sdk-utils</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand All @@ -78,16 +46,6 @@
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public interface YopConstants {

String VERSION = "4.4.10";
String VERSION = "4.4.11";

String DEFAULT_ENCODING = "UTF-8";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import com.yeepay.yop.sdk.client.support.ClientConfigurationSupport;
import com.yeepay.yop.sdk.config.YopSdkConfig;
import com.yeepay.yop.sdk.config.provider.YopSdkConfigProvider;
import com.yeepay.yop.sdk.invoke.RouterPolicy;
import com.yeepay.yop.sdk.router.YopRouterConstants;
import com.yeepay.yop.sdk.router.config.YopRouteConfigProvider;
import com.yeepay.yop.sdk.router.config.YopRouteConfigProviderRegistry;
import com.yeepay.yop.sdk.router.policy.RouterPolicyFactory;
import com.yeepay.yop.sdk.utils.ClientUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -50,6 +55,10 @@ public abstract class AbstractServiceClientBuilder<SubClass extends AbstractServ

private YopPlatformCredentialsProvider platformCredentialsProvider;

private YopRouteConfigProvider routeConfigProvider;

private RouterPolicy routerPolicy;

private String endpoint;

private List<URI> preferredEndPoint;
Expand All @@ -74,6 +83,9 @@ public final ServiceInterfaceToBuild build() {
if (null == platformCredentialsProvider) {
platformCredentialsProvider = YopPlatformCredentialsProviderRegistry.getProvider();
}
if (null == routeConfigProvider) {
routeConfigProvider = YopRouteConfigProviderRegistry.getProvider();
}
YopSdkConfig yopSdkConfig = yopSdkConfigProvider.getConfig(provider, env);
if (null == clientConfiguration) {
clientConfiguration = ClientConfigurationSupport.getClientConfiguration(yopSdkConfig);
Expand All @@ -86,13 +98,18 @@ public final ServiceInterfaceToBuild build() {
preferredYosEndPoint = CollectionUtils.isNotEmpty(yopSdkConfig.getPreferredYosServerRoots()) ?
yopSdkConfig.getPreferredYosServerRoots().stream().map(URI::create).collect(Collectors.toList()) : Collections.emptyList();
}
if (null == routerPolicy) {
routerPolicy = RouterPolicyFactory.get(YopRouterConstants.ROUTER_POLICY_DEFAULT);
}
ClientParams clientParams = ClientParams.Builder.builder()
.withInner(this.inner)
.withProvider(this.provider)
.withEnv(this.env)
.withCredentialsProvider(credentialsProvider)
.withYopSdkConfigProvider(yopSdkConfigProvider)
.withPlatformCredentialsProvider(platformCredentialsProvider)
.withRouteConfigProvider(routeConfigProvider)
.withRouterPolicy(routerPolicy)
.withClientConfiguration(clientConfiguration)
.withEndPoint(endpoint == null ? URI.create(StringUtils.defaultIfBlank(yopSdkConfig.getServerRoot(), YopConstants.DEFAULT_SERVER_ROOT)) : URI.create(endpoint))
.withYosEndPoint(yosEndPoint == null ? URI.create(StringUtils.defaultIfBlank(yopSdkConfig.getYosServerRoot(), YopConstants.DEFAULT_YOS_SERVER_ROOT)) : URI.create(yosEndPoint))
Expand Down Expand Up @@ -152,6 +169,16 @@ public SubClass withPlatformCredentialsProvider(YopPlatformCredentialsProvider p
return getSubclass();
}

public SubClass withRouteConfigProvider(YopRouteConfigProvider routeConfigProvider) {
this.routeConfigProvider = routeConfigProvider;
return getSubclass();
}

public SubClass withRouterPolicy(RouterPolicy routerPolicy) {
this.routerPolicy = routerPolicy;
return getSubclass();
}

public SubClass withClientConfiguration(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
return getSubclass();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.yeepay.yop.sdk.client;

import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.yeepay.yop.sdk.Region;
import com.yeepay.yop.sdk.YopConstants;
import com.yeepay.yop.sdk.auth.credentials.YopCredentials;
import com.yeepay.yop.sdk.config.provider.file.YopCircuitBreakerConfig;
import com.yeepay.yop.sdk.http.Protocol;
import com.yeepay.yop.sdk.http.RetryPolicy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.net.InetAddress;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
Expand All @@ -26,12 +22,12 @@ public class ClientConfiguration {
/**
* The default timeout for creating new connections.
*/
public static final int DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS = 10 * 1000;
public static final int DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS = 3 * 1000;

/**
* The default timeout for request new connections form pool.
*/
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT_IN_MILLIS = 10 * 1000;
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT_IN_MILLIS = 3 * 1000;

/**
* The default timeout for reading from a connected socket.
Expand Down Expand Up @@ -174,20 +170,6 @@ public class ClientConfiguration {
*/
private String clientImpl = YOP_HTTP_CLIENT_IMPL_DEFAULT;

private int maxRetryCount = 3;

private Set<String> retryExceptions = Sets.newHashSet("java.net.UnknownHostException",
"java.net.ConnectException:No route to host (connect failed)",
"java.net.ConnectException:Connection refused (Connection refused)",
"java.net.ConnectException:Connection refused: connect",
"java.net.SocketTimeoutException:connect timed out",
"java.net.NoRouteToHostException",
"org.apache.http.conn.ConnectTimeoutException", "com.yeepay.shade.org.apache.http.conn.ConnectTimeoutException",
"org.apache.http.conn.HttpHostConnectException", "com.yeepay.shade.org.apache.http.conn.HttpHostConnectException",
"java.net.ConnectException:Connection timed out","java.net.ConnectException:连接超时");

private YopCircuitBreakerConfig circuitBreakerConfig = YopCircuitBreakerConfig.DEFAULT_CONFIG;

// Initialize DEFAULT_USER_AGENT
static {
String language = System.getProperty("user.language");
Expand Down Expand Up @@ -238,9 +220,6 @@ public ClientConfiguration(ClientConfiguration other) {
this.region = other.region;
this.credentials = other.credentials;
this.clientImpl = other.clientImpl;
this.maxRetryCount = other.maxRetryCount;
this.retryExceptions = other.retryExceptions;
this.circuitBreakerConfig = other.circuitBreakerConfig;
}

/**
Expand Down Expand Up @@ -929,51 +908,6 @@ public ClientConfiguration withClientImpl(String clientImpl) {
return this;
}

public int getMaxRetryCount() {
return maxRetryCount;
}

public void setMaxRetryCount(int maxRetryCount) {
if (maxRetryCount > 0) {
this.maxRetryCount = maxRetryCount;
}
}

public ClientConfiguration withMaxRetryCount(int maxRetryCount) {
setMaxRetryCount(maxRetryCount);
return this;
}

public Set<String> getRetryExceptions() {
return retryExceptions;
}

public void setRetryExceptions(Set<String> retryExceptions) {
if (CollectionUtils.isNotEmpty(retryExceptions)) {
this.retryExceptions = retryExceptions;
}
}

public ClientConfiguration withRetryExceptions(Set<String> retryExceptions) {
setRetryExceptions(retryExceptions);
return this;
}

public YopCircuitBreakerConfig getCircuitBreakerConfig() {
return circuitBreakerConfig;
}

public void setCircuitBreakerConfig(YopCircuitBreakerConfig circuitBreakerConfig) {
if (null != circuitBreakerConfig) {
this.circuitBreakerConfig = circuitBreakerConfig;
}
}

public ClientConfiguration withCircuitBreakerConfig(YopCircuitBreakerConfig circuitBreakerConfig) {
setCircuitBreakerConfig(circuitBreakerConfig);
return this;
}

@Override
public String toString() {
return "ClientConfiguration [ \n userAgent=" + userAgent
Expand All @@ -991,10 +925,7 @@ public String toString() {
+ socketBufferSizeInBytes + ", \n region="
+ region + ", \n credentials="
+ credentials + ", \n clientImpl="
+ clientImpl + ", \n maxRetryCount="
+ maxRetryCount + ", \n retryExceptions="
+ retryExceptions + ", \n circuitBreakerConfig="
+ circuitBreakerConfig + "]\n";
+ clientImpl + "]\n";
}

}
Loading