Skip to content

Commit

Permalink
MqttWebSocketConfig.serverPath -> path
Browse files Browse the repository at this point in the history
MqttWebSocketConfig.queryString -> query
DEFAULT_MQTT_SUBPROTOCOL -> DEFAULT_SUBPROTOCOL
  • Loading branch information
SgtSilvio committed Jun 1, 2021
1 parent 01fddde commit 152a195
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,33 @@
public class MqttWebSocketConfigImpl implements MqttWebSocketConfig {

static final @NotNull MqttWebSocketConfigImpl DEFAULT =
new MqttWebSocketConfigImpl(DEFAULT_SERVER_PATH, DEFAULT_QUERY_STRING, DEFAULT_MQTT_SUBPROTOCOL,
DEFAULT_HANDSHAKE_TIMEOUT_MS);
new MqttWebSocketConfigImpl(DEFAULT_PATH, DEFAULT_QUERY, DEFAULT_SUBPROTOCOL, DEFAULT_HANDSHAKE_TIMEOUT_MS);

private final @NotNull String serverPath;
private final @NotNull String queryString;
private final @NotNull String path;
private final @NotNull String query;
private final @NotNull String subprotocol;
private final @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs;

MqttWebSocketConfigImpl(
final @NotNull String serverPath,
final @NotNull String queryString,
final @NotNull String path,
final @NotNull String query,
final @NotNull String subprotocol,
final @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs) {

this.serverPath = serverPath;
this.queryString = queryString;
this.path = path;
this.query = query;
this.subprotocol = subprotocol;
this.handshakeTimeoutMs = handshakeTimeoutMs;
}

@Override
public @NotNull String getServerPath() {
return serverPath;
public @NotNull String getPath() {
return path;
}

@Override
public @NotNull String getQueryString() {
return queryString;
public @NotNull String getQuery() {
return query;
}

@Override
Expand Down Expand Up @@ -85,14 +84,14 @@ public boolean equals(final @Nullable Object o) {
}
final MqttWebSocketConfigImpl that = (MqttWebSocketConfigImpl) o;

return serverPath.equals(that.serverPath) && queryString.equals(that.queryString) &&
subprotocol.equals(that.subprotocol) && (handshakeTimeoutMs == that.handshakeTimeoutMs);
return path.equals(that.path) && query.equals(that.query) && subprotocol.equals(that.subprotocol) &&
(handshakeTimeoutMs == that.handshakeTimeoutMs);
}

@Override
public int hashCode() {
int result = serverPath.hashCode();
result = 31 * result + queryString.hashCode();
int result = path.hashCode();
result = 31 * result + query.hashCode();
result = 31 * result + subprotocol.hashCode();
result = 31 * result + Integer.hashCode(handshakeTimeoutMs);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@
*/
public abstract class MqttWebSocketConfigImplBuilder<B extends MqttWebSocketConfigImplBuilder<B>> {

private @NotNull String serverPath = MqttWebSocketConfigImpl.DEFAULT_SERVER_PATH;
private @NotNull String queryString = MqttWebSocketConfigImpl.DEFAULT_QUERY_STRING;
private @NotNull String subprotocol = MqttWebSocketConfigImpl.DEFAULT_MQTT_SUBPROTOCOL;
private @NotNull String path = MqttWebSocketConfigImpl.DEFAULT_PATH;
private @NotNull String query = MqttWebSocketConfigImpl.DEFAULT_QUERY;
private @NotNull String subprotocol = MqttWebSocketConfigImpl.DEFAULT_SUBPROTOCOL;
private @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs =
MqttWebSocketConfigImpl.DEFAULT_HANDSHAKE_TIMEOUT_MS;

MqttWebSocketConfigImplBuilder() {}

MqttWebSocketConfigImplBuilder(final @Nullable MqttWebSocketConfigImpl webSocketConfig) {
if (webSocketConfig != null) {
serverPath = webSocketConfig.getServerPath();
queryString = webSocketConfig.getQueryString();
path = webSocketConfig.getPath();
query = webSocketConfig.getQuery();
subprotocol = webSocketConfig.getSubprotocol();
handshakeTimeoutMs = webSocketConfig.getHandshakeTimeoutMs();
}
}

abstract @NotNull B self();

public @NotNull B serverPath(final @Nullable String serverPath) {
public @NotNull B path(final @Nullable String path) {
// remove any leading slashes
this.serverPath = Checks.notNull(serverPath, "Server path").replaceAll("^/+", "");
this.path = Checks.notNull(path, "Server path").replaceAll("^/+", "");
return self();
}

public @NotNull B queryString(final @Nullable String queryString) {
this.queryString = Checks.notNull(queryString, "Query string");
public @NotNull B query(final @Nullable String query) {
this.query = Checks.notNull(query, "Query string");
return self();
}

Expand All @@ -73,7 +73,7 @@ public abstract class MqttWebSocketConfigImplBuilder<B extends MqttWebSocketConf
}

public @NotNull MqttWebSocketConfigImpl build() {
return new MqttWebSocketConfigImpl(serverPath, queryString, subprotocol, handshakeTimeoutMs);
return new MqttWebSocketConfigImpl(path, query, subprotocol, handshakeTimeoutMs);
}

public static class Default extends MqttWebSocketConfigImplBuilder<Default> implements MqttWebSocketConfigBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void initChannel(
final MqttTransportConfigImpl transportConfig = clientConfig.getCurrentTransportConfig();
final InetSocketAddress serverAddress = transportConfig.getServerAddress();
uri = new URI((transportConfig.getRawTlsConfig() == null) ? "ws" : "wss", null,
serverAddress.getHostString(), serverAddress.getPort(), "/" + webSocketConfig.getServerPath(),
webSocketConfig.getQueryString(), null);
serverAddress.getHostString(), serverAddress.getPort(), "/" + webSocketConfig.getPath(),
webSocketConfig.getQuery(), null);
} catch (final URISyntaxException e) {
onError.accept(channel, e);
return;
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/hivemq/client2/mqtt/MqttWebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
public interface MqttWebSocketConfig {

/**
* The default WebSocket server path.
* The default WebSocket path.
*/
@NotNull String DEFAULT_SERVER_PATH = "";
@NotNull String DEFAULT_PATH = "";
/**
* The default WebSocket query string.
* The default WebSocket query.
*/
@NotNull String DEFAULT_QUERY_STRING = "";
@NotNull String DEFAULT_QUERY = "";
/**
* The default WebSocket subprotocol.
* <p>
* See the <a href="https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name">WebSocket Subprotocol
* Name Registry</a>
*/
@NotNull String DEFAULT_MQTT_SUBPROTOCOL = "mqtt";
@NotNull String DEFAULT_SUBPROTOCOL = "mqtt";
/**
* The default websocket handshake timeout in milliseconds.
* The default WebSocket handshake timeout in milliseconds.
*
* @since 1.2
*/
Expand All @@ -63,22 +63,22 @@ public interface MqttWebSocketConfig {
}

/**
* @return the WebSocket server path.
* @return the WebSocket path.
*/
@NotNull String getServerPath();
@NotNull String getPath();

/**
* @return the WebSocket query string.
* @return the WebSocket query.
*/
@NotNull String getQueryString();
@NotNull String getQuery();

/**
* @return the WebSocket subprotocol.
*/
@NotNull String getSubprotocol();

/**
* @return the websocket handshake timeout in milliseconds.
* @return the WebSocket handshake timeout in milliseconds.
* @since 1.2
*/
@Range(from = 0, to = Integer.MAX_VALUE) int getHandshakeTimeoutMs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@
public interface MqttWebSocketConfigBuilderBase<B extends MqttWebSocketConfigBuilderBase<B>> {

/**
* Sets the {@link MqttWebSocketConfig#getServerPath() server path}.
* Sets the {@link MqttWebSocketConfig#getPath() path}.
*
* @param serverPath the server path.
* @param path the path.
* @return the builder.
*/
@CheckReturnValue
@NotNull B serverPath(@NotNull String serverPath);
@NotNull B path(@NotNull String path);

/**
* Sets the {@link MqttWebSocketConfig#getQueryString() query string}.
* Sets the {@link MqttWebSocketConfig#getQuery() query}.
*
* @param queryString the query string.
* @param query the query.
* @return the builder.
*/
@CheckReturnValue
@NotNull B queryString(@NotNull String queryString);
@NotNull B query(@NotNull String query);

/**
* Sets the {@link MqttWebSocketConfig#getSubprotocol() subprotocol}.
Expand All @@ -60,11 +60,11 @@ public interface MqttWebSocketConfigBuilderBase<B extends MqttWebSocketConfigBui
@NotNull B subprotocol(@NotNull String subprotocol);

/**
* Sets the {@link MqttWebSocketConfig#getHandshakeTimeoutMs() websocket handshake timeout}.
* Sets the {@link MqttWebSocketConfig#getHandshakeTimeoutMs() WebSocket handshake timeout}.
* <p>
* The timeout in milliseconds must be in the range: [0, {@link Integer#MAX_VALUE}].
*
* @param timeout the websocket handshake timeout or <code>0</code> to disable the timeout.
* @param timeout the WebSocket handshake timeout or <code>0</code> to disable the timeout.
* @param timeUnit the time unit of the given timeout (this timeout only supports millisecond precision).
* @return the builder.
* @since 1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private Mqtt3RxClient getClient() {
}

if (isNotUsingMqttPort(port)) {
mqttClientBuilder.webSocketConfig(MqttWebSocketConfig.builder().serverPath(serverPath).build());
mqttClientBuilder.webSocketConfig(MqttWebSocketConfig.builder().path(serverPath).build());
}

return mqttClientBuilder.useMqttVersion3().buildRx();
Expand Down

0 comments on commit 152a195

Please sign in to comment.