Skip to content

Commit

Permalink
Merge pull request #138 from zzq996/master
Browse files Browse the repository at this point in the history
Version 3.23.9.1
New features:

Allow you set custom dns resolver
Third-party dependence:

Remove java-xmlbuilder, use default javax.xml lib
  • Loading branch information
zzq996 authored Oct 29, 2023
2 parents 247ddfd + 8f7159e commit 7c6feb2
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 334 deletions.
7 changes: 7 additions & 0 deletions README-Android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 3.23.9.1
New features:
1. Allow you set custom dns resolver

Third-party dependence:
1. Remove java-xmlbuilder, use default javax.xml lib
-----------------------------------------------------------------------------------
Version 3.23.9
New features:
1. Allow you set\get\list\delete bucket inventory configuration
Expand Down
7 changes: 7 additions & 0 deletions README-Java.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 3.23.9.1
New features:
1. Allow you set custom dns resolver

Third-party dependence:
1. Remove java-xmlbuilder, use default javax.xml lib
-----------------------------------------------------------------------------------
Version 3.23.9
New features:
1. Allow you set\get\list\delete bucket inventory configuration
Expand Down
7 changes: 7 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 3.23.9.1
New features:
1. Allow you set custom dns resolver

Third-party dependence:
1. Remove java-xmlbuilder, use default javax.xml lib
-----------------------------------------------------------------------------------
Version 3.23.9
New features:
1. Allow you set\get\list\delete bucket inventory configuration
Expand Down
7 changes: 7 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 3.23.9.1
New features:
1. 支持设置自定义dns解析器

Third-party dependence:
1. 移除 java-xmlbuilder, 使用默认的javax.xml库
-----------------------------------------------------------------------------------
Version 3.23.9
New features:
1. 新增配置桶清单接口
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/com/obs/services/AbstractClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@
import com.obs.services.model.V4PostSignatureResponse;
import com.obs.services.model.V4TemporarySignatureRequest;
import com.obs.services.model.V4TemporarySignatureResponse;
import static com.jamesmurty.utils.BaseXMLBuilder.failIfExternalEntityParsingCannotBeConfigured;

public abstract class AbstractClient extends ObsService implements Closeable, IObsClient, IFSClient {
private static final ILogger ILOG = LoggerBuilder.getLogger(AbstractClient.class);

static {
failIfExternalEntityParsingCannotBeConfigured = false;
}

protected void init(String accessKey, String secretKey, String securityToken, ObsConfiguration config) {
InterfaceLogBean reqBean = new InterfaceLogBean("ObsClient", config.getEndPoint(), "");
Expand All @@ -73,7 +68,7 @@ protected void init(String accessKey, String secretKey, String securityToken, Ob
if (this.isAuthTypeNegotiation()) {
this.getProviderCredentials().setIsAuthTypeNegotiation(true);
}
this.initHttpClient(config.getHttpDispatcher());
this.initHttpClient(config.getHttpDispatcher(), config.getCustomizedDnsImpl());
OBSXMLBuilder.setXmlDocumentBuilderFactoryClass(config.getXmlDocumentBuilderFactoryClass());
reqBean.setRespTime(new Date());
reqBean.setResultCode(Constants.RESULTCODE_SUCCESS);
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/obs/services/ObsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.obs.services.model.HttpProtocolTypeEnum;

import okhttp3.Dispatcher;
import okhttp3.Dns;

import java.security.SecureRandom;

Expand Down Expand Up @@ -96,6 +97,8 @@ public class ObsConfiguration implements Cloneable {
private HttpProtocolTypeEnum httpProtocolType;

private Dispatcher httpDispatcher;

private Dns customizedDnsImpl;

private String xmlDocumentBuilderFactoryClass;

Expand Down Expand Up @@ -878,6 +881,26 @@ public void setHttpDispatcher(Dispatcher httpDispatcher) {
this.httpDispatcher = httpDispatcher;
}


/**
* Obtain the customized Dns.
*
* @return customizedDnsImpl
*
*/
public Dns getCustomizedDnsImpl() {
return customizedDnsImpl;
}

/**
* set the customized Dns.
*
* @param customizedDnsImpl
* Customized Dns
*/
public void setCustomizedDnsImpl(Dns customizedDnsImpl) {
this.customizedDnsImpl = customizedDnsImpl;
}
public String getXmlDocumentBuilderFactoryClass() {
return xmlDocumentBuilderFactoryClass;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/obs/services/internal/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static class ObsRequestParams {

public static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");

public static final String OBS_SDK_VERSION = "3.23.9";
public static final String OBS_SDK_VERSION = "3.23.9.1";

public static final String USER_AGENT_VALUE = "obs-sdk-java/" + Constants.OBS_SDK_VERSION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.obs.services.internal.utils.ServiceUtils;
import com.obs.services.model.HttpMethodEnum;
import okhttp3.Dispatcher;
import okhttp3.Dns;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
Expand All @@ -55,10 +56,10 @@ public class RestConnectionService {

protected volatile ProviderCredentials credentials;

protected void initHttpClient(Dispatcher httpDispatcher) {
protected void initHttpClient(Dispatcher httpDispatcher, Dns customizedDnsImpl) {

OkHttpClient.Builder builder = RestUtils.initHttpClientBuilder(obsProperties, keyManagerFactory,
trustManagerFactory, httpDispatcher, credentials.getSecureRandom());
trustManagerFactory, httpDispatcher, customizedDnsImpl, credentials.getSecureRandom());

if (this.obsProperties.getBoolProperty(ObsConstraint.PROXY_ISABLE, true)) {
String proxyHostAddress = this.obsProperties.getStringProperty(ObsConstraint.PROXY_HOST, null);
Expand Down
91 changes: 53 additions & 38 deletions app/src/main/java/com/obs/services/internal/utils/RestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@

package com.obs.services.internal.utils;

import com.obs.log.ILogger;
import com.obs.log.LoggerBuilder;
import com.obs.services.exception.ObsException;
import com.obs.services.internal.Constants;
import com.obs.services.internal.Constants.CommonHeaders;
import com.obs.services.internal.ObsConstraint;
import com.obs.services.internal.ObsProperties;
import com.obs.services.internal.ServiceException;
import com.obs.services.internal.ext.ExtObsConstraint;
import com.obs.services.model.HttpProtocolTypeEnum;
import okhttp3.Authenticator;
import okhttp3.ConnectionPool;
import okhttp3.Credentials;
import okhttp3.Dispatcher;
import okhttp3.Dns;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
import org.jetbrains.annotations.NotNull;

import javax.net.SocketFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
Expand All @@ -36,38 +67,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.net.SocketFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

import com.obs.log.ILogger;
import com.obs.log.LoggerBuilder;
import com.obs.services.exception.ObsException;
import com.obs.services.internal.Constants;
import com.obs.services.internal.Constants.CommonHeaders;
import com.obs.services.internal.ObsConstraint;
import com.obs.services.internal.ObsProperties;
import com.obs.services.internal.ServiceException;
import com.obs.services.internal.ext.ExtObsConstraint;
import com.obs.services.model.HttpProtocolTypeEnum;

import okhttp3.Authenticator;
import okhttp3.ConnectionPool;
import okhttp3.Credentials;
import okhttp3.Dispatcher;
import okhttp3.Dns;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;

public class RestUtils {

private static final ILogger log = LoggerBuilder.getLogger(RestUtils.class);
Expand Down Expand Up @@ -330,7 +329,7 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre

public static OkHttpClient.Builder initHttpClientBuilder(ObsProperties obsProperties,
KeyManagerFactory keyManagerFactory, TrustManagerFactory trustManagerFactory,
Dispatcher httpDispatcher, SecureRandom secureRandom) {
Dispatcher httpDispatcher, Dns customizedDnsImpl, SecureRandom secureRandom) {

List<Protocol> protocols = new ArrayList<Protocol>(2);
protocols.add(Protocol.HTTP_1_1);
Expand All @@ -351,6 +350,8 @@ public static OkHttpClient.Builder initHttpClientBuilder(ObsProperties obsProper
ObsConstraint.DEFAULT_IDLE_CONNECTION_TIME),
TimeUnit.MILLISECONDS);

Dns dns = customizedDnsImpl == null ? new DefaultObsDns() : customizedDnsImpl;

builder.protocols(protocols).followRedirects(false).followSslRedirects(false)
.retryOnConnectionFailure(
obsProperties.getBoolProperty(ExtObsConstraint.IS_RETRY_ON_CONNECTION_FAILURE_IN_OKHTTP, false))
Expand All @@ -364,11 +365,7 @@ public static OkHttpClient.Builder initHttpClientBuilder(ObsProperties obsProper
.connectionPool(pool)
.hostnameVerifier((hostname, session) -> !obsProperties.getBoolProperty(ObsConstraint.HTTP_STRICT_HOSTNAME_VERIFICATION, false)
|| HttpsURLConnection.getDefaultHostnameVerifier().verify(obsProperties.getStringProperty(ObsConstraint.END_POINT, ""), session))
.dns(hostname -> {
List<InetAddress> adds = Dns.SYSTEM.lookup(hostname);
log.info("internet host address:" + adds);
return adds;
});
.dns(dns);

int socketReadBufferSize = obsProperties.getIntProperty(ObsConstraint.SOCKET_READ_BUFFER_SIZE, -1);
int socketWriteBufferSize = obsProperties.getIntProperty(ObsConstraint.SOCKET_WRITE_BUFFER_SIZE, -1);
Expand Down Expand Up @@ -479,4 +476,22 @@ public static String readBodyFromResponse(Response response) {
}
return body;
}
public static class DefaultObsDns implements Dns {
public DefaultObsDns() {
log.info("use Default Dns");
}

/**
* @param hostname
* @return
* @throws UnknownHostException
*/
@NotNull
@Override
public List<InetAddress> lookup(@NotNull String hostname) throws UnknownHostException {
List<InetAddress> adds = Dns.SYSTEM.lookup(hostname);
log.info("internet host address:" + adds);
return adds;
}
}
}
Loading

0 comments on commit 7c6feb2

Please sign in to comment.