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
50 changes: 3 additions & 47 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
import org.apache.tools.ant.filters.ReplaceTokens

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.1.0'
}
}

plugins {
id "eclipse"
id "jacoco"
id "java-library"
id "maven-publish"
id "org.ajoberstar.github-pages" version "1.7.2"
id "signing"
}

def getProperty = { property ->
if (!project.hasProperty(property)) {
throw new GradleException("${property} property must be set")
}
return project.property(property)
}

group = "com.pusher"
version = "2.4.4"
version = "2.4.5"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand Down Expand Up @@ -55,20 +35,17 @@ dependencies {
testImplementation "com.google.truth:truth:1.0.1"
}

import org.apache.tools.ant.filters.ReplaceTokens

processResources {
filter(ReplaceTokens, tokens: [
version: project.version
])
}


javadoc {
/* info for JavaDoc options http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javadoc.html#overviewcomment */
title "Pusher Java Websocket API"
options.overview = file("src/main/javadoc/overview.html")
// uncomment this to use the custom javadoc styles
//options.stylesheetFile = file("src/main/javadoc/css/styles.css")
exclude "com/pusher/client/channel/impl/*"
exclude "com/pusher/client/connection/impl/*"
exclude "com/pusher/client/connection/websocket/*"
Expand All @@ -79,7 +56,6 @@ javadoc {
options.linkSource = true
}


jar {
manifest = project.manifest {
from sharedManifest
Expand All @@ -97,32 +73,18 @@ task fatJar(type: Jar, dependsOn: configurations.runtimeClasspath) {
}
assemble.dependsOn fatJar


task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
assemble.dependsOn sourcesJar


task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
assemble.dependsOn javadocJar

githubPages {
repoUri = 'https://github.com/pusher/pusher-websocket-java.git'
pages {
from javadoc.outputs.files
}
commitMessage = "JavaDoc gh-pages for ${version}"
credentials {
username = { getProperty("github.username") }
password = { getProperty("github.password") }
}
}

artifacts {
archives jar, fatJar, sourcesJar, javadocJar
}
Expand All @@ -136,7 +98,6 @@ publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'pusher-java-client'

from components.java
pom {
name = 'Pusher Java Client Library'
Expand Down Expand Up @@ -187,10 +148,6 @@ publishing {
}
}

signing {
sign publishing.publications.mavenJava
}

jacoco {
toolVersion = "0.8.8"
}
Expand All @@ -201,9 +158,8 @@ jacocoTestReport {
reports.csv.required = false
}

// Test Logging - https://stackoverflow.com/a/42425815/2623314
test {
testLogging {
showStandardStreams = true
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 10 additions & 0 deletions src/main/java/com/pusher/client/PusherOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
public class PusherOptions {

private String tlsVersion = "TLS";
private static final String SRC_LIB_DEV_VERSION = "@version@";
private static final String LIB_DEV_VERSION = "0.0.0-dev";
public static final String LIB_VERSION = readVersionFromProperties();
Expand Down Expand Up @@ -44,6 +45,15 @@ public class PusherOptions {
private int maxReconnectionAttempts = MAX_RECONNECTION_ATTEMPTS;
private int maxReconnectGapInSeconds = MAX_RECONNECT_GAP_IN_SECONDS;

public PusherOptions setTlsVersion(String tlsVersion) {
this.tlsVersion = tlsVersion;
return this;
}

public String getTlsVersion() {
return tlsVersion;
}

/**
* @deprecated Please use isUseTLS
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class WebSocketClientWrapper extends WebSocketClient {
private static final String WSS_SCHEME = "wss";
private WebSocketListener webSocketListener;

public WebSocketClientWrapper(final URI uri, final Proxy proxy, final WebSocketListener webSocketListener)
public WebSocketClientWrapper(final URI uri, final Proxy proxy, final WebSocketListener webSocketListener, String tlsVersion)
throws SSLException {
super(uri);
if (uri.getScheme().equals(WSS_SCHEME)) {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
SSLContext sslContext = SSLContext.getInstance(tlsVersion);
sslContext.init(null, null, null); // will use java's default
// key and trust store which
// is sufficient unless you
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/pusher/client/util/BaseHttpAuthClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pusher.client.util;

import javax.net.ssl.SSLSocketFactory;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
Expand All @@ -22,6 +23,7 @@ abstract class BaseHttpAuthClient {
private final URL endPoint;
private Map<String, String> mHeaders = new HashMap<>();
protected ConnectionFactory mConnectionFactory;
protected SSLSocketFactory mSslSocketFactory = null;

/**
* Creates a new auth client.
Expand Down Expand Up @@ -61,6 +63,15 @@ public void setHeaders(final Map<String, String> headers) {
mHeaders = headers;
}

/**
* Set the SSL socket factory that is used for the connection. This allows to
* configure custom certificate handling (self-signed certificates, mutual TLS, ...)
* @param sslSocketFactory The SSL socket factory to use
*/
public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) {
mSslSocketFactory = sslSocketFactory;
}

/**
* Identifies if the HTTP request will be sent over HTTPS.
*
Expand Down Expand Up @@ -92,6 +103,10 @@ protected String performAuthRequest() {
HttpURLConnection connection;
if (isSSL()) {
connection = (HttpsURLConnection) endPoint.openConnection();
if(mSslSocketFactory != null) {
((HttpsURLConnection) connection)
.setSSLSocketFactory(mSslSocketFactory);
}
} else {
connection = (HttpURLConnection) endPoint.openConnection();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/pusher/client/util/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public class Factory {
private ExecutorService eventQueue;
private ScheduledExecutorService timers;
private static final Object eventLock = new Object();
private String tlsVersion = "TLS";

public synchronized InternalConnection getConnection(
final String apiKey,
final PusherOptions options,
final Consumer<PusherEvent> eventHandler
) {
if (connection == null) {
tlsVersion = options.getTlsVersion(); // ← add this line
try {
connection =
new WebSocketConnection(
Expand All @@ -82,7 +84,7 @@ public WebSocketClientWrapper newWebSocketClientWrapper(
final Proxy proxy,
final WebSocketListener webSocketListener
) throws SSLException {
return new WebSocketClientWrapper(uri, proxy, webSocketListener);
return new WebSocketClientWrapper(uri, proxy, webSocketListener, tlsVersion); // ← use field
}

public synchronized ScheduledExecutorService getTimers() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/pusher/client/EndToEndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public WebSocketClientWrapper answer(final InvocationOnMock invocation) throws T
final URI uri = (URI) invocation.getArguments()[0];
final Proxy proxy = (Proxy) invocation.getArguments()[1];
final WebSocketListener webSocketListener = (WebSocketListener) invocation.getArguments()[2];
testWebsocket = new TestWebSocketClientWrapper(uri, proxy, webSocketListener);
testWebsocket = new TestWebSocketClientWrapper(uri, proxy, webSocketListener, "TLSv1.3");
return testWebsocket;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

public class TestWebSocketClientWrapper extends WebSocketClientWrapper {

private final List<String> messagesSent = new ArrayList<String>();
private final List<String> messagesSent = new ArrayList<>();
private boolean connectCalled = false;

public TestWebSocketClientWrapper(final URI uri, final Proxy proxy, final WebSocketListener webSocketListener)
public TestWebSocketClientWrapper(final URI uri, final Proxy proxy, final WebSocketListener webSocketListener, String tlsVersion)
throws SSLException {
super(uri, proxy, webSocketListener);
super(uri, proxy, webSocketListener, tlsVersion);
}

void assertConnectCalled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class WebSocketClientWrapperTest {

@Before
public void setUp() throws URISyntaxException, SSLException {
wrapper = new WebSocketClientWrapper(new URI("http://www.test.com"), mockProxy, mockListener);
wrapper = new WebSocketClientWrapper(new URI("http://www.test.com"), mockProxy, mockListener,"TLSV13");
}

@Test
Expand Down