Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化TripLinkHttpClient,增加超时时间 #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ public class TripLinkHttpClient implements HttpClient<CallHttpResponse> {

private static final String CONTENT_TYPE_JSON_CONTENT = "application/json";

private static Integer CONNECT_TIMEOUT = null;
private static Integer READ_TIMEOUT = null;

/**
* des:
* @param connectTimeout 毫秒
* @param readTimeout 毫秒
* date 2025/1/3 13:54
*/
public TripLinkHttpClient(Integer connectTimeout,Integer readTimeout) {
if(connectTimeout != null){
CONNECT_TIMEOUT = connectTimeout;
}
if(readTimeout != null){
READ_TIMEOUT = readTimeout;
}

}
public TripLinkHttpClient() {

}

public CallHttpResponse post(String requestJson, String url, Map<String,String> header) {
try {
if(null == header){
Expand Down Expand Up @@ -85,6 +107,11 @@ private static CallHttpResponse httpsRequest(String requestUrl,String httpMethod
conn.setUseCaches(false);
conn.setRequestMethod(httpMethod);
conn.setSSLSocketFactory(ssf);
if (null != CONNECT_TIMEOUT)
conn.setConnectTimeout(CONNECT_TIMEOUT);
if(null != READ_TIMEOUT)
conn.setReadTimeout(READ_TIMEOUT);

//设置 header
if(null != header){
for(Map.Entry<String,String> entry : header.entrySet()){
Expand Down