1

using notnoop / java-apns https://github.com/notnoop/java-apns I'm using this code to send message:

try {
ApnsService service = APNS
.newService()
.withCert("myCertificates.p12",
"xxxxxxxxxx").withProductionDestination().build();

        String payload = APNS.newPayload().alertBody(messageObject.MsgText)
                .sound("default").badge(1).build();

        Iterator<String> vItr = messageObject.addresses.iterator();
        while (vItr.hasNext()) {
            String sent2Token = (String) (vItr.next());

            service.push(sent2Token, payload);
        }
        service.stop();

    } catch (NetworkIOException e) {
        System.out.println("client>> " + e.getMessage());
        e.printStackTrace();
    }

message is sent fine, but need to get red of this output, because it might slow my program beside it taking space .... please advice?

16:07:56.206 [Thread-4140] INFO c.n.apns.internal.ApnsConnectionImpl - Exception while waiting for error code
java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_05]
at java.net.SocketInputStream.read(SocketInputStream.java:150) ~[na:1.7.0_05]
at java.net.SocketInputStream.read(SocketInputStream.java:121) ~[na:1.7.0_05]
at sun.security.ssl.InputRecord.readFully(InputRecord.java:312) ~[na:1.7.0_05]
at sun.security.ssl.InputRecord.read(InputRecord.java:350) ~[na:1.7.0_05]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893) ~[na:1.7.0_05]
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:850) ~[na:1.7.0_05]
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) ~[na:1.7.0_05]
at java.io.InputStream.read(InputStream.java:101) ~[na:1.7.0_05]
at com.notnoop.apns.internal.ApnsConnectionImpl$1MonitoringThread.run(ApnsConnectionImpl.java:122) ~[server.jar:na]
user836026
  • 10,608
  • 15
  • 73
  • 129
  • Are you sure the message is sent fine? Do all the messages reach the devices? This log suggests that a `SocketException` was thrown while attempting to read the error response from Apple. Unless it's a timeout exception (in which case there's no problem), the socket was probably closed by Apple, which indicates you sent some invalid data to the APNS server (the most often cause for this is sending invalid device tokens). – Eran May 02 '13 at 20:52
  • yes Eran, message is sent. – user836026 May 02 '13 at 20:57
  • Are you sending one message or multiple messages? If multiple messages, are you sending them all to the same device or to different devices? If multiple devices, do all of the messages reach the devices or just some of them? – Eran May 02 '13 at 21:07
  • in this case i'm sending to one device and it reach the device. – user836026 May 02 '13 at 22:04
  • Then you should use questions like [this one](http://stackoverflow.com/questions/2372056/how-to-turn-off-logging-from-slf4j) to figure out how to disable (or at least reduce) the log output. – Eran May 02 '13 at 22:19

1 Answers1

1

To resurrect a year old question:

Until recently java-apns logged an exception when the connection with the apns service was closed. You should do two things:

  • Use java-apns 1.0.0 Beta2 (available on maven central) which does not log that exception
  • Normally you'd keep the built ApnsService around during the runtime of your server as setting up and closing down the SSL connection is a little expensive. So only close it if you're sure that you won't send another connection for a long time. ApnsService mantains a live connection with the Apple's push server.
froh42
  • 5,190
  • 6
  • 30
  • 42