Skip to content

Commit

Permalink
降低jdk需求至1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaoxiao-xxx committed Oct 19, 2017
1 parent 9f0703d commit 6b7cfd5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.xuxiaoxiao</groupId>
<artifactId>xtools-common</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<name>xtools-common</name>
<description>Java开发基础工具集,陆续收录常用的java代码,令代码更加简洁美观</description>
<url>https://github.com/xuxiaoxiao-xxx/XTools-Common</url>

<properties>
<java.version>1.8</java.version>
<java.version>1.7</java.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -51,8 +51,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -135,8 +135,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/me/xuxiaoxiao/xtools/XCodeTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public final class XCodeTools {
/**
* 散列算法-SHA1
*/
public static final String HASH_SHA1 = "SHA1";
public static final String HASH_SHA1 = "SHA-1";
/**
* 散列算法-SHA256
*/
public static final String HASH_SHA256 = "SHA-256";

private static final char HEX[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

Expand Down
51 changes: 30 additions & 21 deletions src/main/java/me/xuxiaoxiao/xtools/XHttpTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ private static HttpURLConnection connect(XOption option, String url) throws Exce
return (HttpURLConnection) new URL(url).openConnection();
} else if (url.toLowerCase().startsWith("https://")) {
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, option.trustManagers, new SecureRandom());
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.setSSLSocketFactory(option.sslContext.getSocketFactory());
connection.setHostnameVerifier(option.hostnameVerifier);
return connection;
} else {
Expand Down Expand Up @@ -130,9 +128,9 @@ public static class XOption {
*/
public final boolean followRedirect = followRedirect();
/**
* 证书管理器
* SSL上下文
*/
public final TrustManager[] trustManagers = trustManagers();
public final SSLContext sslContext = sslContext();
/**
* 主机名验证器
*/
Expand Down Expand Up @@ -168,29 +166,40 @@ public boolean followRedirect() {
}

/**
* 请求的证书管理器
* 获取SSL上下文
*
* @return 证书管理器
* @return 默认不进行证书验证
*/
public TrustManager[] trustManagers() {
return new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public SSLContext sslContext() {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}

@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}};
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}}, new SecureRandom());
return sslContext;
} catch (Exception e) {
return null;
}
}

public HostnameVerifier hostnameVerifier() {
return (s, sslSession) -> true;
return new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
};
}

/**
Expand Down

0 comments on commit 6b7cfd5

Please sign in to comment.