Skip to content

Commit 0d697d4

Browse files
committed
merge developga2.4
1 parent ba7b48c commit 0d697d4

24 files changed

Lines changed: 518 additions & 429 deletions

enos-http-sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>enos-http</artifactId>
13-
<version>0.2.1</version>
13+
<version>2.4.0</version>
1414

1515
<packaging>jar</packaging>
1616

enos-http-sdk/src/main/java/com/envisioniot/enos/iot_http_sdk/file/FileFormData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static Part createFormData(@NonNull UploadFileInfo fileInfo) throws IOExc
7070
.addUnsafeNonAscii("Content-MD5", md5(fileInfo.getFile()))
7171
.build();
7272

73-
return Part.create(headers,
73+
return MultipartBody.Part.create(headers,
7474
RequestBody.create(MediaType.parse(HttpConnection.MEDIA_TYPE_OCTET_STREAM), fileInfo.getFile()));
7575
}
7676
}

enos-http-sdk/src/main/java/com/envisioniot/enos/iot_http_sdk/ssl/EccSSLSocketFactory.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,33 @@
1616
* @date 2020/2/11 9:28
1717
*/
1818
public class EccSSLSocketFactory extends SSLSocketFactory {
19+
private static final String[] ECC_CIPHER_SUITES = new String[]{
20+
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
21+
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
22+
};
23+
private static final String[] RSA_CIPHER_SUITES = new String[]{
24+
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
25+
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
26+
"TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
27+
"TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
28+
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
29+
"TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
30+
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
31+
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256"
32+
};
33+
34+
private final String[] cipherSuites;
35+
1936
private SSLSocketFactory factory;
2037

21-
EccSSLSocketFactory(SSLSocketFactory factory) {
38+
private Boolean isEccConnect;
39+
40+
EccSSLSocketFactory(SSLSocketFactory factory, Boolean isEccConnect) {
2241
this.factory = factory;
42+
this.isEccConnect = isEccConnect;
43+
this.cipherSuites = Boolean.TRUE.equals(isEccConnect)
44+
? ECC_CIPHER_SUITES :
45+
RSA_CIPHER_SUITES;
2346
}
2447

2548
@Override
@@ -29,12 +52,12 @@ public Socket createSocket() throws IOException {
2952

3053
@Override
3154
public String[] getDefaultCipherSuites() {
32-
return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"};
55+
return cipherSuites;
3356
}
3457

3558
@Override
3659
public String[] getSupportedCipherSuites() {
37-
return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"};
60+
return cipherSuites;
3861
}
3962

4063
@Override
@@ -44,7 +67,11 @@ public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOE
4467

4568
private Socket encapsulated(Socket socket) {
4669
if (socket instanceof SSLSocket) {
47-
((SSLSocket) socket).setEnabledCipherSuites(getDefaultCipherSuites());
70+
if (isEccConnect) {
71+
((SSLSocket) socket).setEnabledCipherSuites(ECC_CIPHER_SUITES);
72+
} else {
73+
((SSLSocket) socket).setEnabledCipherSuites(RSA_CIPHER_SUITES);
74+
}
4875
}
4976
return socket;
5077
}

enos-http-sdk/src/main/java/com/envisioniot/enos/iot_http_sdk/ssl/OkHttpUtil.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,25 @@ private static OkHttpClient buildOkHttpsClient(boolean isEccConnect, String jksP
7474
X509TrustManager trustManagerVerifyCa = (X509TrustManager) trustManagers[0];
7575
// TSL or SSL
7676
SSLContext sslContext = SSLContext.getInstance("TLS");
77-
sslContext.init(keyManagers, trustManagers, new SecureRandom());
77+
78+
TrustManager[] trustAllCerts = new TrustManager[] {
79+
new X509TrustManager() {
80+
@Override
81+
public void checkClientTrusted(X509Certificate[] x509Certificates,
82+
String s) throws CertificateException {}
83+
@Override
84+
public void checkServerTrusted(X509Certificate[] x509Certificates,
85+
String s) throws CertificateException {}
86+
@Override
87+
public X509Certificate[] getAcceptedIssuers() {
88+
return new X509Certificate[0];
89+
}
90+
}
91+
};
92+
sslContext.init(keyManagers, trustAllCerts, new SecureRandom());
7893
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
7994

80-
if (isEccConnect) {
81-
sslSocketFactory = new EccSSLSocketFactory(sslSocketFactory);
82-
}
95+
sslSocketFactory = new EccSSLSocketFactory(sslSocketFactory, isEccConnect);
8396

8497
// check cert
8598
okHttpBuilder.sslSocketFactory(sslSocketFactory, trustManagerVerifyCa);
Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
1-
package com.envisioniot.enos.iot_mqtt_sdk.core;
2-
3-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
4-
5-
import java.util.concurrent.*;
6-
7-
/**
8-
* Factory that provides thread pools for handling connect, publish, time-out scheduler,
9-
* async callback. Note that this factory is per MqttClient. <br/>
10-
* <br/>
11-
* User can customize the relevant thread pool through the provided <b>set</b> method.
12-
*
13-
* @author zhensheng.cai
14-
* @author jian.zhang4
15-
*/
16-
public class ExecutorFactory implements IExecutorFactory {
17-
18-
/**
19-
* Thread pools that handles mqtt publish action in async way.
20-
*/
21-
private ExecutorService publishExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
22-
new LinkedBlockingQueue<>(1000), new ThreadFactoryBuilder().setNameFormat("publish-executor-%d").build());
23-
24-
/**
25-
* We should only have one connect action per MqttClient at the same time. So one
26-
* thread should be good enough to handle async connection.
27-
*/
28-
private ExecutorService connectExecutor = Executors.newSingleThreadExecutor(
29-
new ThreadFactoryBuilder().setNameFormat("connect-executor-%d").build());
30-
31-
/**
32-
* callback timeout pool
33-
*/
34-
private ScheduledExecutorService timeoutScheduler = new ScheduledThreadPoolExecutor(3,
35-
new ThreadFactoryBuilder().setNameFormat("timeout-pool-%d").build());
36-
37-
/**
38-
* Thread pools that execute async callback provided by user
39-
*/
40-
private ExecutorService callbackExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
41-
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("callback-executor-%d").build());
42-
43-
44-
/**
45-
* shutdown all thread pools managed by this factory
46-
*/
47-
public void shutdownExecutorServices() {
48-
publishExecutor.shutdownNow();
49-
connectExecutor.shutdownNow();
50-
timeoutScheduler.shutdownNow();
51-
callbackExecutor.shutdownNow();
52-
}
53-
54-
public ExecutorService getPublishExecutor() {
55-
return publishExecutor;
56-
}
57-
58-
public void setPublishExecutor(ExecutorService publishExecutor) {
59-
this.publishExecutor = publishExecutor;
60-
}
61-
62-
public ExecutorService getConnectExecutor() {
63-
return connectExecutor;
64-
}
65-
66-
public void setConnectExecutor(ExecutorService connectExecutor) {
67-
this.connectExecutor = connectExecutor;
68-
}
69-
70-
public ScheduledExecutorService getTimeoutScheduler() {
71-
return timeoutScheduler;
72-
}
73-
74-
public void setTimeoutScheduler(ScheduledExecutorService timeoutScheduler) {
75-
this.timeoutScheduler = timeoutScheduler;
76-
}
77-
78-
public ExecutorService getCallbackExecutor() {
79-
return callbackExecutor;
80-
}
81-
82-
public void setCallbackExecutor(ExecutorService callbackExecutor) {
83-
this.callbackExecutor = callbackExecutor;
84-
}
85-
}
1+
package com.envisioniot.enos.iot_mqtt_sdk.core;
2+
3+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
4+
5+
import java.util.concurrent.*;
6+
7+
/**
8+
* Factory that provides thread pools for handling connect, publish, time-out scheduler,
9+
* async callback. Note that this factory is per MqttClient. <br/>
10+
* <br/>
11+
* User can customize the relevant thread pool through the provided <b>set</b> method.
12+
*
13+
* @author zhensheng.cai
14+
* @author jian.zhang4
15+
*/
16+
public class ExecutorFactory implements IExecutorFactory {
17+
18+
/**
19+
* Thread pools that handles mqtt publish action in async way.
20+
*/
21+
private ExecutorService publishExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
22+
new LinkedBlockingQueue<>(1000), new ThreadFactoryBuilder().setNameFormat("publish-executor-%d").build());
23+
24+
/**
25+
* We should only have one connect action per MqttClient at the same time. So one
26+
* thread should be good enough to handle async connection.
27+
*/
28+
private ExecutorService connectExecutor = Executors.newSingleThreadExecutor(
29+
new ThreadFactoryBuilder().setNameFormat("connect-executor-%d").build());
30+
31+
/**
32+
* callback timeout pool
33+
*/
34+
private ScheduledExecutorService timeoutScheduler = new ScheduledThreadPoolExecutor(3,
35+
new ThreadFactoryBuilder().setNameFormat("timeout-pool-%d").build());
36+
37+
/**
38+
* Thread pools that execute async callback provided by user
39+
*/
40+
private ExecutorService callbackExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
41+
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("callback-executor-%d").build());
42+
43+
44+
/**
45+
* shutdown all thread pools managed by this factory
46+
*/
47+
public void shutdownExecutorServices() {
48+
publishExecutor.shutdownNow();
49+
connectExecutor.shutdownNow();
50+
timeoutScheduler.shutdownNow();
51+
callbackExecutor.shutdownNow();
52+
}
53+
54+
public ExecutorService getPublishExecutor() {
55+
return publishExecutor;
56+
}
57+
58+
public void setPublishExecutor(ExecutorService publishExecutor) {
59+
this.publishExecutor = publishExecutor;
60+
}
61+
62+
public ExecutorService getConnectExecutor() {
63+
return connectExecutor;
64+
}
65+
66+
public void setConnectExecutor(ExecutorService connectExecutor) {
67+
this.connectExecutor = connectExecutor;
68+
}
69+
70+
public ScheduledExecutorService getTimeoutScheduler() {
71+
return timeoutScheduler;
72+
}
73+
74+
public void setTimeoutScheduler(ScheduledExecutorService timeoutScheduler) {
75+
this.timeoutScheduler = timeoutScheduler;
76+
}
77+
78+
public ExecutorService getCallbackExecutor() {
79+
return callbackExecutor;
80+
}
81+
82+
public void setCallbackExecutor(ExecutorService callbackExecutor) {
83+
this.callbackExecutor = callbackExecutor;
84+
}
85+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package com.envisioniot.enos.iot_mqtt_sdk.core;
2-
3-
import java.util.concurrent.ExecutorService;
4-
import java.util.concurrent.ScheduledExecutorService;
5-
6-
public interface IExecutorFactory {
7-
8-
void shutdownExecutorServices();
9-
10-
ExecutorService getPublishExecutor();
11-
12-
ExecutorService getConnectExecutor();
13-
14-
ScheduledExecutorService getTimeoutScheduler();
15-
16-
ExecutorService getCallbackExecutor();
17-
}
1+
package com.envisioniot.enos.iot_mqtt_sdk.core;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.ScheduledExecutorService;
5+
6+
public interface IExecutorFactory {
7+
8+
void shutdownExecutorServices();
9+
10+
ExecutorService getPublishExecutor();
11+
12+
ExecutorService getConnectExecutor();
13+
14+
ScheduledExecutorService getTimeoutScheduler();
15+
16+
ExecutorService getCallbackExecutor();
17+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.envisioniot.enos.iot_mqtt_sdk.core;
2-
3-
import java.lang.annotation.*;
4-
5-
@Inherited
6-
@Documented
7-
@Target({ElementType.TYPE})
8-
@Retention(RetentionPolicy.RUNTIME)
9-
public @interface Sharable {
10-
11-
}
1+
package com.envisioniot.enos.iot_mqtt_sdk.core;
2+
3+
import java.lang.annotation.*;
4+
5+
@Inherited
6+
@Documented
7+
@Target({ElementType.TYPE})
8+
@Retention(RetentionPolicy.RUNTIME)
9+
public @interface Sharable {
10+
11+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
package com.envisioniot.enos.iot_mqtt_sdk.core.internals;
2-
3-
import com.envisioniot.enos.iot_mqtt_sdk.util.StringUtil;
4-
5-
public class Utils {
6-
7-
static String getRootMessage(Throwable error) {
8-
if (error == null) {
9-
return "";
10-
}
11-
12-
if (error.getCause() == null) {
13-
return StringUtil.isNotEmpty(error.getMessage()) ? error.getMessage() : error.getClass().getName();
14-
}
15-
16-
return getRootMessage(error.getCause());
17-
}
18-
19-
20-
}
1+
package com.envisioniot.enos.iot_mqtt_sdk.core.internals;
2+
3+
import com.envisioniot.enos.iot_mqtt_sdk.util.StringUtil;
4+
5+
public class Utils {
6+
7+
static String getRootMessage(Throwable error) {
8+
if (error == null) {
9+
return "";
10+
}
11+
12+
if (error.getCause() == null) {
13+
return StringUtil.isNotEmpty(error.getMessage()) ? error.getMessage() : error.getClass().getName();
14+
}
15+
16+
return getRootMessage(error.getCause());
17+
}
18+
19+
20+
}

enos-sdk-sample/src/main/java/http/DownloadFeatureFileSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void main(String[] args) throws EnvisionException {
5858
connection.downloadFileAsync(fileUri, FileCategory.FEATURE, new IFileCallback() {
5959
@Override
6060
public void onResponse(InputStream inputStream) throws IOException {
61-
System.out.println("download feature ile asynchronously");
61+
System.out.println("download feature file asynchronously");
6262
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
6363
byte[] buffer = new byte[bufferLength];
6464
int len;

0 commit comments

Comments
 (0)