Skip to content

Commit

Permalink
Extended websocket configuration in order to configure websocket path…
Browse files Browse the repository at this point in the history
… and max frame size; default values are still the same (#461)
  • Loading branch information
aemaem authored and andsel committed Apr 2, 2019
1 parent 0c1dd46 commit 1ee744f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions broker/src/main/java/io/moquette/BrokerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public final class BrokerConstants {
+ DEFAULT_MOQUETTE_STORE_H2_DB_FILENAME;
public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port";
public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port";
public static final String WEB_SOCKET_PATH_PROPERTY_NAME = "websocket_path";
public static final String WEB_SOCKET_MAX_FRAME_SIZE_PROPERTY_NAME = "websocket_max_frame_size";

/**
* Defines the SSL implementation to use, default to "JDK".
Expand All @@ -57,6 +59,7 @@ public final class BrokerConstants {
public static final String DB_AUTHENTICATOR_DIGEST = "authenticator.db.digest";
public static final int PORT = 1883;
public static final int WEBSOCKET_PORT = 8080;
public static final String WEBSOCKET_PATH = "/mqtt";
public static final String DISABLED_PORT_BIND = "disabled";
public static final String HOST = "0.0.0.0";
public static final String NEED_CLIENT_AUTH = "need_client_auth";
Expand Down
8 changes: 6 additions & 2 deletions broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ private void initializeWebSocketTransport(final NewNettyMQTTHandler handler, ICo
final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();

String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
String path = props.getProperty(BrokerConstants.WEB_SOCKET_PATH_PROPERTY_NAME, BrokerConstants.WEBSOCKET_PATH);
int maxFrameSize = props.intProp(BrokerConstants.WEB_SOCKET_MAX_FRAME_SIZE_PROPERTY_NAME, 65536);
initFactory(host, port, "Websocket MQTT", new PipelineInitializer() {

@Override
Expand All @@ -295,7 +297,7 @@ void init(SocketChannel channel) {
pipeline.addLast(new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("webSocketHandler",
new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
new WebSocketServerProtocolHandler(path, MQTT_SUBPROTOCOL_CSV_LIST, false, maxFrameSize));
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
configureMQTTPipeline(pipeline, timeoutHandler, handler);
Expand Down Expand Up @@ -343,6 +345,8 @@ private void initializeWSSTransport(NewNettyMQTTHandler handler, IConfig props,
int sslPort = Integer.parseInt(sslPortProp);
final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
String path = props.getProperty(BrokerConstants.WEB_SOCKET_PATH_PROPERTY_NAME, BrokerConstants.WEBSOCKET_PATH);
int maxFrameSize = props.intProp(BrokerConstants.WEB_SOCKET_MAX_FRAME_SIZE_PROPERTY_NAME, 65536);
String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
initFactory(host, sslPort, "Secure websocket", new PipelineInitializer() {
Expand All @@ -355,7 +359,7 @@ void init(SocketChannel channel) throws Exception {
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("webSocketHandler",
new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
new WebSocketServerProtocolHandler(path, MQTT_SUBPROTOCOL_CSV_LIST, false, maxFrameSize));
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void tearDown() throws Exception {
@Test
public void checkPlainConnect() throws Exception {
LOG.info("*** checkPlainConnect ***");
String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT + "/mqtt";
String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT + BrokerConstants.WEBSOCKET_PATH;

MQTTWebSocket socket = new MQTTWebSocket();
client.start();
Expand Down

0 comments on commit 1ee744f

Please sign in to comment.