Apple のプッシュ通知を使用しようとしています。ここでこのチュートリアルを使用しています: http://www.ibm.com/developerworks/java/library/mo-ios-push/#ibm-pcon
プッシュ通知を作成しようとしているところです。サンプル コードは http://code.google.com/p/javapns/wiki/PushNotificationBasicで、次のようになります。
import javapns.Push;
public class PushTest {
public static void main(String[] args) {
Push.alert("Hello World!", "keystore.p12", "keystore_password", false, "Your token");
}
}
keystore.p12 部分を除いて、すべてをセットアップしました。キーストアに関するドキュメントの内容は次のとおりです。
オブジェクト キーストア: キーストア ファイルへの参照、または実際のキーストア コンテンツ。鍵ストアの作成方法について詳しくは、証明書の準備を参照してください。このパラメーターには、次のオブジェクトを渡すことができます。
- java.io.File: キーストア ファイルへの直接ポインタ
- java.lang.String: ローカル キーストア ファイルへのパス
- java.io.InputStream: キーストアからのバイトを提供するストリーム
- byte[]: キーストアの実際のバイト
- java.security.KeyStore: 実際にロードされたキーストア
自分のコンピューターのキーストアのパスを単純に入力したくはありません ( Java-PNS を使用してプッシュ通知を iPhone に送信中にエラーが発生しましたか? )。
どのオブジェクトを使用すればよいですか? 私の傾向は、java.security.KeyStore を使用することです。
最後に、このコードは Amazon Web Service の Elastic Beanstalk でホストする必要があります (それが重要な場合)。
---------編集1------------
Richard J. Ross III のコードを入れてみました。しかし、自分の .p12 ファイルのセットアップが正しいかどうかを知る前に、JavaPNS (および私が信じているファイル構造) に関する問題を回避する必要があります。以下のコードを実行すると、次のエラーが表示されます: HTTP Status 404 - Servlet IosSendGameServlet is not available
. すべての JavaPNS ステートメントをコメントアウトすると、次のエラーが表示されます: HTTP Status 500 - javax.servlet.ServletException: Parameter recievingAppleDeviceID not found.
(パラメーターを入力していないため) JavaPNS へのアクセス方法に問題があると思われます。ファイル構造の間違った場所にあるのではないでしょうか? servlet-api と同じ場所にあります (lib 内)。これは、AWS Elastic Beanstalk サーバーにアップロードする方法に問題があるのでしょうか?
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; //<--gets commented out to receive 500 error
import javapns.communication.exceptions.CommunicationException;//<--gets commented out to receive 500 error
import javapns.communication.exceptions.KeystoreException;//<--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();
}
}
}