diff --git a/CHANGELOG.md b/CHANGELOG.md index 64dabb43..ce2d15a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # pusher-websocket-java changelog +## Version 2.2.0 - 22nd April 2020 + +* Changed PusherOptions `setEncrypted` and `isEncrypted` to `setForceTLS` and `isForceTLS` to reduce confusion between this option and private encrypted channels. + ## Version 2.1.1 - 15th April 2020 * Fix a case where multiple websocket connections could be opened at once diff --git a/README.md b/README.md index 9c5a604f..b6ab37b8 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ The pusher-java-client is available in Maven Central. com.pusher pusher-java-client - 2.1.1 + 2.2.0 ``` @@ -70,7 +70,7 @@ The pusher-java-client is available in Maven Central. ```groovy dependencies { - compile 'com.pusher:pusher-java-client:2.1.1' + compile 'com.pusher:pusher-java-client:2.2.0' } ``` diff --git a/build.gradle b/build.gradle index de62c60f..e3316c28 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'signing' apply plugin: 'jacoco' group = "com.pusher" -version = "2.1.1" +version = "2.2.0" sourceCompatibility = "1.8" targetCompatibility = "1.8" diff --git a/src/main/java/com/pusher/client/PusherOptions.java b/src/main/java/com/pusher/client/PusherOptions.java index 77b525e2..2d54cccd 100644 --- a/src/main/java/com/pusher/client/PusherOptions.java +++ b/src/main/java/com/pusher/client/PusherOptions.java @@ -34,7 +34,7 @@ public class PusherOptions { private String host = "ws.pusherapp.com"; private int wsPort = WS_PORT; private int wssPort = WSS_PORT; - private boolean encrypted = true; + private boolean forceTLS = true; private long activityTimeout = DEFAULT_ACTIVITY_TIMEOUT; private long pongTimeout = DEFAULT_PONG_TIMEOUT; private Authorizer authorizer; @@ -43,24 +43,39 @@ public class PusherOptions { private int maxReconnectGapInSeconds = MAX_RECONNECT_GAP_IN_SECONDS; /** - * Gets whether an encrypted (SSL) connection should be used when connecting - * to Pusher. - * - * @return true if an encrypted connection should be used; otherwise false. + * @deprecated + * Please use isForceTLS */ + @Deprecated public boolean isEncrypted() { - return encrypted; + return forceTLS; + } + + /** + * @deprecated + * Please use setForceTLS + */ + @Deprecated + public PusherOptions setEncrypted(final boolean encrypted) { + this.forceTLS = encrypted; + return this; } /** - * Sets whether an encrypted (SSL) connection should be used when connecting to - * Pusher. * - * @param encrypted Whether to use an SSL connection + * @return whether the connection to Pusher should use TLS + */ + public boolean isForceTLS() { + return forceTLS; + } + + /** + * Sets whether the connection to Pusher should be use TLS. + * @param forceTLS whether the connection should use TLS, by default this is true * @return this, for chaining */ - public PusherOptions setEncrypted(final boolean encrypted) { - this.encrypted = encrypted; + public PusherOptions setForceTLS(final boolean forceTLS) { + this.forceTLS = forceTLS; return this; } @@ -103,7 +118,7 @@ public PusherOptions setHost(final String host) { } /** - * The port to which unencrypted connections will be made. + * The port to which non TLS connections will be made. * * Note that if you wish to connect to a standard Pusher cluster, the * convenience method setCluster will set the host and ports correctly from @@ -222,7 +237,7 @@ public long getPongTimeout() { * @return the WebSocket URL */ public String buildUrl(final String apiKey) { - return String.format("%s://%s:%s/app/%s%s", encrypted ? WSS_SCHEME : WS_SCHEME, host, encrypted ? wssPort + return String.format("%s://%s:%s/app/%s%s", forceTLS ? WSS_SCHEME : WS_SCHEME, host, forceTLS ? wssPort : wsPort, apiKey, URI_SUFFIX); } diff --git a/src/main/java/com/pusher/client/example/ExampleApp.java b/src/main/java/com/pusher/client/example/ExampleApp.java index 9dd22d45..0ce39fda 100644 --- a/src/main/java/com/pusher/client/example/ExampleApp.java +++ b/src/main/java/com/pusher/client/example/ExampleApp.java @@ -47,7 +47,7 @@ public ExampleApp(final String[] args) { // configure your Pusher connection with the options you want final PusherOptions options = new PusherOptions() - .setEncrypted(true) + .setForceTLS(true) .setCluster(cluster); Pusher pusher = new Pusher(channelsKey, options); diff --git a/src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java b/src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java index b2a7f20f..34b004ec 100644 --- a/src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java +++ b/src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java @@ -56,7 +56,7 @@ private PresenceChannelExampleApp(final String[] args) { // configure your Pusher connection with the options you want final PusherOptions options = new PusherOptions() - .setEncrypted(true) + .setForceTLS(true) .setCluster(cluster) .setAuthorizer(authorizer); Pusher pusher = new Pusher(channelsKey, options); diff --git a/src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java b/src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java index 6ea9db42..d86e6a29 100644 --- a/src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java +++ b/src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java @@ -54,7 +54,7 @@ public static void main(final String[] args) { // configure your Pusher connection with the options you want final PusherOptions options = new PusherOptions() - .setEncrypted(true) + .setForceTLS(true) .setCluster(cluster) .setAuthorizer(authorizer); Pusher pusher = new Pusher(channelsKey, options); diff --git a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java index 73d4db92..4043b0a7 100644 --- a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java +++ b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java @@ -60,7 +60,7 @@ private PrivateEncryptedChannelExampleApp(final String[] args) { final PusherOptions options = new PusherOptions() .setCluster(cluster) .setAuthorizer(authorizer) - .setEncrypted(true); + .setForceTLS(true); Pusher pusher = new Pusher(channelsKey, options); // set up a ConnectionEventListener to listen for connection changes to Pusher diff --git a/src/test/java/com/pusher/client/PusherOptionsTest.java b/src/test/java/com/pusher/client/PusherOptionsTest.java index e10cde5c..0e5e7ddc 100644 --- a/src/test/java/com/pusher/client/PusherOptionsTest.java +++ b/src/test/java/com/pusher/client/PusherOptionsTest.java @@ -1,17 +1,18 @@ package com.pusher.client; -import static org.junit.Assert.*; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + @RunWith(MockitoJUnitRunner.class) public class PusherOptionsTest { @@ -30,6 +31,11 @@ public void testEncryptedInitializedAsTrue() { assert pusherOptions.isEncrypted(); } + @Test + public void testForceTLSInitializedAsTrue() { + assert pusherOptions.isForceTLS(); + } + @Test public void testAuthorizerIsInitiallyNull() { assertNull(pusherOptions.getAuthorizer()); @@ -47,6 +53,12 @@ public void testEncryptedCanBeSetToTrue() { assertSame(true, pusherOptions.isEncrypted()); } + @Test + public void testForceTLSCanBeSetToTrue() { + pusherOptions.setForceTLS(true); + assertSame(true, pusherOptions.isForceTLS()); + } + @Test public void testSetAuthorizerReturnsSelf() { assertSame(pusherOptions, pusherOptions.setAuthorizer(mockAuthorizer)); @@ -57,6 +69,11 @@ public void testSetEncryptedReturnsSelf() { assertSame(pusherOptions, pusherOptions.setEncrypted(true)); } + @Test + public void testSetForceTLSReturnsSelf() { + assertSame(pusherOptions, pusherOptions.setForceTLS(true)); + } + @Test public void testDefaultURL() { assertEquals(pusherOptions.buildUrl(API_KEY), "wss://ws.pusherapp.com:443/app/" + API_KEY @@ -65,7 +82,7 @@ public void testDefaultURL() { @Test public void testNonSSLURLIsCorrect() { - pusherOptions.setEncrypted(false); + pusherOptions.setForceTLS(false); assertEquals(pusherOptions.buildUrl(API_KEY), "ws://ws.pusherapp.com:80/app/" + API_KEY + "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION); } @@ -79,7 +96,7 @@ public void testClusterSetURLIsCorrect() { @Test public void testClusterSetNonSSLURLIsCorrect() { - pusherOptions.setCluster("eu").setEncrypted(false); + pusherOptions.setCluster("eu").setForceTLS(false); assertEquals(pusherOptions.buildUrl(API_KEY), "ws://ws-eu.pusher.com:80/app/" + API_KEY + "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION); } @@ -93,7 +110,7 @@ public void testCustomHostAndPortURLIsCorrect() { @Test public void testCustomHostAndPortNonSSLURLIsCorrect() { - pusherOptions.setHost("subdomain.example.com").setWsPort(8080).setWssPort(8181).setEncrypted(false); + pusherOptions.setHost("subdomain.example.com").setWsPort(8080).setWssPort(8181).setForceTLS(false); assertEquals(pusherOptions.buildUrl(API_KEY), "ws://subdomain.example.com:8080/app/" + API_KEY + "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION); }