Commit b3dc441428205bc158b1d3e84d6803c078ee7356
1 parent
b2d694f7
Fix io.netty.handler.ssl.SslHandler is not a @Sharable handler
Showing
1 changed file
with
8 additions
and
13 deletions
... | ... | @@ -15,12 +15,10 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.transport.mqtt; |
17 | 17 | |
18 | -import com.google.common.io.Resources; | |
19 | 18 | import io.netty.handler.ssl.SslHandler; |
20 | 19 | import lombok.extern.slf4j.Slf4j; |
21 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 21 | import org.springframework.beans.factory.annotation.Value; |
23 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | |
24 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
25 | 23 | import org.springframework.stereotype.Component; |
26 | 24 | import org.springframework.util.StringUtils; |
... | ... | @@ -30,8 +28,8 @@ import org.thingsboard.server.common.msg.EncryptionUtil; |
30 | 28 | import org.thingsboard.server.common.transport.TransportService; |
31 | 29 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
32 | 30 | import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; |
33 | -import org.thingsboard.server.gen.transport.TransportProtos; | |
34 | 31 | import org.thingsboard.server.common.transport.util.SslUtil; |
32 | +import org.thingsboard.server.gen.transport.TransportProtos; | |
35 | 33 | |
36 | 34 | import javax.net.ssl.KeyManager; |
37 | 35 | import javax.net.ssl.KeyManagerFactory; |
... | ... | @@ -40,10 +38,7 @@ import javax.net.ssl.SSLEngine; |
40 | 38 | import javax.net.ssl.TrustManager; |
41 | 39 | import javax.net.ssl.TrustManagerFactory; |
42 | 40 | import javax.net.ssl.X509TrustManager; |
43 | -import java.io.File; | |
44 | -import java.io.FileInputStream; | |
45 | 41 | import java.io.InputStream; |
46 | -import java.net.URL; | |
47 | 42 | import java.security.KeyStore; |
48 | 43 | import java.security.cert.CertificateEncodingException; |
49 | 44 | import java.security.cert.CertificateException; |
... | ... | @@ -73,16 +68,16 @@ public class MqttSslHandlerProvider { |
73 | 68 | @Autowired |
74 | 69 | private TransportService transportService; |
75 | 70 | |
76 | - private SslHandler sslHandler; | |
71 | + private SSLEngine sslEngine; | |
77 | 72 | |
78 | 73 | public SslHandler getSslHandler() { |
79 | - if (sslHandler == null) { | |
80 | - sslHandler = createSslHandler(); | |
74 | + if (sslEngine == null) { | |
75 | + sslEngine = createSslEngine(); | |
81 | 76 | } |
82 | - return sslHandler; | |
77 | + return new SslHandler(sslEngine); | |
83 | 78 | } |
84 | 79 | |
85 | - private SslHandler createSslHandler() { | |
80 | + private SSLEngine createSslEngine() { | |
86 | 81 | try { |
87 | 82 | TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
88 | 83 | KeyStore trustStore = KeyStore.getInstance(keyStoreType); |
... | ... | @@ -113,10 +108,10 @@ public class MqttSslHandlerProvider { |
113 | 108 | sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); |
114 | 109 | sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); |
115 | 110 | sslEngine.setEnableSessionCreation(true); |
116 | - return new SslHandler(sslEngine); | |
111 | + return sslEngine; | |
117 | 112 | } catch (Exception e) { |
118 | 113 | log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e); |
119 | - throw new RuntimeException("Failed to get SSL handler", e); | |
114 | + throw new RuntimeException("Failed to get SSL engine", e); | |
120 | 115 | } |
121 | 116 | } |
122 | 117 | ... | ... |