Skip to content

Commit e934d25

Browse files
committed
Add WebSocket Compression Support
OCPP 2.0.1 requires CSMS and Local Controllers to support RFC 7692 WebSocket compression, and recommends it for Charging Stations using mobile data connections. This feature was not implemented yet. Add the WEBSOCKET_COMPRESSION_SUPPORT boolean to JSONConfiguration, enabled by default for the server and disabled by default for the client. Bump the WebSocket library dependency from version 1.5.3 to 1.6.0, since the PerMessageDeflateExtension was broken in older versions.
1 parent 32903d4 commit e934d25

13 files changed

Lines changed: 37 additions & 13 deletions

File tree

OCPP-J/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
dependencies {
66
compile project(':common')
77
compile 'com.google.code.gson:gson:2.8.9'
8-
compile 'org.java-websocket:Java-WebSocket:1.5.3'
8+
compile 'org.java-websocket:Java-WebSocket:1.6.0'
99
testCompile 'junit:junit:4.13.2'
1010
testCompile 'org.mockito:mockito-core:4.11.0'
1111
testCompile 'org.hamcrest:hamcrest-core:1.3'

OCPP-J/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>org.java-websocket</groupId>
6363
<artifactId>Java-WebSocket</artifactId>
64-
<version>1.5.4</version>
64+
<version>1.6.0</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>junit</groupId>

OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class JSONConfiguration {
3838
public static final String PASSWORD_PARAMETER = "PASSWORD";
3939
public static final String CONNECT_NON_BLOCKING_PARAMETER = "CONNECT_NON_BLOCKING";
4040
public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";
41+
public static final String WEBSOCKET_COMPRESSION_SUPPORT = "WEBSOCKET_COMPRESSION_SUPPORT";
4142
public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT";
4243
public static final String HTTP_HEALTH_CHECK_ENABLED = "HTTP_HEALTH_CHECK_ENABLED";
4344
public static final String OCPPJ_CP_MIN_PASSWORD_LENGTH = "OCPPJ_CP_MIN_PASSWORD_LENGTH";

ocpp-v1_6-example/json-client-implementation/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.java-websocket</groupId>
3838
<artifactId>Java-WebSocket</artifactId>
39-
<version>1.5.3</version>
39+
<version>1.6.0</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.google.code.gson</groupId>

ocpp-v1_6-example/json_server_example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.java-websocket</groupId>
3838
<artifactId>Java-WebSocket</artifactId>
39-
<version>1.5.3</version>
39+
<version>1.6.0</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.google.code.gson</groupId>

ocpp-v1_6/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
dependencies {
66
compile project(':common')
77
compile project(':OCPP-J')
8-
compile 'org.java-websocket:Java-WebSocket:1.5.3'
8+
compile 'org.java-websocket:Java-WebSocket:1.6.0'
99
compile group: 'javax.xml.soap', name: 'javax.xml.soap-api', version: '1.4.0'
1010

1111
testCompile 'junit:junit:4.13.2'

ocpp-v1_6/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<dependency>
6161
<groupId>org.java-websocket</groupId>
6262
<artifactId>Java-WebSocket</artifactId>
63-
<version>1.5.4</version>
63+
<version>1.6.0</version>
6464
</dependency>
6565
<dependency>
6666
<groupId>junit</groupId>

ocpp-v2/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies {
77
compile project(':OCPP-J')
88
compile project(':v1_6')
99
compile 'com.google.code.findbugs:jsr305:3.0.1'
10-
compile 'org.java-websocket:Java-WebSocket:1.5.3'
10+
compile 'org.java-websocket:Java-WebSocket:1.6.0'
1111
testCompile 'junit:junit:4.13.2'
1212
testCompile 'org.mockito:mockito-core:4.11.0'
1313
testCompile 'org.hamcrest:hamcrest-core:1.3'

ocpp-v2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>org.java-websocket</groupId>
7272
<artifactId>Java-WebSocket</artifactId>
73-
<version>1.5.4</version>
73+
<version>1.6.0</version>
7474
</dependency>
7575
<dependency>
7676
<groupId>junit</groupId>

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONClient.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@
3535
import eu.chargetime.ocpp.wss.WssSocketBuilder;
3636
import java.io.IOException;
3737
import java.util.ArrayList;
38-
import java.util.Collections;
3938
import java.util.List;
4039
import java.util.UUID;
4140
import java.util.concurrent.CompletionStage;
41+
import java.util.zip.Deflater;
4242
import javax.annotation.Nullable;
4343
import javax.net.ssl.SSLContext;
4444
import org.java_websocket.drafts.Draft;
4545
import org.java_websocket.drafts.Draft_6455;
46+
import org.java_websocket.extensions.IExtension;
47+
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
4648
import org.java_websocket.protocols.IProtocol;
4749
import org.java_websocket.protocols.Protocol;
4850
import org.slf4j.Logger;
@@ -88,11 +90,20 @@ public MultiProtocolJSONClient(
8890
List<ProtocolVersion> protocolVersions, String identity, JSONConfiguration configuration) {
8991
this.identity = identity;
9092
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+
}
91102
List<IProtocol> inputProtocols = new ArrayList<>(protocolVersions.size());
92103
for (ProtocolVersion protocolVersion : protocolVersions) {
93104
inputProtocols.add(new Protocol(protocolVersion.getSubProtocolName()));
94105
}
95-
Draft draft = new Draft_6455(Collections.emptyList(), inputProtocols);
106+
Draft draft = new Draft_6455(inputExtensions, inputProtocols);
96107
transmitter = new MultiProtocolWebSocketTransmitter(featureRepository, configuration, draft);
97108
JSONCommunicator communicator = new JSONCommunicator(transmitter, false);
98109
ISessionFactory sessionFactory = new MultiProtocolSessionFactory(featureRepository);

0 commit comments

Comments
 (0)