Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Push Notification - JavaPNS - keystore.p12 file security
    primarykey
    data
    text
    <p>I am trying to use Apple's Push Notifications. I am using this tutorial here: <a href="http://www.ibm.com/developerworks/java/library/mo-ios-push/#ibm-pcon" rel="nofollow noreferrer">http://www.ibm.com/developerworks/java/library/mo-ios-push/#ibm-pcon</a></p> <p>I am on the part where I am trying to create the Push Notification. The sample code is here: <a href="http://code.google.com/p/javapns/wiki/PushNotificationBasic" rel="nofollow noreferrer">http://code.google.com/p/javapns/wiki/PushNotificationBasic</a> and looks like this:</p> <pre><code>import javapns.Push; public class PushTest { public static void main(String[] args) { Push.alert("Hello World!", "keystore.p12", "keystore_password", false, "Your token"); } } </code></pre> <p>I have everything set up except for the keystore.p12 part. Here is what the documentation says about keystores:</p> <p>Object keystore: a reference to a keystore file, or the actual keystore content. See Preparing certificates for more information about how to create a keystore. You can pass the following objects to this parameter:</p> <ul> <li>java.io.File: a direct pointer to your keystore file</li> <li>java.lang.String: a path to your local keystore file</li> <li>java.io.InputStream: a stream providing the bytes from a keystore</li> <li>byte[]: the actual bytes of a keystore</li> <li>java.security.KeyStore: an actual loaded keystore</li> </ul> <p>I do not simply want to type in the path of the keystore on my computer (as they do here <a href="https://stackoverflow.com/questions/11012191/getting-error-while-sending-push-notification-to-iphone-using-java-pns">Getting error while sending Push Notification to iPhone using Java-PNS?</a>) because I feel like that is unsafe.</p> <p>Which of the objects should I use? My inclination says to use a java.security.KeyStore.</p> <p>As a final note, this code needs to be hosted on Amazon Web Service's Elastic Beanstalk (if that matters).</p> <p><strong>---------Edit 1------------</strong></p> <p>I have tried to put in Richard J. Ross III's code. But before it is possible to learn if my .p12 file setup is correct, I first need to get around an issue concerning JavaPNS (and file structure I believe). Running the code below gives me this error: <code>HTTP Status 404 - Servlet IosSendGameServlet is not available</code>. When I comment out all of the JavaPNS statements, I get this error: <code>HTTP Status 500 - javax.servlet.ServletException: Parameter recievingAppleDeviceID not found.</code> (because I don't put in the parameters) This leads me to believe that there is a problem with the way that JavaPNS is being accessed. Maybe it is in the wrong place in my file structure? It is in the same place as servlet-api (in lib). Perhaps this is a problem with the way I upload to the AWS Elastic Beanstalk server?</p> <pre><code>package com.google.android.gcm.demo.server; import java.io.IOException; import java.io.InputStream; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javapns.Push; //&lt;--gets commented out to receive 500 error import javapns.communication.exceptions.CommunicationException;//&lt;--gets commented out to receive 500 error import javapns.communication.exceptions.KeystoreException;//&lt;--gets commented out to receive 500 error public class IosSendGameServlet extends BaseServlet { @Override public void init(ServletConfig config) throws ServletException { super.init(config); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String recievingAppleDeviceId = getParameter(req, "recievingAppleDeviceID"); String sendingUser = getParameter(req, "sendingUser"); InputStream keyStore = this.getClass().getResourceAsStream("/sasSandbox.p12"); //everything below here gets commented out to receive 500 error try { Push.alert("Game with " + sendingUser + ": It's your turn!", keyStore, "mypassword", false, recievingAppleDeviceId); } catch (CommunicationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeystoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload