Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to OkHttp 3.10 with JDK9+ support #45

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.clevertap.apns</groupId>
<artifactId>apns-http2</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>

<name>apns-http2</name>
<description>A library for communicating with the Apple Push Gateway in HTTP/2.</description>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.2.0</version>
<version>3.10.0</version>
</dependency>

<dependency>
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import java.util.UUID;

/**
Expand Down Expand Up @@ -177,12 +178,20 @@ public SyncOkHttpApnsClient(InputStream certificate, String password, boolean pr
SSLContext sslContext = SSLContext.getInstance("TLS");

final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
tmf.init(ks);
sslContext.init(keyManagers, tmf.getTrustManagers(), null);

final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

builder.sslSocketFactory(sslSocketFactory);
TrustManagerFactory trustManagerFactory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
}
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
sslContext.init(null, new TrustManager[]{trustManager}, null);
builder.sslSocketFactory(sslSocketFactory, trustManager);

client = builder.build();

Expand Down
60 changes: 60 additions & 0 deletions src/test/com/clevertap/apns/integration/NotificationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.clevertap.apns.integration;

import com.clevertap.apns.ApnsClient;
import com.clevertap.apns.Notification;
import com.clevertap.apns.NotificationResponse;
import com.clevertap.apns.NotificationResponseListener;
import com.clevertap.apns.clients.ApnsClientBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;

public class NotificationTest {
private static String APN_AUTH_KEY;
private static String TOKEN;
private static String TEAM_ID;
private static String KEY_ID;

ApnsClient asyncClient;
@BeforeClass
public static void init(){
APN_AUTH_KEY = System.getProperty("com.clevertap.auth_key");
TOKEN = System.getProperty("com.clevertap.token");
TEAM_ID = System.getProperty("com.clevertap.team_id");
KEY_ID = System.getProperty("com.clevertap.key_id");
}
@Before
public void setUp() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
asyncClient = new ApnsClientBuilder().
inAsynchronousMode().
withApnsAuthKey(APN_AUTH_KEY).
withTeamID(TEAM_ID).
withKeyID(KEY_ID).
build();
}
@Test
public void sendNotification(){
Notification notification = new Notification.Builder(TOKEN).alertBody("Hello").build();

asyncClient.push(notification, new NotificationResponseListener() {
@Override
public void onSuccess(Notification notification) {

}

@Override
public void onFailure(Notification notification, NotificationResponse response) {
Assert.fail("Failed to send notification: "+response.getResponseBody());
}
});
}

}