|
35 | 35 | import eu.chargetime.ocpp.wss.WssSocketBuilder; |
36 | 36 | import java.io.IOException; |
37 | 37 | import java.util.ArrayList; |
38 | | -import java.util.Collections; |
39 | 38 | import java.util.List; |
40 | 39 | import java.util.UUID; |
41 | 40 | import java.util.concurrent.CompletionStage; |
| 41 | +import java.util.zip.Deflater; |
42 | 42 | import javax.annotation.Nullable; |
43 | 43 | import javax.net.ssl.SSLContext; |
44 | 44 | import org.java_websocket.drafts.Draft; |
45 | 45 | import org.java_websocket.drafts.Draft_6455; |
| 46 | +import org.java_websocket.extensions.IExtension; |
| 47 | +import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension; |
46 | 48 | import org.java_websocket.protocols.IProtocol; |
47 | 49 | import org.java_websocket.protocols.Protocol; |
48 | 50 | import org.slf4j.Logger; |
@@ -88,11 +90,20 @@ public MultiProtocolJSONClient( |
88 | 90 | List<ProtocolVersion> protocolVersions, String identity, JSONConfiguration configuration) { |
89 | 91 | this.identity = identity; |
90 | 92 | featureRepository = new MultiProtocolFeatureRepository(protocolVersions); |
| 93 | + List<IExtension> inputExtensions = new ArrayList<>(); |
| 94 | + if (configuration.getParameter(JSONConfiguration.WEBSOCKET_COMPRESSION_SUPPORT, false)) { |
| 95 | + PerMessageDeflateExtension perMessageDeflateExtension = |
| 96 | + new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION); |
| 97 | + perMessageDeflateExtension.setThreshold(0); |
| 98 | + perMessageDeflateExtension.setServerNoContextTakeover(false); |
| 99 | + perMessageDeflateExtension.setClientNoContextTakeover(false); |
| 100 | + inputExtensions.add(perMessageDeflateExtension); |
| 101 | + } |
91 | 102 | List<IProtocol> inputProtocols = new ArrayList<>(protocolVersions.size()); |
92 | 103 | for (ProtocolVersion protocolVersion : protocolVersions) { |
93 | 104 | inputProtocols.add(new Protocol(protocolVersion.getSubProtocolName())); |
94 | 105 | } |
95 | | - Draft draft = new Draft_6455(Collections.emptyList(), inputProtocols); |
| 106 | + Draft draft = new Draft_6455(inputExtensions, inputProtocols); |
96 | 107 | transmitter = new MultiProtocolWebSocketTransmitter(featureRepository, configuration, draft); |
97 | 108 | JSONCommunicator communicator = new JSONCommunicator(transmitter, false); |
98 | 109 | ISessionFactory sessionFactory = new MultiProtocolSessionFactory(featureRepository); |
|
0 commit comments