Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class JSONConfiguration {
public static final String CONNECT_NON_BLOCKING_PARAMETER = "CONNECT_NON_BLOCKING";
public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";
public static final String WEBSOCKET_COMPRESSION_SUPPORT = "WEBSOCKET_COMPRESSION_SUPPORT";
public static final String WEBSOCKET_MAX_FRAME_SIZE = "WEBSOCKET_MAX_FRAME_SIZE";
public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT";
public static final String HTTP_HEALTH_CHECK_ENABLED = "HTTP_HEALTH_CHECK_ENABLED";
public static final String OCPPJ_CP_MIN_PASSWORD_LENGTH = "OCPPJ_CP_MIN_PASSWORD_LENGTH";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.extensions.IExtension;
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
import org.java_websocket.protocols.IProtocol;
import org.java_websocket.protocols.Protocol;
import org.slf4j.Logger;
Expand Down Expand Up @@ -90,11 +89,14 @@ public MultiProtocolJSONClient(
List<ProtocolVersion> protocolVersions, String identity, JSONConfiguration configuration) {
this.identity = identity;
featureRepository = new MultiProtocolFeatureRepository(protocolVersions);
int maxFrameSize = configuration.getParameter(JSONConfiguration.WEBSOCKET_MAX_FRAME_SIZE, 0);
List<IExtension> inputExtensions = new ArrayList<>();
if (configuration.getParameter(JSONConfiguration.WEBSOCKET_COMPRESSION_SUPPORT, false)) {
PerMessageDeflateExtension perMessageDeflateExtension =
new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION);
perMessageDeflateExtension.setThreshold(0);
maxFrameSize > 0
? new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION, maxFrameSize)
: new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION);
perMessageDeflateExtension.setThreshold(64);
perMessageDeflateExtension.setServerNoContextTakeover(false);
perMessageDeflateExtension.setClientNoContextTakeover(false);
inputExtensions.add(perMessageDeflateExtension);
Expand All @@ -103,7 +105,10 @@ public MultiProtocolJSONClient(
for (ProtocolVersion protocolVersion : protocolVersions) {
inputProtocols.add(new Protocol(protocolVersion.getSubProtocolName()));
}
Draft draft = new Draft_6455(inputExtensions, inputProtocols);
Draft draft =
maxFrameSize > 0
? new Draft_6455(inputExtensions, inputProtocols, maxFrameSize)
: new Draft_6455(inputExtensions, inputProtocols);
transmitter = new MultiProtocolWebSocketTransmitter(featureRepository, configuration, draft);
JSONCommunicator communicator = new JSONCommunicator(transmitter, false);
ISessionFactory sessionFactory = new MultiProtocolSessionFactory(featureRepository);
Expand Down Expand Up @@ -217,6 +222,14 @@ public void disconnect() {
client.disconnect();
}

public double getCompressionRatio() {
IExtension extension = transmitter.getExtension();
if (extension instanceof PerMessageDeflateExtension) {
return ((PerMessageDeflateExtension) extension).getCompressionRatio();
}
return 1;
}

public Exception getLastError() {
return transmitter.getLastError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ of this software and associated documentation files (the "Software"), to deal
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.extensions.IExtension;
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
import org.java_websocket.protocols.IProtocol;
import org.java_websocket.protocols.Protocol;
import org.slf4j.Logger;
Expand All @@ -68,12 +67,14 @@ public MultiProtocolJSONServer(
List<ProtocolVersion> protocolVersions, JSONConfiguration configuration) {
featureRepository = new MultiProtocolFeatureRepository(protocolVersions);
MultiProtocolSessionFactory sessionFactory = new MultiProtocolSessionFactory(featureRepository);

int maxFrameSize = configuration.getParameter(JSONConfiguration.WEBSOCKET_MAX_FRAME_SIZE, 0);
List<IExtension> extensions = new ArrayList<>();
if (configuration.getParameter(JSONConfiguration.WEBSOCKET_COMPRESSION_SUPPORT, true)) {
PerMessageDeflateExtension perMessageDeflateExtension =
new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION);
perMessageDeflateExtension.setThreshold(0);
maxFrameSize > 0
? new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION, maxFrameSize)
: new PerMessageDeflateExtension(Deflater.BEST_COMPRESSION);
perMessageDeflateExtension.setThreshold(64);
perMessageDeflateExtension.setServerNoContextTakeover(false);
perMessageDeflateExtension.setClientNoContextTakeover(false);
extensions.add(perMessageDeflateExtension);
Expand All @@ -82,8 +83,10 @@ public MultiProtocolJSONServer(
for (ProtocolVersion protocolVersion : protocolVersions) {
protocols.add(new Protocol(protocolVersion.getSubProtocolName()));
}
Draft draft = new Draft_6455(extensions, protocols);

Draft draft =
maxFrameSize > 0
? new Draft_6455(extensions, protocols, maxFrameSize)
: new Draft_6455(extensions, protocols);
if (configuration.getParameter(JSONConfiguration.HTTP_HEALTH_CHECK_ENABLED, true)) {
logger.info("JSONServer with HttpHealthCheckDraft");
listener =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.HashMap;
import java.util.Map;
import javax.net.SocketFactory;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.exceptions.WebsocketNotConnectedException;
import org.java_websocket.extensions.IExtension;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -264,6 +267,20 @@ public void send(Object request) throws NotConnectedException {
}
}

public IExtension getExtension() {
WebSocketClient webSocketClient = client;
if (webSocketClient != null) {
WebSocket webSocket = webSocketClient.getConnection();
if (webSocket != null) {
Draft draft = webSocket.getDraft();
if (draft instanceof Draft_6455) {
return ((Draft_6455) draft).getExtension();
}
}
}
return null;
}

public Exception getLastError() {
return lastError;
}
Expand Down
Loading
Loading