Skip to content

Commit c85f492

Browse files
authored
Merge pull request #255 from pusher/dev-encrypted-use-tls
2.2.0 Pusher Options encrypted to forceTLS
2 parents 77b97fc + cdccd66 commit c85f492

File tree

9 files changed

+62
-26
lines changed

9 files changed

+62
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# pusher-websocket-java changelog
22

3+
## Version 2.2.0 - 22nd April 2020
4+
5+
* Changed PusherOptions `setEncrypted` and `isEncrypted` to `setForceTLS` and `isForceTLS` to reduce confusion between this option and private encrypted channels.
6+
37
## Version 2.1.1 - 15th April 2020
48

59
* Fix a case where multiple websocket connections could be opened at once

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The pusher-java-client is available in Maven Central.
6161
<dependency>
6262
<groupId>com.pusher</groupId>
6363
<artifactId>pusher-java-client</artifactId>
64-
<version>2.1.1</version>
64+
<version>2.2.0</version>
6565
</dependency>
6666
</dependencies>
6767
```
@@ -70,7 +70,7 @@ The pusher-java-client is available in Maven Central.
7070

7171
```groovy
7272
dependencies {
73-
compile 'com.pusher:pusher-java-client:2.1.1'
73+
compile 'com.pusher:pusher-java-client:2.2.0'
7474
}
7575
```
7676

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ apply plugin: 'signing'
2222
apply plugin: 'jacoco'
2323

2424
group = "com.pusher"
25-
version = "2.1.1"
25+
version = "2.2.0"
2626
sourceCompatibility = "1.8"
2727
targetCompatibility = "1.8"
2828

src/main/java/com/pusher/client/PusherOptions.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class PusherOptions {
3434
private String host = "ws.pusherapp.com";
3535
private int wsPort = WS_PORT;
3636
private int wssPort = WSS_PORT;
37-
private boolean encrypted = true;
37+
private boolean forceTLS = true;
3838
private long activityTimeout = DEFAULT_ACTIVITY_TIMEOUT;
3939
private long pongTimeout = DEFAULT_PONG_TIMEOUT;
4040
private Authorizer authorizer;
@@ -43,24 +43,39 @@ public class PusherOptions {
4343
private int maxReconnectGapInSeconds = MAX_RECONNECT_GAP_IN_SECONDS;
4444

4545
/**
46-
* Gets whether an encrypted (SSL) connection should be used when connecting
47-
* to Pusher.
48-
*
49-
* @return true if an encrypted connection should be used; otherwise false.
46+
* @deprecated
47+
* Please use isForceTLS
5048
*/
49+
@Deprecated
5150
public boolean isEncrypted() {
52-
return encrypted;
51+
return forceTLS;
52+
}
53+
54+
/**
55+
* @deprecated
56+
* Please use setForceTLS
57+
*/
58+
@Deprecated
59+
public PusherOptions setEncrypted(final boolean encrypted) {
60+
this.forceTLS = encrypted;
61+
return this;
5362
}
5463

5564
/**
56-
* Sets whether an encrypted (SSL) connection should be used when connecting to
57-
* Pusher.
5865
*
59-
* @param encrypted Whether to use an SSL connection
66+
* @return whether the connection to Pusher should use TLS
67+
*/
68+
public boolean isForceTLS() {
69+
return forceTLS;
70+
}
71+
72+
/**
73+
* Sets whether the connection to Pusher should be use TLS.
74+
* @param forceTLS whether the connection should use TLS, by default this is true
6075
* @return this, for chaining
6176
*/
62-
public PusherOptions setEncrypted(final boolean encrypted) {
63-
this.encrypted = encrypted;
77+
public PusherOptions setForceTLS(final boolean forceTLS) {
78+
this.forceTLS = forceTLS;
6479
return this;
6580
}
6681

@@ -103,7 +118,7 @@ public PusherOptions setHost(final String host) {
103118
}
104119

105120
/**
106-
* The port to which unencrypted connections will be made.
121+
* The port to which non TLS connections will be made.
107122
*
108123
* Note that if you wish to connect to a standard Pusher cluster, the
109124
* convenience method setCluster will set the host and ports correctly from
@@ -222,7 +237,7 @@ public long getPongTimeout() {
222237
* @return the WebSocket URL
223238
*/
224239
public String buildUrl(final String apiKey) {
225-
return String.format("%s://%s:%s/app/%s%s", encrypted ? WSS_SCHEME : WS_SCHEME, host, encrypted ? wssPort
240+
return String.format("%s://%s:%s/app/%s%s", forceTLS ? WSS_SCHEME : WS_SCHEME, host, forceTLS ? wssPort
226241
: wsPort, apiKey, URI_SUFFIX);
227242
}
228243

src/main/java/com/pusher/client/example/ExampleApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ExampleApp(final String[] args) {
4747

4848
// configure your Pusher connection with the options you want
4949
final PusherOptions options = new PusherOptions()
50-
.setEncrypted(true)
50+
.setForceTLS(true)
5151
.setCluster(cluster);
5252
Pusher pusher = new Pusher(channelsKey, options);
5353

src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private PresenceChannelExampleApp(final String[] args) {
5656

5757
// configure your Pusher connection with the options you want
5858
final PusherOptions options = new PusherOptions()
59-
.setEncrypted(true)
59+
.setForceTLS(true)
6060
.setCluster(cluster)
6161
.setAuthorizer(authorizer);
6262
Pusher pusher = new Pusher(channelsKey, options);

src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void main(final String[] args) {
5454

5555
// configure your Pusher connection with the options you want
5656
final PusherOptions options = new PusherOptions()
57-
.setEncrypted(true)
57+
.setForceTLS(true)
5858
.setCluster(cluster)
5959
.setAuthorizer(authorizer);
6060
Pusher pusher = new Pusher(channelsKey, options);

src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private PrivateEncryptedChannelExampleApp(final String[] args) {
6060
final PusherOptions options = new PusherOptions()
6161
.setCluster(cluster)
6262
.setAuthorizer(authorizer)
63-
.setEncrypted(true);
63+
.setForceTLS(true);
6464
Pusher pusher = new Pusher(channelsKey, options);
6565

6666
// set up a ConnectionEventListener to listen for connection changes to Pusher

src/test/java/com/pusher/client/PusherOptionsTest.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.pusher.client;
22

3-
import static org.junit.Assert.*;
4-
53
import org.junit.Before;
64
import org.junit.Test;
75
import org.junit.runner.RunWith;
86
import org.mockito.Mock;
97
import org.mockito.runners.MockitoJUnitRunner;
108

11-
import java.net.InetAddress;
129
import java.net.InetSocketAddress;
1310
import java.net.Proxy;
1411

12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertNull;
14+
import static org.junit.Assert.assertSame;
15+
1516
@RunWith(MockitoJUnitRunner.class)
1617
public class PusherOptionsTest {
1718

@@ -30,6 +31,11 @@ public void testEncryptedInitializedAsTrue() {
3031
assert pusherOptions.isEncrypted();
3132
}
3233

34+
@Test
35+
public void testForceTLSInitializedAsTrue() {
36+
assert pusherOptions.isForceTLS();
37+
}
38+
3339
@Test
3440
public void testAuthorizerIsInitiallyNull() {
3541
assertNull(pusherOptions.getAuthorizer());
@@ -47,6 +53,12 @@ public void testEncryptedCanBeSetToTrue() {
4753
assertSame(true, pusherOptions.isEncrypted());
4854
}
4955

56+
@Test
57+
public void testForceTLSCanBeSetToTrue() {
58+
pusherOptions.setForceTLS(true);
59+
assertSame(true, pusherOptions.isForceTLS());
60+
}
61+
5062
@Test
5163
public void testSetAuthorizerReturnsSelf() {
5264
assertSame(pusherOptions, pusherOptions.setAuthorizer(mockAuthorizer));
@@ -57,6 +69,11 @@ public void testSetEncryptedReturnsSelf() {
5769
assertSame(pusherOptions, pusherOptions.setEncrypted(true));
5870
}
5971

72+
@Test
73+
public void testSetForceTLSReturnsSelf() {
74+
assertSame(pusherOptions, pusherOptions.setForceTLS(true));
75+
}
76+
6077
@Test
6178
public void testDefaultURL() {
6279
assertEquals(pusherOptions.buildUrl(API_KEY), "wss://ws.pusherapp.com:443/app/" + API_KEY
@@ -65,7 +82,7 @@ public void testDefaultURL() {
6582

6683
@Test
6784
public void testNonSSLURLIsCorrect() {
68-
pusherOptions.setEncrypted(false);
85+
pusherOptions.setForceTLS(false);
6986
assertEquals(pusherOptions.buildUrl(API_KEY), "ws://ws.pusherapp.com:80/app/" + API_KEY
7087
+ "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION);
7188
}
@@ -79,7 +96,7 @@ public void testClusterSetURLIsCorrect() {
7996

8097
@Test
8198
public void testClusterSetNonSSLURLIsCorrect() {
82-
pusherOptions.setCluster("eu").setEncrypted(false);
99+
pusherOptions.setCluster("eu").setForceTLS(false);
83100
assertEquals(pusherOptions.buildUrl(API_KEY), "ws://ws-eu.pusher.com:80/app/" + API_KEY
84101
+ "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION);
85102
}
@@ -93,7 +110,7 @@ public void testCustomHostAndPortURLIsCorrect() {
93110

94111
@Test
95112
public void testCustomHostAndPortNonSSLURLIsCorrect() {
96-
pusherOptions.setHost("subdomain.example.com").setWsPort(8080).setWssPort(8181).setEncrypted(false);
113+
pusherOptions.setHost("subdomain.example.com").setWsPort(8080).setWssPort(8181).setForceTLS(false);
97114
assertEquals(pusherOptions.buildUrl(API_KEY), "ws://subdomain.example.com:8080/app/" + API_KEY
98115
+ "?client=java-client&protocol=5&version=" + PusherOptions.LIB_VERSION);
99116
}

0 commit comments

Comments
 (0)