Skip to content
Merged
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
54 changes: 35 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<okhttp.version>4.8.1</okhttp.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -55,8 +56,23 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.2.0</version>
<version>${okhttp.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${okhttp.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<version>${okhttp.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -109,27 +125,27 @@
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- this plugin is for creating fat jar (jar with embedded dependencies). -->
<!-- this plugin is for creating fat jar (jar with embedded dependencies). -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down Expand Up @@ -181,4 +197,4 @@
<url>https://opensource.org/licenses/BSD-3-Clause</url>
</license>
</licenses>
</project>
</project>
17 changes: 12 additions & 5 deletions src/main/java/com/clevertap/apns/clients/ApnsClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package com.clevertap.apns.clients;

import com.clevertap.apns.ApnsClient;
import com.clevertap.apns.exceptions.InvalidTrustManagerException;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
Expand All @@ -52,6 +53,7 @@ public class ApnsClientBuilder {
private boolean production;
private String password;
private int connectionPort = 443;
private String gatewayUrl;

private boolean asynchronous = false;
private String defaultTopic = null;
Expand Down Expand Up @@ -169,9 +171,14 @@ public ApnsClientBuilder withDefaultTopic(String defaultTopic) {
return this;
}

public ApnsClientBuilder withGatewayUrl(String url) {
this.gatewayUrl = url;
return this;
}

public ApnsClient build() throws CertificateException,
NoSuchAlgorithmException, KeyStoreException, IOException,
UnrecoverableKeyException, KeyManagementException {
UnrecoverableKeyException, KeyManagementException, InvalidTrustManagerException {

if (builder == null) {
builder = createDefaultOkHttpClientBuilder();
Expand All @@ -183,15 +190,15 @@ public ApnsClient build() throws CertificateException,

if (certificate != null) {
if (asynchronous) {
return new AsyncOkHttpApnsClient(certificate, password, production, defaultTopic, builder, connectionPort);
return new AsyncOkHttpApnsClient(certificate, password, production, defaultTopic, builder, connectionPort, gatewayUrl);
} else {
return new SyncOkHttpApnsClient(certificate, password, production, defaultTopic, builder, connectionPort);
return new SyncOkHttpApnsClient(certificate, password, production, defaultTopic, builder, connectionPort, gatewayUrl);
}
} else if (keyID != null && teamID != null && apnsAuthKey != null) {
if (asynchronous) {
return new AsyncOkHttpApnsClient(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, connectionPort);
return new AsyncOkHttpApnsClient(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, connectionPort, gatewayUrl);
} else {
return new SyncOkHttpApnsClient(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, connectionPort);
return new SyncOkHttpApnsClient(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, connectionPort, gatewayUrl);
}
} else {
throw new IllegalArgumentException("Either the token credentials (team ID, key ID, and the private key) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.clevertap.apns.Notification;
import com.clevertap.apns.NotificationResponse;
import com.clevertap.apns.NotificationResponseListener;
import com.clevertap.apns.exceptions.InvalidTrustManagerException;
import okhttp3.*;

import java.io.IOException;
Expand All @@ -56,7 +57,7 @@ public AsyncOkHttpApnsClient(String apnsAuthKey, String teamID, String keyID,
public AsyncOkHttpApnsClient(InputStream certificate, String password, boolean production,
String defaultTopic, ConnectionPool connectionPool)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException,
IOException, UnrecoverableKeyException, KeyManagementException {
IOException, UnrecoverableKeyException, KeyManagementException, InvalidTrustManagerException {
super(certificate, password, production, defaultTopic, connectionPool);
}

Expand All @@ -65,23 +66,36 @@ public AsyncOkHttpApnsClient(String apnsAuthKey, String teamID, String keyID,
this(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, 443);
}

public AsyncOkHttpApnsClient(String apnsAuthKey, String teamID, String keyID,
boolean production, String defaultTopic, OkHttpClient.Builder builder, int connectionPort,
String gatewayUrl) {
super(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, gatewayUrl);
}

public AsyncOkHttpApnsClient(String apnsAuthKey, String teamID, String keyID,
boolean production, String defaultTopic, OkHttpClient.Builder builder, int connectionPort) {
super(apnsAuthKey, teamID, keyID, production, defaultTopic, builder);
this(apnsAuthKey, teamID, keyID, production, defaultTopic, builder, 443, null);
}

public AsyncOkHttpApnsClient(InputStream certificate, String password, boolean production,
String defaultTopic, OkHttpClient.Builder builder)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException,
IOException, UnrecoverableKeyException, KeyManagementException {
IOException, UnrecoverableKeyException, KeyManagementException, InvalidTrustManagerException {
this(certificate, password, production, defaultTopic, builder, 443);
}

public AsyncOkHttpApnsClient(InputStream certificate, String password, boolean production,
String defaultTopic, OkHttpClient.Builder builder, int connectionPort, String gatewayUrl)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException,
IOException, UnrecoverableKeyException, KeyManagementException, InvalidTrustManagerException {
super(certificate, password, production, defaultTopic, builder, gatewayUrl);
}

public AsyncOkHttpApnsClient(InputStream certificate, String password, boolean production,
String defaultTopic, OkHttpClient.Builder builder, int connectionPort)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException,
IOException, UnrecoverableKeyException, KeyManagementException {
super(certificate, password, production, defaultTopic, builder);
IOException, UnrecoverableKeyException, KeyManagementException, InvalidTrustManagerException {
this(certificate, password, production, defaultTopic, builder, 443, null);
}

@Override
Expand Down
Loading