Skip to content
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@
<version>${org.springframework}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework}</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.yeepay.yop.sdk.http.impl.apache;

import com.yeepay.yop.sdk.client.ClientConfiguration;
import com.yeepay.yop.sdk.exception.YopClientBizException;
import com.yeepay.yop.sdk.exception.YopClientException;
import com.yeepay.yop.sdk.exception.param.IllegalParamFormatException;
import com.yeepay.yop.sdk.http.*;
import com.yeepay.yop.sdk.internal.MultiPartFile;
import com.yeepay.yop.sdk.internal.Request;
Expand Down Expand Up @@ -53,6 +55,7 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static com.yeepay.yop.sdk.YopConstants.*;
import static com.yeepay.yop.sdk.constants.ExceptionConstants.SDK_CONFIG_RUNTIME_DEPENDENCY;

/**
* title: Yop http客户端<br>
Expand Down Expand Up @@ -170,7 +173,7 @@ private HttpClientConnectionManager createHttpClientConnectionManager() {
SSLContext sslContext = getSSLContext();
sslSocketFactory = new SSLConnectionSocketFactory(sslContext, HOSTNAME_VERIFIER_INSTANCE);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new YopClientException("EnvProblem, Fail to Create SSLConnectionSocketFactory, ex:", e);
throw new YopClientBizException(SDK_CONFIG_RUNTIME_DEPENDENCY, "EnvProblem, Fail to Create SSLConnectionSocketFactory, ex:", e);
}
RegistryBuilder registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create().register(Protocol.HTTPS.toString(), sslSocketFactory)
.register(Protocol.HTTP.toString(), PlainConnectionSocketFactory.getSocketFactory());
Expand Down Expand Up @@ -302,7 +305,7 @@ private HttpRequestBase createHttpRequest(Request<?> request) {
} else if (request.getHttpMethod() == HttpMethodName.HEAD) {
httpRequest = new HttpHead(uri);
} else {
throw new YopClientException("ReqParam Illegal, HttpMethod, name:" + request.getHttpMethod());
throw new IllegalParamFormatException("httpMethod", "ReqParam Illegal, HttpMethod, name:" + request.getHttpMethod());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright: Copyright (c)2011
* Company: 易宝支付(YeePay)
*/

package com.yeepay.yop.sdk.constants;

/**
* title: YOP-SDK异常码定义<br>
* description: 描述<br>
* Copyright: Copyright (c)2014<br>
* Company: 易宝支付(YeePay)<br>
*
* @author wdc
* @version 1.0.0
* @since 2025/2/24
*/
public interface ExceptionConstants {

/**
* 错误描述:SDK项目运行时依赖配置异常
* 解决方案:检查pom.xml文件与类加载环境,确保按官方文档引入相关依赖
*/
String SDK_CONFIG_RUNTIME_DEPENDENCY = "sdk.config.runtime.dependency";

/**
* 错误描述:SDK配置项格式错误
* 解决方案:检查yop_sdk_config_xxx.json文件与YopFileSdkConfig配置类的属性,确保类型与格式正确
*/
String SDK_CONFIG_PARAM_FORMAT = "sdk.config.param.format";

/**
* 错误描述:SDK请求参数格式错误
* 解决方案:检查接口文档的参数描述与xxxRequest设置的实际参数,确保类型与格式正确
*/
String SDK_INVOKE_REQUEST_PARAM_FORMAT_PREFIX = "sdk.invoke.check.request-param.format";

/**
* 错误描述:SDK请求域名解析异常
* 解决方案:
* 1.检查客户端代理与服务端请求域名,确认网络配置是否正常,是否有网络波动
* 2.可通过查单接口或等待结果回调通知,获取最终业务处理状态,避免重复交易
*/
String SDK_INVOKE_IO_EXCEPTION_PREFIX = "sdk.invoke.io";

/**
* 错误描述:SDK请求域名熔断
* 解决方案:
* 1.检查报错详细堆栈,确定熔断原因
* 2.默认情况下,YOP-SDK会自动切换域名重试,重试次数为3次
* 3.可通过查单接口或等待结果回调通知,获取最终业务处理状态,避免重复交易
*/
String SDK_INVOKE_HOST_BLOCKED_EXCEPTION = "sdk.invoke.host.blocked";

/**
* 错误描述:SDK请求未知异常
* 解决方案:
* 1.检查报错详细堆栈,确定异常原因
* 2.可通过查单接口或等待结果回调通知,获取最终业务处理状态,避免重复交易
*/
String SDK_INVOKE_UNEXPECTED_EXCEPTION = "sdk.invoke.unexpected";


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.yeepay.yop.sdk.exception;

import com.yeepay.yop.sdk.utils.YopTraceUtils;

import static com.yeepay.yop.sdk.constants.CharacterConstants.COMMA;

/**
* title: <br>
* description: <br>
Expand All @@ -10,23 +14,39 @@
* @version 1.0.0
* @since 2018/8/17 16:45
*/
public class YopClientBizException extends YopClientException {
public class YopClientBizException extends YopClientException implements YopTracedException {

private static final long serialVersionUID = -1L;

private final String errorCode;
private final String requestId;



public YopClientBizException(String errorCode, String message) {
super(message);
this.requestId = YopTraceUtils.getCurrentRequestId();
this.errorCode = errorCode;
}

public YopClientBizException(String errorCode, String message, Throwable cause) {
super(message, cause);
this.requestId = YopTraceUtils.getCurrentRequestId();
this.errorCode = errorCode;
}

@Override
public String getErrorCode() {
return errorCode;
}

@Override
public String getMessage() {
return getErrorCode() + COMMA + getRequestId() + COMMA + super.getMessage();
}

@Override
public String getRequestId() {
return requestId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/
package com.yeepay.yop.sdk.exception;

import static com.yeepay.yop.sdk.constants.CharacterConstants.COMMA;
import static com.yeepay.yop.sdk.constants.CharacterConstants.EMPTY;
import static com.yeepay.yop.sdk.constants.ExceptionConstants.SDK_INVOKE_HOST_BLOCKED_EXCEPTION;

/**
* title: Yop域名熔断异常<br>
* description: 该异常会触发当笔切换dns重试<br>
Expand All @@ -14,7 +18,7 @@
* @version 1.0.0
* @since 2023/3/27
*/
public class YopHostBlockException extends YopBlockException {
public class YopHostBlockException extends YopBlockException implements YopTracedException {
private static final long serialVersionUID = -1L;

public YopHostBlockException(String message) {
Expand All @@ -24,4 +28,20 @@ public YopHostBlockException(String message) {
public YopHostBlockException(String message, Throwable cause) {
super(message, cause);
}

@Override
public String getErrorCode() {
return SDK_INVOKE_HOST_BLOCKED_EXCEPTION;
}

@Override
public String getRequestId() {
// 熔断异常,请求标识无意义
return EMPTY;
}

@Override
public String getMessage() {
return getErrorCode() + COMMA + super.getMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* about the error and why it occurred. In particular, the errorType field can be used to determine if the caller's
* request was invalid, or the service encountered an error on the server side while processing it.
*/
public class YopServiceException extends YopClientException {
public class YopServiceException extends YopClientException implements YopTracedException {
private static final long serialVersionUID = 1483785729559154396L;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright: Copyright (c)2011
* Company: 易宝支付(YeePay)
*/

package com.yeepay.yop.sdk.exception;

/**
* title: <br>
* description: 描述<br>
* Copyright: Copyright (c)2014<br>
* Company: 易宝支付(YeePay)<br>
*
* @author wdc
* @version 1.0.0
* @since 2025/2/24
*/
public interface YopTracedException {

/**
* 获取错误码
*
* @return String
*/
String getErrorCode();

/**
* 获取请求标识
*
* @return String
*/
String getRequestId();


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
package com.yeepay.yop.sdk.exception;

import static com.yeepay.yop.sdk.constants.CharacterConstants.COMMA;
import static com.yeepay.yop.sdk.constants.ExceptionConstants.SDK_INVOKE_UNEXPECTED_EXCEPTION;

/**
* title: Yop未知异常<br>
* description: 该异常不会重试<br>
Expand All @@ -14,14 +17,36 @@
* @version 1.0.0
* @since 2023/3/27
*/
public class YopUnknownException extends RuntimeException {
public class YopUnknownException extends RuntimeException implements YopTracedException {
private static final long serialVersionUID = -1L;

private String requestId;

public YopUnknownException(String message) {
super(message);
}

public YopUnknownException(String message, Throwable cause) {
super(message, cause);
}

public YopUnknownException(String message, Throwable cause, String requestId) {
super(message, cause);
this.requestId = requestId;
}

@Override
public String getErrorCode() {
return SDK_INVOKE_UNEXPECTED_EXCEPTION;
}

@Override
public String getRequestId() {
return this.requestId;
}

@Override
public String getMessage() {
return getErrorCode() + COMMA + getRequestId() + COMMA + super.getMessage();
}
}
Loading