Everytime I try to send a notification
Get the following error:
Connection initialized...
Attempt failed... trying again
preclose
in finally
enter code here
java.net.SocketException: Socket is closed
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at ts.javapns.back.PushNotificationManager.sendNotification(PushNotificationManager.java:199)
at org.apache.jsp.japnslist_jsp._jspService(org.apache.jsp.japnslist_jsp:118)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
enter code here
What version of the product are you using? On what operating system? Windows XP, newest version of javaapns
// APNs Server Host & port
String HOST = "gateway.sandbox.push.apple.com";
int PORT = 2195;
// Badge
int BADGE = 6;
// iPhone's UDID (64-char device token)
String iPhoneId = "aebf53cc8d6bfaf47dace40747091fa5b0fc837b...";
String certificate = "C:/webapplication/WEB-INF/cert.p12";
String passwd = "password";
System.out.println( "Setting up Push notification" );
//Set system properties .....
System.setProperty("javax.net.ssl.trustStore", "/var/www/ap开发者_运维问答ns/<apple.keystore>");
System.setProperty("javax.net.ssl.trustStorePassword", "<pass>");
try {
// Setup up a simple message
PayLoad aPayload = new PayLoad();
aPayload.addBadge( BADGE );
System.out.println( "Payload setup successfull." );
System.out.println ( aPayload );
// Get PushNotification Instance
PushNotificationManager pushManager = PushNotificationManager.getInstance();
System.out.println( "Linking iPhone's UDID (64-char device token) to stringName" );
// Link iPhone's UDID (64-char device token) to a stringName
pushManager.addDevice("iPhone", iPhoneId);
System.out.println( "iPhone UDID taken." );
System.out.println("Token:"+pushManager.getDevice("iPhone").getToken());
// Get iPhone client
Device client = pushManager.getDevice( "iPhone" );
System.out.println( "Client setup successfull." );
// Initialize connection
pushManager.initializeConnection( HOST, PORT, certificate, passwd, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
System.out.println( "Connection initialized..." );
// Send message
pushManager.sendNotification( client, aPayload );
System.out.println( "Message sent!" );
//Remove device
pushManager.removeDevice(iPhoneId);
System.out.println( "Removing Device" );
System.out.println("# of attempts:" + pushManager.getRetryAttempts() );
pushManager.stopConnection();
System.out.println( "done" );
} catch (Exception e) {
e.printStackTrace();
}
As far as I can tell I am having an issue at this point in PushNotificationManager.java file
Function: public void sendNotification(Device device, PayLoad payload)
at this line of sendNotification: this.socket.getOutputStream().write(getMessage(device.getToken(), new PayLoad() ));
Socket is closed but I do not know why it would be?
Please help.
JavaPNS was recently updated to 2.0, and fixed ALL reported issues up to the release date. It does fix the issue you are describing.
Sylvain
Don't we have to specify the sanbox server for development or production server for the AdHoc?
精彩评论