質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

SMS

SMS(Short Message Service)は電話、ウェブやモバイルのコミュニケーションシステムで規格化されたテキストのコミュニケーションサービスです。固定回線間や携帯電話間で短い文章のやりとりをすることを可能にしています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

0回答

413閲覧

amazonSNS 送信ステータス取得について。

bigi_java

総合スコア10

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

SMS

SMS(Short Message Service)は電話、ウェブやモバイルのコミュニケーションシステムで規格化されたテキストのコミュニケーションサービスです。固定回線間や携帯電話間で短い文章のやりとりをすることを可能にしています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2018/11/30 05:31

編集2018/11/30 05:35

amazonSNSを利用してSMSを送信するシステムを作っています。
送信することはかないまいしたが、配信失敗時のエラーをcatchすることができず、調べたところcloudwatchというサービスからJson形式の配信ステータスを取得できるようです。

Java

1 /** 2 * SMS送信 3 * @param customerId 顧客ID 4 * @param agreementNo 同意情報NO 5 * @param telephon 電話番号 6 * @return      検索結果のHTML 7 * @throws Exception 8 */ 9 @POST 10 @GET 11 @Path("sms") 12 @Consumes({ "application/json"}) 13 @Produces({ "application/json; charset=UTF-8" }) 14 //public RestApiResponse smssend(@PathParam("customerId") String customerId, SendSmsForm form, Long agreementNo) throws Exception{ 15 public RestApiResponse authenticate (@PathParam("customerId")String customerId, String Telephone) throws Exception { 16 17 18 RestApiResponse result = new RestApiResponse(); 19 String Message = reloadableConfig.getString("message"); 20 String Time = reloadableConfig.getString("time"); 21 int Count = reloadableConfig.getInt("count"); 22 int smsflag; 23 int i = Count; 24 25 if(Telephone == null){ 26 // パラメータなし → エラー 27 result.setNG("The phone number isn't input yet."); 28 return result; // 結果を返却 29 } 30 31 try { 32 33 String telephone = null; 34 String test = null; 35 /*メッセージ内容*/ 36 37 JSONObject json = new JSONObject(Telephone); 38 telephone = json.getString("Telephone"); 39 System.out.println(telephone); 40 if(telephone.length() == 0){ 41 result.setNG("The phone number isn't input yet."); 42 return result; // 結果を返却 43 } 44 45 String message = Message;//reloadable.properties参照 46 String phoneNumber = "+1" + telephone;//固定の"+1"を付ける 47 System.out.println(message); 48 System.out.println(phoneNumber); 49 Map<String, MessageAttributeValue> smsAttributes = 50 new HashMap<String, MessageAttributeValue>(); 51 //<set SMS attributes> 52 53 String status = sendSMSMessage(snsClient, message, phoneNumber, smsAttributes); 54 if (status == "FAILURE"){ 55 result.setNG("Sending the message is failed."); 56 return result; 57 } 58 59 60 result.setOK(); 61 smsflag = 1; 62 agreementService.smsupdate(smsflag,telephone); 63 }catch(Exception e){ 64 //result.setNG("Sending the message is failed."); 65 System.out.println(e.getMessage()); 66 } 67 68 return result; 69 } 70 71 public static String sendSMSMessage(AmazonSNSClient snsClient, String message, 72 String phoneNumber, Map<String, MessageAttributeValue> smsAttributes) { 73 74 try{ 75 PublishResult result = snsClient.publish(new PublishRequest() 76 .withMessage(message) 77 .withPhoneNumber(phoneNumber) 78 .withMessageAttributes(smsAttributes)); 79 System.out.println(result); // Prints the message ID. 80 String id = result.getMessageId(); 81 System.out.println(id); 82 int statusCode = result .getSdkHttpMetadata().getHttpStatusCode(); 83 System.out.println(statusCode); 84 ResponseMetadata response = result.getSdkResponseMetadata(); 85 System.out.println(response); 86 87 SetPlatformApplicationAttributesRequest setPlatformApplicationAttributesRequest = new SetPlatformApplicationAttributesRequest(); 88 Map<String, String> attributes = new HashMap<>(); 89 attributes.put("SuccessFeedbackRoleArn", "arn:aws:iam::111122223333:role/SNS_CWlogs"); 90 attributes.put("FailureFeedbackRoleArn", "arn:aws:iam::111122223333:role/SNS_CWlogs"); 91 attributes.put("SuccessFeedbackSampleRate", "5"); 92 attributes.put("MessageID", id); 93 setPlatformApplicationAttributesRequest.withAttributes(attributes); 94 System.out.println(attributes); 95 setPlatformApplicationAttributesRequest.setPlatformApplicationArn("arn:aws:sns:us-west-2:111122223333:app/GCM/GCMPushApp"); 96 SetPlatformApplicationAttributesResult res = snsClient.setPlatformApplicationAttributes(setPlatformApplicationAttributesRequest); 97 ResponseMetadata obj = res.getSdkResponseMetadata(); 98 99 String status = null; 100 JSONObject json = new JSONObject(obj); 101 status = json.getString("status"); 102 System.out.println(status);

上記太字の部分を追加し、指定したメッセージの配信ステータスを取得したいのですが取得することが出来ません。
有識者の方、ご教授いただけないでしょうか。
使用言語はJavaです。
宜しくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yukkuri

2018/12/15 01:51 編集

すいません、上記太字の部分、とはどこでしょうか。ソースにコメントとかで追加してください。あと、このコードではtryのしたにcatchがない部分があるので、おそらく動きません。また、tryの後は一つインデントをしてください。ifなどと混じって読みにくいです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問