Repository: jchambers/pushy
Pull request #1073 (2024-07-06 16:56:51)

Update metrics listeners dependencies/READMEs; update to Dropwizard Metrics 4
This updates the Dropwizard Metrics listener to depend on Dropwizard Metrics 4. Dropwizard Metrics 3 is truly ancient; that nobody complained about this so far makes me really suspicious that nobody is really using this listener, and we might benefit from dropping it entirely some time in the future.


Patch:
diff --git a/dropwizard-metrics-listener/README.md b/dropwizard-metrics-listener/README.md
index 6b41b807..e39f7c35 100644
--- a/dropwizard-metrics-listener/README.md
+++ b/dropwizard-metrics-listener/README.md
@@ -6,11 +6,11 @@ This module is an implementation of Pushy's [`ApnsClientMetricsListener`](https:
 <dependency>
     <groupId>com.eatthepath</groupId>
     <artifactId>pushy-dropwizard-metrics-listener</artifactId>
-    <version>0.15.2</version>
+    <version>0.16.0</version>
 </dependency>
 ```
 
-If you don't use Maven, you can add the `.jar` file and its dependencies to your classpath by the method of your choice. The Dropwizard Metrics listener for Pushy depends on Pushy itself (obviously enough) and version 3.1.0 of the [Dropwizard Metrics library](http://metrics.dropwizard.io/).
+If you don't use Maven, you can add the `.jar` file and its dependencies to your classpath by the method of your choice. The Dropwizard Metrics listener for Pushy depends on Pushy itself (obviously enough) and version 4.2.26 of the [Dropwizard Metrics library](http://metrics.dropwizard.io/).
 
 ## Using the Dropwizard Metrics listener
 
diff --git a/dropwizard-metrics-listener/pom.xml b/dropwizard-metrics-listener/pom.xml
index b2884bbb..2944ecd3 100644
--- a/dropwizard-metrics-listener/pom.xml
+++ b/dropwizard-metrics-listener/pom.xml
@@ -44,7 +44,7 @@
         <dependency>
             <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-core</artifactId>
-            <version>3.1.0</version>
+            <version>4.2.26</version>
         </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
diff --git a/micrometer-metrics-listener/README.md b/micrometer-metrics-listener/README.md
index 8d62d0ef..b7af0516 100644
--- a/micrometer-metrics-listener/README.md
+++ b/micrometer-metrics-listener/README.md
@@ -6,11 +6,11 @@ This module is an implementation of Pushy's [`ApnsClientMetricsListener`](https:
 <dependency>
     <groupId>com.eatthepath</groupId>
     <artifactId>pushy-micrometer-metrics-listener</artifactId>
-    <version>0.15.2</version>
+    <version>0.16.0</version>
 </dependency>
 ```
 
-If you don't use Maven, you can add the `.jar` file and its dependencies to your classpath by the method of your choice. The Micrometer listener for Pushy depends on Pushy itself (obviously enough) and version 1.0 of the [Micrometer application monitoring library](http://micrometer.io/). Please note that while Pushy itself works with Java 7 and newer, **the Micrometer metrics listener requires Java 8 or newer.**
+If you don't use Maven, you can add the `.jar` file and its dependencies to your classpath by the method of your choice. The Micrometer listener for Pushy depends on Pushy itself (obviously enough) and version 1.13.1 of the [Micrometer application monitoring library](http://micrometer.io/).
 
 ## Using the Micrometer Metrics listener
 
diff --git a/micrometer-metrics-listener/pom.xml b/micrometer-metrics-listener/pom.xml
index ea928687..0a46f7ac 100644
--- a/micrometer-metrics-listener/pom.xml
+++ b/micrometer-metrics-listener/pom.xml
@@ -43,7 +43,7 @@
         <dependency>
             <groupId>io.micrometer</groupId>
             <artifactId>micrometer-core</artifactId>
-            <version>1.0.3</version>
+            <version>1.13.1</version>
         </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
diff --git a/pushy/src/main/java/com/eatthepath/pushy/apns/ApnsClientBuilder.java b/pushy/src/main/java/com/eatthepath/pushy/apns/ApnsClientBuilder.java
index 3ce5fb7b..b935f83e 100644
--- a/pushy/src/main/java/com/eatthepath/pushy/apns/ApnsClientBuilder.java
+++ b/pushy/src/main/java/com/eatthepath/pushy/apns/ApnsClientBuilder.java
@@ -241,6 +241,24 @@ public class ApnsClientBuilder {
         return this.setClientCredentials(x509Certificate, privateKey, p12Password);
     }
 
+    /**
+     * <p>Sets the TLS credentials for the client under construction. Clients constructed with TLS credentials will use
+     * TLS-based authentication when sending push notifications. This method assumes that the given private key does
+     * not require a password.</p>
+     *
+     * <p>Clients may not have both TLS credentials and a signing key.</p>
+     *
+     * @param clientCertificate the certificate to be used to identify the client to the APNs server
+     * @param privateKey the private key for the client certificate
+     *
+     * @return a reference to this builder
+     *
+     * @since 0.16
+     */
+    public ApnsClientBuilder setClientCredentials(final X509Certificate clientCertificate, final PrivateKey privateKey) {
+        return this.setClientCredentials(clientCertificate, privateKey, null);
+    }
+
     /**
      * <p>Sets the TLS credentials for the client under construction. Clients constructed with TLS credentials will use
      * TLS-based authentication when sending push notifications.</p>
diff --git a/pushy/src/main/java/com/eatthepath/pushy/apns/server/BaseHttp2ServerBuilder.java b/pushy/src/main/java/com/eatthepath/pushy/apns/server/BaseHttp2ServerBuilder.java
index 5efd4e0e..05eea2f1 100644
--- a/pushy/src/main/java/com/eatthepath/pushy/apns/server/BaseHttp2ServerBuilder.java
+++ b/pushy/src/main/java/com/eatthepath/pushy/apns/server/BaseHttp2ServerBuilder.java
@@ -125,6 +125,21 @@ abstract class BaseHttp2ServerBuilder <T extends BaseHttp2Server> {
         return this;
     }
 
+    /**
+     * <p>Sets the credentials for the server under construction. This method assumes that the given private key does
+     * not require a password.</p>
+     *
+     * @param certificates a certificate chain including the server's own certificate
+     * @param privateKey the private key for the server's certificate
+     *
+     * @return a reference to this builder
+     *
+     * @since 0.16
+     */
+    public BaseHttp2ServerBuilder<T> setServerCredentials(final X509Certificate[] certificates, final PrivateKey privateKey) {
+        return this.setServerCredentials(certificates, privateKey, null);
+    }
+
     /**
      * <p>Sets the credentials for the server under construction.</p>
      *
diff --git a/pushy/src/main/java/com/eatthepath/pushy/apns/server/BenchmarkApnsServerBuilder.java b/pushy/src/main/java/com/eatthepath/pushy/apns/server/BenchmarkApnsServerBuilder.java
index 72ab6c2e..f506391f 100644
--- a/pushy/src/main/java/com/eatthepath/pushy/apns/server/BenchmarkApnsServerBuilder.java
+++ b/pushy/src/main/java/com/eatthepath/pushy/apns/server/BenchmarkApnsServerBuilder.java
@@ -57,6 +57,12 @@ public class BenchmarkApnsServerBuilder extends BaseHttp2ServerBuilder<Benchmark
         return this;
     }
 
+    @Override
+    public BenchmarkApnsServerBuilder setServerCredentials(final X509Certificate[] certificates, final PrivateKey privateKey) {
+        super.setServerCredentials(certificates, privateKey);
+        return this;
+    }
+
     @Override
     public BenchmarkApnsServerBuilder setServerCredentials(final X509Certificate[] certificates, final PrivateKey privateKey, final String privateKeyPassword) {
         super.setServerCredentials(certificates, privateKey, privateKeyPassword);
diff --git a/pushy/src/main/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilder.java b/pushy/src/main/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilder.java
index 35259d41..ac24a274 100644
--- a/pushy/src/main/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilder.java
+++ b/pushy/src/main/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilder.java
@@ -62,6 +62,12 @@ public class MockApnsServerBuilder extends BaseHttp2ServerBuilder<MockApnsServer
         return this;
     }
 
+    @Override
+    public MockApnsServerBuilder setServerCredentials(final X509Certificate[] certificates, final PrivateKey privateKey) {
+        super.setServerCredentials(certificates, privateKey);
+        return this;
+    }
+
     @Override
     public MockApnsServerBuilder setServerCredentials(final X509Certificate[] certificates, final PrivateKey privateKey, final String privateKeyPassword) {
         super.setServerCredentials(certificates, privateKey, privateKeyPassword);


Test patch:
diff --git a/pushy/src/test/java/com/eatthepath/pushy/apns/ApnsClientBuilderTest.java b/pushy/src/test/java/com/eatthepath/pushy/apns/ApnsClientBuilderTest.java
index da606a97..4df34a2f 100644
--- a/pushy/src/test/java/com/eatthepath/pushy/apns/ApnsClientBuilderTest.java
+++ b/pushy/src/test/java/com/eatthepath/pushy/apns/ApnsClientBuilderTest.java
@@ -107,6 +107,24 @@ public class ApnsClientBuilderTest {
         }
     }
 
+    @Test
+    void testBuildClientWithCertificateAndUnprotectedKeyNoPassword() throws Exception {
+        // We DO need a password to unlock the keystore, but the key itself should be unprotected
+        try (final InputStream p12InputStream = this.getClass().getResourceAsStream(SINGLE_TOPIC_CLIENT_KEYSTORE_UNPROTECTED_FILENAME)) {
+
+            final PrivateKeyEntry privateKeyEntry =
+                P12Util.getFirstPrivateKeyEntryFromP12InputStream(p12InputStream, KEYSTORE_PASSWORD);
+
+            final ApnsClient client = new ApnsClientBuilder()
+                .setApnsServer(ApnsClientBuilder.PRODUCTION_APNS_HOST)
+                .setEventLoopGroup(EVENT_LOOP_GROUP)
+                .setClientCredentials((X509Certificate) privateKeyEntry.getCertificate(), privateKeyEntry.getPrivateKey())
+                .build();
+
+            client.close().get();
+        }
+    }
+
     @Test
     void testBuildClientWithCertificateAndUnprotectedKey() throws Exception {
         // We DO need a password to unlock the keystore, but the key itself should be unprotected
diff --git a/pushy/src/test/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilderTest.java b/pushy/src/test/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilderTest.java
index 2c30b2a6..99391f1b 100644
--- a/pushy/src/test/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilderTest.java
+++ b/pushy/src/test/java/com/eatthepath/pushy/apns/server/MockApnsServerBuilderTest.java
@@ -78,7 +78,7 @@ public class MockApnsServerBuilderTest {
 
             // We're happy here as long as nothing explodes
             new MockApnsServerBuilder()
-                .setServerCredentials(new X509Certificate[] { (X509Certificate) privateKeyEntry.getCertificate() }, privateKeyEntry.getPrivateKey(), null)
+                .setServerCredentials(new X509Certificate[] { (X509Certificate) privateKeyEntry.getCertificate() }, privateKeyEntry.getPrivateKey())
                     .setHandlerFactory(new AcceptAllPushNotificationHandlerFactory())
                 .build();
         }