{"issue":{"title":"Recently started getting this error","milestone":null,"user":{"id":471445,"login":"amathias","url":"https://api.github.com/users/amathias","avatar_url":"https://secure.gravatar.com/avatar/43b28891f9a81982d03dd2fc5d31944c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"43b28891f9a81982d03dd2fc5d31944c"},"created_at":"2011-12-09T22:04:41Z","labels":[],"state":"open","updated_at":"2011-12-16T15:03:59Z","id":2507586,"html_url":"https://github.com/notnoop/java-apns/issues/63","pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"closed_at":null,"body":"Some background:\r\n\r\nHere is how my code sends the APNS notification:\r\n\r\nApnsService service = serviceBuilder.build();\r\n\r\n\t\tservice.start();\r\n\t\t\r\n\t\tPayloadBuilder pB = com.notnoop.apns.APNS.newPayload().alertBody(message).badge(badgeCount);\r\n\t\t\r\n\t\tif(!NO_SOUND.equalsIgnoreCase(sound)) {\r\n\t\t\tpB.sound(sound);\r\n\t\t}\r\n\t\t\r\n\t\tString payload =\r\n\t\t    pB.build();\r\n\t\t\r\n\t\tlogger.info(\"Attempting to send APNS payload : \" + payload.toString());\r\n\r\n\t\tfor(String token : tokens) {\r\n\r\n\t\t\tservice.push(token, payload);\r\n\t\t}\r\n\t\tdeleteInactiveDevices(service); // custom method\r\n\t\tservice.stop();  // this is when the stack trace happens, stack trace is shown below\r\n\r\nThe notification reaches my phone successfully however I get the following error:\r\n\r\n\r\n(com.notnoop.apns.internal.ApnsConnectionImpl$1MonitoringThread:112) WARN  Exception while waiting for error code\r\njava.net.SocketException: socket closed\r\n\tat java.net.SocketInputStream.socketRead0(Native Method)\r\n\tat java.net.SocketInputStream.read(SocketInputStream.java:129)\r\n\tat com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)\r\n\tat com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)\r\n\tat com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)\r\n\tat com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)\r\n\tat com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)\r\n\tat java.io.InputStream.read(InputStream.java:85)\r\n\tat com.notnoop.apns.internal.ApnsConnectionImpl$1MonitoringThread.run(ApnsConnectionImpl.java:102)\r\n\r\nAgain, as described in the commented code above, this error happens when I attempt to stop the service. It seems to be waiting on an error code. I think that I'm getting an error from Apple and im not handling it appropriately, but am not sure what to do. Is there something I am missing ?\r\n\r\n(and obviously I know that i should not be starting and stopping the service for a single notification, but this is for testing)\r\n\r\n\r\n\r\n\r\nSecond issue:\r\n\r\nAlso, when i use this code on my company's website I get the following error:\r\n\r\nat com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:268)\r\n\tat com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:173)\r\n\tat com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)\r\n\tat com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)\r\n\tat com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)\r\n\tat com.omeda.mobile.APNS.sendAPNSNotification(APNS.java:124)\r\n\tat com.omeda.system.OperationsController.sendApnsNotification(OperationsController.java:1034)\r\n\tat org.apache.jsp.operations.appsettings.APNSTester_jsp._jspService(APNSTester_jsp.java:352)\r\n\tat org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\r\n\tat org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)\r\n\tat org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)\r\n\tat org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat com.omeda.portal.security.SecurityFilter.doFilter(SecurityFilter.java:101)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)\r\n\tat org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)\r\n\tat org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)\r\n\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)\r\n\tat java.lang.Thread.run(Thread.java:662)\r\nCaused by: java.net.SocketException: Connection reset\r\n\tat java.net.SocketInputStream.read(SocketInputStream.java:168)\r\n\tat com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)\r\n\tat com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)\r\n\tat com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:830)\r\n\tat com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)\r\n\tat com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:637)\r\n\tat com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:88)\r\n\tat java.io.OutputStream.write(OutputStream.java:58)\r\n\tat com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:161)\r\n\r\nThe socket gets reset, the 3 way handshake is performed, then nothing happens. Does anything stick out in this ?\r\n\r\nPlease if you know a solution post or email me at amathias@omeda.com. I am very worried about this and looking forward to a solution. I am using the jar file from this page which says it was last updated August, 2010 which has me worried, it was updated so long ago.","number":63,"url":"https://api.github.com/repos/notnoop/java-apns/issues/63","comments":5,"assignee":null},"comment":{"user":{"id":783663,"login":"Mopper","url":"https://api.github.com/users/Mopper","avatar_url":"https://secure.gravatar.com/avatar/e535c0fff924484aa95c2f4a683a38b2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"e535c0fff924484aa95c2f4a683a38b2"},"created_at":"2011-12-16T15:03:59Z","updated_at":"2011-12-16T15:03:59Z","id":3178120,"body":"The best way would be to implement ApnsDelegate and pass it to ApnsServiceBuilder.withDelegate(). The connectionClosed() and messageSendFailed() methods are the ones you should be interested in here. ","url":"https://api.github.com/repos/notnoop/java-apns/issues/comments/3178120"},"action":"created"}