Search code examples
apple-push-notificationsfirewalliptables

Server side APNs push notification behind proxy


I need to send push notification using a control panel from server.

The server is a Linux virtual Cloud box which is behind a proxy. The control panel is designed using J2EE with Tomcat

I am using JAVA based https://github.com/notnoop/java-apns/releases API for push

The code

ApnsService service = APNS.newService().withSandboxDestination().withCert("mycert.p12", "mypassword").build();
String messageTobeSent = APNS.newPayload()
    .alertBody("Message with badge 2")
    .badge(2)
    .alertTitle("Message with badge 2")
    .sound("ding.wav")
    .build();
service.push("d81f0080ed7bf05ac96261dc1805fbf00230073f606f1388a644469b1893446f",  messageTobeSent, new Date());

I am getting an error Couldn't connect to APNS server, My Questions are

  1. Is this because of the proxy?
  2. Does APNs works with proxy?
  3. Will this library capable or connecting behind proxy?

Solution

  • Answering your 3rd Question which will solve the first two questions regardlessly. NotNoop Java-Apns definitely supports proxy.

    Refer the Java Doc provided ApnsServiceBuilder withProxy(java.net.Proxy)

    Specify the proxy to be used to establish the connections to Apple Servers

    In your code you can put as following

    ApnsService service = APNS
    .newService()
    .withSandboxDestination()
    .withProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("<your proxy host>", <your proxy port>)))
    .build();
    

    Now the library itself will connect via proxy