Class MockApnsServerBuilder

java.lang.Object
com.eatthepath.pushy.apns.server.MockApnsServerBuilder

public class MockApnsServerBuilder
extends Object

A MockApnsServerBuilder constructs new MockApnsServer instances. Callers must supply server credentials via one of the setServerCredentials methods and supply a PushNotificationHandlerFactory prior to constructing a new server with the build() method; all other settings are optional.

Server builders may be reused to generate multiple servers, and their settings may be changed from one server to the next.

Since:
0.8
Author:
Jon Chambers
  • Field Details

    • DEFAULT_MAX_CONCURRENT_STREAMS

      public static final int DEFAULT_MAX_CONCURRENT_STREAMS
      The default maximum number of concurrent streams for an APNs server, which matches the default limit set by the real APNs server at the time of this writing.
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • setServerCredentials

      public MockApnsServerBuilder setServerCredentials​(File certificatePemFile, File privateKeyPkcs8File, String privateKeyPassword)

      Sets the credentials for the server under construction using the certificates in the given PEM file and the private key in the given PKCS#8 file.

      Parameters:
      certificatePemFile - a PEM file containing the certificate chain for the server under construction
      privateKeyPkcs8File - a PKCS#8 file containing the private key for the server under construction
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setServerCredentials

      public MockApnsServerBuilder setServerCredentials​(InputStream certificatePemInputStream, InputStream privateKeyPkcs8InputStream, String privateKeyPassword)

      Sets the credentials for the server under construction using the certificates in the given PEM input stream and the private key in the given PKCS#8 input stream.

      Parameters:
      certificatePemInputStream - a PEM input stream containing the certificate chain for the server under construction
      privateKeyPkcs8InputStream - a PKCS#8 input stream containing the private key for the server under construction
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setServerCredentials

      public MockApnsServerBuilder setServerCredentials​(X509Certificate[] certificates, PrivateKey privateKey, String privateKeyPassword)

      Sets the credentials for the server under construction.

      Parameters:
      certificates - a certificate chain including the server's own certificate
      privateKey - the private key for the server's certificate
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setTrustedClientCertificateChain

      public MockApnsServerBuilder setTrustedClientCertificateChain​(File certificatePemFile)

      Sets the trusted certificate chain for the server under construction using the contents of the given PEM file. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificatePemFile - a PEM file containing one or more trusted certificates
      Returns:
      a reference to this builder
    • setTrustedClientCertificateChain

      public MockApnsServerBuilder setTrustedClientCertificateChain​(InputStream certificateInputStream)

      Sets the trusted certificate chain for the server under construction using the contents of the given PEM input stream. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificateInputStream - an input stream to PEM-formatted data containing one or more trusted certificates
      Returns:
      a reference to this builder
    • setTrustedServerCertificateChain

      public MockApnsServerBuilder setTrustedServerCertificateChain​(X509Certificate... certificates)

      Sets the trusted certificate chain for the server under construction. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificates - one or more trusted certificates
      Returns:
      a reference to this builder
    • setEventLoopGroup

      public MockApnsServerBuilder setEventLoopGroup​(EventLoopGroup eventLoopGroup)

      Sets the event loop group to be used by the server under construction. If not set (or if null), the server will create and manage its own event loop group.

      Parameters:
      eventLoopGroup - the event loop group to use for this server, or null to let the server manage its own event loop group
      Returns:
      a reference to this builder
    • setMaxConcurrentStreams

      public MockApnsServerBuilder setMaxConcurrentStreams​(int maxConcurrentStreams)
      Sets the maximum number of concurrent HTTP/2 streams allowed by the server under construction. By default, mock servers will have a concurrent stream limit of 1500.
      Parameters:
      maxConcurrentStreams - the maximum number of concurrent HTTP/2 streams allowed by the server under construction; must be positive
      Returns:
      a reference to this builder
    • setUseAlpn

      public MockApnsServerBuilder setUseAlpn​(boolean useAlpn)

      Sets whether the server under construction should use ALPN. By default, mock servers do not use ALPN and instead require clients to use direct negotiation.

      Note that Pushy itself does not require (or even use) ALPN and always uses direct protocol negotiation. ALPN is only useful in cases where Pushy's mock server is being used with a non-Pushy APNs client.

      Note also that turning on ALPN support may introduce new system requirements for the mock server. Prior to version 9, Java does not include support for ALPN, and so it will need to be provided by thid-party software such as the Jetty ALPN agent or Netty's netty-tcnative package.

      Parameters:
      useAlpn - true to enable ALPN support, or false to require direct protocol negotiation
      Returns:
      a reference to this builder
      See Also:
      Jetty ALPN Agent, netty-tcnative
    • setHandlerFactory

      public MockApnsServerBuilder setHandlerFactory​(PushNotificationHandlerFactory handlerFactory)
      Sets the handler factory to be used to construct push notification handlers for the server under construction. Servers require a handler factory.
      Parameters:
      handlerFactory - the handler factory to be used by the server under construction
      Returns:
      a reference to this builder
      Since:
      0.12
    • setListener

      public MockApnsServerBuilder setListener​(MockApnsServerListener listener)
      Sets the listener to be notified when notifications are accepted or rejected by the server under construction. If not set or if null, the server will not notify a listener when notifications are accepted or rejected.
      Parameters:
      listener - the listener to be used by the server under construction
      Returns:
      a reference to this builder
      Since:
      0.12
    • build

      public MockApnsServer build() throws SSLException
      Constructs a new server with the previously-set configuration.
      Returns:
      a new server instance with the previously-set configuration
      Throws:
      SSLException - if an SSL context could not be created for the new server for any reason