Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MIM and MOBO

  • Loading branch information...
commit 5ea403f10c70f6cf41532fd5706fb919e3e63743 1 parent 52be021
attdevsupport authored
Showing with 10,967 additions and 0 deletions.
  1. +233 −0 MIM/Csharp/app1/Default.aspx
  2. +1,105 −0 MIM/Csharp/app1/Default.aspx.cs
  3. +35 −0 MIM/Csharp/app1/MSRestfulV2_1_CsharpMIMApp1.sln
  4. +102 −0 MIM/Csharp/app1/README.txt
  5. +37 −0 MIM/Csharp/app1/Web.config
  6. BIN  MIM/Csharp/app1/images/Thumbs.db
  7. BIN  MIM/Csharp/app1/images/att.gif
  8. +39 −0 MIM/Csharp/app1/style/common.css
  9. +3 −0  MIM/Java/app1/META-INF/MANIFEST.MF
  10. +531 −0 MIM/Java/app1/MIM.jsp
  11. +89 −0 MIM/Java/app1/README.txt
  12. BIN  MIM/Java/app1/WEB-INF/.DS_Store
  13. BIN  MIM/Java/app1/WEB-INF/classes/com/att/rest/HttpMethod.class
  14. +11 −0 MIM/Java/app1/WEB-INF/classes/com/att/rest/HttpMethod.java
  15. BIN  MIM/Java/app1/WEB-INF/classes/com/att/rest/RestClient.class
  16. +157 −0 MIM/Java/app1/WEB-INF/classes/com/att/rest/RestClient.java
  17. BIN  MIM/Java/app1/WEB-INF/lib/.DS_Store
  18. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-benchmark-0.7.2-javadoc.jar
  19. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-benchmark-0.7.2-sources.jar
  20. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-benchmark-0.7.2.jar
  21. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-core-0.7.2-javadoc.jar
  22. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-core-0.7.2-sources.jar
  23. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-core-0.7.2-tests.jar
  24. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-core-0.7.2.jar
  25. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-dom-0.7.2-javadoc.jar
  26. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-dom-0.7.2-sources.jar
  27. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-dom-0.7.2.jar
  28. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-examples-0.7.2-javadoc.jar
  29. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-examples-0.7.2-sources.jar
  30. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-examples-0.7.2.jar
  31. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-storage-0.7.2-javadoc.jar
  32. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-storage-0.7.2-sources.jar
  33. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-storage-0.7.2-tests.jar
  34. BIN  MIM/Java/app1/WEB-INF/lib/apache-mime4j-storage-0.7.2.jar
  35. BIN  MIM/Java/app1/WEB-INF/lib/commons-codec-1.4.jar
  36. BIN  MIM/Java/app1/WEB-INF/lib/commons-codec-1.5.jar
  37. BIN  MIM/Java/app1/WEB-INF/lib/commons-fileupload-1.2.2.jar
  38. BIN  MIM/Java/app1/WEB-INF/lib/commons-httpclient-3.0.1.jar
  39. BIN  MIM/Java/app1/WEB-INF/lib/commons-io-1.4.jar
  40. BIN  MIM/Java/app1/WEB-INF/lib/commons-io-2.3.jar
  41. BIN  MIM/Java/app1/WEB-INF/lib/commons-logging-1.1.1.jar
  42. BIN  MIM/Java/app1/WEB-INF/lib/httpclient-4.1.2.jar
  43. BIN  MIM/Java/app1/WEB-INF/lib/httpclient-cache-4.1.2.jar
  44. BIN  MIM/Java/app1/WEB-INF/lib/httpcore-4.1.2.jar
  45. BIN  MIM/Java/app1/WEB-INF/lib/httpcore-4.2.1.jar
  46. BIN  MIM/Java/app1/WEB-INF/lib/httpcore-ab-4.2.1.jar
  47. BIN  MIM/Java/app1/WEB-INF/lib/httpcore-nio-4.2.1.jar
  48. BIN  MIM/Java/app1/WEB-INF/lib/httpmime-4.1.2.jar
  49. BIN  MIM/Java/app1/WEB-INF/lib/jersey-client.jar
  50. BIN  MIM/Java/app1/WEB-INF/lib/jersey-core.jar
  51. BIN  MIM/Java/app1/WEB-INF/lib/jersey-multipart.jar
  52. BIN  MIM/Java/app1/WEB-INF/lib/json-rpc-1.0.jar
  53. +14 −0 MIM/Java/app1/config.jsp
  54. BIN  MIM/Java/app1/images/.DS_Store
  55. BIN  MIM/Java/app1/images/att.gif
  56. +172 −0 MIM/Java/app1/oauth.jsp
  57. +39 −0 MIM/Java/app1/style/common.css
  58. +96 −0 MIM/PHP/app1/README.txt
  59. +14 −0 MIM/PHP/app1/config.php
  60. +41 −0 MIM/PHP/app1/images/.svn/entries
  61. +1 −0  MIM/PHP/app1/images/.svn/format
  62. +5 −0 MIM/PHP/app1/images/.svn/prop-base/att.gif.svn-base
  63. BIN  MIM/PHP/app1/images/.svn/text-base/att.gif.svn-base
  64. BIN  MIM/PHP/app1/images/att.gif
  65. +531 −0 MIM/PHP/app1/index.php
  66. +40 −0 MIM/PHP/app1/style/.svn/entries
  67. +1 −0  MIM/PHP/app1/style/.svn/format
  68. +39 −0 MIM/PHP/app1/style/.svn/text-base/common.css.svn-base
  69. +39 −0 MIM/PHP/app1/style/common.css
  70. +117 −0 MIM/Ruby/app1/README
  71. +62 −0 MIM/Ruby/app1/common.rb
  72. +5 −0 MIM/Ruby/app1/config.yml
  73. +113 −0 MIM/Ruby/app1/mim.rb
  74. BIN  MIM/Ruby/app1/public/images/att.gif
  75. +39 −0 MIM/Ruby/app1/public/style/common.css
  76. +342 −0 MIM/Ruby/app1/views/mim.erb
  77. +232 −0 MIM/Vb/app1/Default.aspx
  78. +1,050 −0 MIM/Vb/app1/Default.aspx.vb
  79. +35 −0 MIM/Vb/app1/MSRestfulV2_1_VbMIMApp1.sln
  80. +102 −0 MIM/Vb/app1/README.txt
  81. +37 −0 MIM/Vb/app1/Web.config
  82. BIN  MIM/Vb/app1/images/Thumbs.db
  83. BIN  MIM/Vb/app1/images/att.gif
  84. +39 −0 MIM/Vb/app1/style/common.css
  85. +1 −0  MMS/Ruby/app2/mms2.rb
  86. +189 −0 MOBO/Csharp/app1/Default.aspx
  87. +1,159 −0 MOBO/Csharp/app1/Default.aspx.cs
  88. +35 −0 MOBO/Csharp/app1/MSRestfulV2_1_CsharpMoboApp1.sln
  89. +106 −0 MOBO/Csharp/app1/README.txt
  90. +42 −0 MOBO/Csharp/app1/Web.config
  91. BIN  MOBO/Csharp/app1/images/Thumbs.db
  92. BIN  MOBO/Csharp/app1/images/att.gif
  93. +39 −0 MOBO/Csharp/app1/style/common.css
  94. +3 −0  MOBO/Java/app1/META-INF/MANIFEST.MF
  95. +482 −0 MOBO/Java/app1/MOBO.jsp
  96. +89 −0 MOBO/Java/app1/README.txt
  97. BIN  MOBO/Java/app1/WEB-INF/.DS_Store
  98. BIN  MOBO/Java/app1/WEB-INF/classes/com/att/rest/HttpMethod.class
  99. +11 −0 MOBO/Java/app1/WEB-INF/classes/com/att/rest/HttpMethod.java
  100. BIN  MOBO/Java/app1/WEB-INF/classes/com/att/rest/RestClient.class
  101. +157 −0 MOBO/Java/app1/WEB-INF/classes/com/att/rest/RestClient.java
  102. BIN  MOBO/Java/app1/WEB-INF/lib/.DS_Store
  103. BIN  MOBO/Java/app1/WEB-INF/lib/commons-codec-1.5.jar
  104. BIN  MOBO/Java/app1/WEB-INF/lib/commons-fileupload-1.2.2.jar
  105. BIN  MOBO/Java/app1/WEB-INF/lib/commons-httpclient-3.0.1.jar
  106. BIN  MOBO/Java/app1/WEB-INF/lib/commons-io-1.4.jar
  107. BIN  MOBO/Java/app1/WEB-INF/lib/commons-logging-1.1.1.jar
  108. BIN  MOBO/Java/app1/WEB-INF/lib/dsn.jar
  109. BIN  MOBO/Java/app1/WEB-INF/lib/imap.jar
  110. BIN  MOBO/Java/app1/WEB-INF/lib/jersey-client.jar
  111. BIN  MOBO/Java/app1/WEB-INF/lib/jersey-core.jar
  112. BIN  MOBO/Java/app1/WEB-INF/lib/jersey-multipart.jar
  113. BIN  MOBO/Java/app1/WEB-INF/lib/json-rpc-1.0.jar
  114. BIN  MOBO/Java/app1/WEB-INF/lib/mailapi.jar
  115. BIN  MOBO/Java/app1/WEB-INF/lib/pop3.jar
  116. BIN  MOBO/Java/app1/WEB-INF/lib/smtp.jar
  117. +14 −0 MOBO/Java/app1/config.jsp
  118. BIN  MOBO/Java/app1/images/att.gif
  119. +179 −0 MOBO/Java/app1/oauth.jsp
  120. +39 −0 MOBO/Java/app1/style/common.css
  121. BIN  MOBO/PHP/app1/.DS_Store
  122. +95 −0 MOBO/PHP/app1/README.txt
  123. +14 −0 MOBO/PHP/app1/config.php
  124. +41 −0 MOBO/PHP/app1/images/.svn/entries
  125. +1 −0  MOBO/PHP/app1/images/.svn/format
  126. +5 −0 MOBO/PHP/app1/images/.svn/prop-base/att.gif.svn-base
  127. BIN  MOBO/PHP/app1/images/.svn/text-base/att.gif.svn-base
  128. BIN  MOBO/PHP/app1/images/att.gif
  129. +566 −0 MOBO/PHP/app1/index.php
  130. +40 −0 MOBO/PHP/app1/style/.svn/entries
  131. +1 −0  MOBO/PHP/app1/style/.svn/format
  132. +39 −0 MOBO/PHP/app1/style/.svn/text-base/common.css.svn-base
  133. +40 −0 MOBO/PHP/app1/style/common.css
  134. +117 −0 MOBO/Ruby/app1/README
  135. +47 −0 MOBO/Ruby/app1/common.rb
  136. +5 −0 MOBO/Ruby/app1/config.yml
  137. +192 −0 MOBO/Ruby/app1/mobo.rb
  138. BIN  MOBO/Ruby/app1/public/images/att.gif
  139. +40 −0 MOBO/Ruby/app1/public/style/common.css
  140. +219 −0 MOBO/Ruby/app1/views/mobo.erb
  141. +190 −0 MOBO/Vb/app1/Default.aspx
  142. +1,001 −0 MOBO/Vb/app1/Default.aspx.vb
  143. +35 −0 MOBO/Vb/app1/MSRestfulV2_1_VbMoboApp1.sln
  144. +106 −0 MOBO/Vb/app1/README.txt
  145. +42 −0 MOBO/Vb/app1/Web.config
  146. BIN  MOBO/Vb/app1/images/Thumbs.db
  147. BIN  MOBO/Vb/app1/images/att.gif
  148. +39 −0 MOBO/Vb/app1/style/common.css
View
233 MIM/Csharp/app1/Default.aspx
@@ -0,0 +1,233 @@
+<!--
+Licensed by AT&T under 'Software Development Kit Tools Agreement.' 2012
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/
+Copyright 2012 AT&T Intellectual Property. All rights reserved. http://developer.att.com
+For more information contact developer.support@att.com
+-->
+
+<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MIM_App1"
+ ValidateRequest="false" EnableEventValidation="false" ViewStateEncryptionMode="Never"
+ EnableViewStateMac="false" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+ <title>AT&amp;T Sample MIM Application 1- Sample MIM Service Application</title>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ <link rel="stylesheet" type="text/css" href="style/common.css" />
+</head>
+<body>
+ <form id="form1" runat="server">
+ <div id="container">
+ <!-- open HEADER -->
+ <div id="header">
+ <div>
+ <div class="hcLeft">
+ Server Time:</div>
+ <div class="hcRight">
+ <asp:Label ID="lblServerTime" runat="server" Text="Label"></asp:Label>
+ </div>
+ </div>
+ <div>
+ <div class="hcLeft">
+ Client Time:</div>
+ <div class="hcRight">
+ <script language="JavaScript" type="text/javascript">
+ var myDate = new Date();
+ document.write(myDate);
+ </script>
+ </div>
+ </div>
+ <div>
+ <div class="hcLeft">
+ User Agent:</div>
+ <div class="hcRight">
+ <script language="JavaScript" type="text/javascript">
+ document.write("" + navigator.userAgent);
+ </script>
+ </div>
+ </div>
+ <br style="clear: both;" />
+ </div>
+ <!-- close HEADER -->
+ <div class="wrapper">
+ <div class="content">
+ <h1>
+ AT&amp;T Sample MIM Application 1 - Basic MIM Service Application</h1>
+ <h2>
+ Feature 1: Get Message Header(s)</h2>
+ </div>
+ </div>
+ <br />
+ <br />
+ <div class="navigation">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td style="width: 20%" valign="middle" class="label">
+ Header Count:
+ </td>
+ <td class="cell">
+ <asp:TextBox runat="server" ID="txtHeaderCount" Width="20%" MaxLength="3"></asp:TextBox>
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 20%" valign="middle" class="label">
+ Index Cursor:
+ </td>
+ <td class="cell">
+ <asp:TextBox runat="server" ID="txtIndexCursor" Width="70%"></asp:TextBox>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div id="extraleft">
+ <div class="warning">
+ <strong>INFORMATION:</strong> Header Count is mandatory(1-500) and Index cursor is optional.
+ To Use MIM, mobile number should be registered at messages.att.net
+ </div>
+ </div>
+ <div class="extra">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td class="cell">
+ <asp:Button ID="GetHeaderButton" runat="server" Text="Get Message Headers" OnClick="GetHeaderButton_Click" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <br />
+ <br style="clear: both;" />
+ <div style="text-align: left">
+ <asp:Panel ID="statusPanel" runat="server" Font-Names="Calibri" Font-Size="XX-Small">
+ </asp:Panel>
+ </div>
+ <div style="text-align: left">
+ <asp:Panel ID="pnlHeader" runat="server">
+ <table border="0" width="100%">
+ <tr>
+ <td style="width: 10%" valign="middle" class="label">
+ Header Count:
+ </td>
+ <td class="cell" align="left">
+ <asp:Label ID="lblHeaderCount" runat="server" CssClass="label"></asp:Label>
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 10%" valign="middle" class="label">
+ Index Cursor:
+ </td>
+ <td class="cell" align="left">
+ <asp:Label ID="lblIndexCursor" runat="server" CssClass="label"></asp:Label>
+ </td>
+ </tr>
+ </table>
+ <table border="0" width="100%">
+ <tr>
+ <td colspan="2">
+ <asp:GridView ID="gvMessageHeaders" runat="server" BackColor="White" BorderColor="#CCCCCC"
+ BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="100%">
+ <FooterStyle BackColor="White" ForeColor="#000066" />
+ <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
+ <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
+ <RowStyle ForeColor="#000066" HorizontalAlign="Left" />
+ <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
+ <SortedAscendingCellStyle BackColor="#F1F1F1" />
+ <SortedAscendingHeaderStyle BackColor="#007DBB" />
+ <SortedDescendingCellStyle BackColor="#CAC9C9" />
+ <SortedDescendingHeaderStyle BackColor="#00547E" />
+ </asp:GridView>
+ </td>
+ </tr>
+ </table>
+ </asp:Panel>
+ </div>
+ <br style="clear: both;" />
+ <br />
+ <div>
+ <div class="content">
+ <h2>
+ Feature 2: Get Message Content</h2>
+ </div>
+ </div>
+ <br />
+ <br />
+ <div class="navigation">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td style="width: 20%" valign="middle" class="label">
+ Message ID:
+ </td>
+ <td class="cell">
+ <asp:TextBox runat="server" ID="txtMessageId" Width="90%"></asp:TextBox>
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 20%" valign="middle" class="label">
+ Part Number:
+ </td>
+ <td class="cell">
+ <asp:TextBox runat="server" ID="txtPartNumber" Width="90%"></asp:TextBox>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <br />
+ <br />
+ <div class="extra">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td class="cell">
+ <asp:Button ID="GetMessageContent" runat="server" Text="Get Message Content" OnClick="GetMessageContent_Click" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <br style="clear: both;" />
+ <div style="text-align: left">
+ <asp:Panel ID="ContentPanelStatus" runat="server" Font-Names="Calibri" Font-Size="XX-Small">
+ </asp:Panel>
+ </div>
+ <br style="clear: both;" />
+ <br />
+ <br />
+ <div style="text-align: center">
+ <asp:Panel ID="smilpanel" runat="server">
+ <asp:TextBox ID="TextBox1" runat="server" Width="500" TextMode="MultiLine" BorderStyle="NotSet"
+ Enabled="False" EnableViewState="False" EnableTheming="False" Height="100"></asp:TextBox>
+ </asp:Panel>
+ </div>
+ <asp:Panel ID="imagePanel" runat="server" HorizontalAlign="Center">
+ <img id="imagetoshow" runat="server" alt="Fetched Image" />
+ </asp:Panel>
+ <br style="clear: both;" />
+ <div id="footer">
+ <div style="float: right; width: 20%; font-size: 9px; text-align: right">
+ Powered by AT&amp;T Cloud Architecture</div>
+ <p>
+ &#169; 2012 AT&amp;T Intellectual Property. All rights reserved. <a href="http://developer.att.com/"
+ target="_blank">http://developer.att.com</a>
+ <br />
+ The Application hosted on this site are working examples intended to be used for
+ reference in creating products to consume AT&amp;T Services and not meant to be
+ used as part of your product. The data in these pages is for test purposes only
+ and intended only for use as a reference in how the services perform.
+ <br />
+ For download of tools and documentation, please go to <a href="https://devconnect-api.att.com/"
+ target="_blank">https://devconnect-api.att.com</a>
+ <br />
+ For more information contact <a href="mailto:developer.support@att.com">developer.support@att.com</a></p>
+ </div>
+ </div>
+ <p>
+ &nbsp;</p>
+ </form>
+</body>
+</html>
View
1,105 MIM/Csharp/app1/Default.aspx.cs
@@ -0,0 +1,1105 @@
+// <copyright file="Default.aspx.cs" company="AT&amp;T">
+// Licensed by AT&amp;T under 'Software Development Kit Tools Agreement.' 2012
+// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/
+// Copyright 2012 AT&amp;T Intellectual Property. All rights reserved. http://developer.att.com
+// For more information contact developer.support@att.com
+// </copyright>
+
+#region References
+
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.IO;
+using System.Net;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Web.Script.Serialization;
+using System.Web.UI.WebControls;
+
+#endregion
+
+/// <summary>
+/// Access Token Types
+/// </summary>
+public enum AccessTokenType
+{
+ /// <summary>
+ /// Access Token Type is based on Authorization Code
+ /// </summary>
+ Authorization_Code,
+
+ /// <summary>
+ /// Access Token Type is based on Refresh Token
+ /// </summary>
+ Refresh_Token
+}
+
+/// <summary>
+/// This application allows the AT&T subscriber access to message related data
+/// stored in the AT&amp;T Messages environment.
+/// </summary>
+public partial class MIM_App1 : System.Web.UI.Page
+{
+ #region Application Instance Variables
+
+ /// <summary>
+ /// API Address
+ /// </summary>
+ private string endPoint;
+
+ /// <summary>
+ /// Access token variables - temporary
+ /// </summary>
+ private string apiKey, authCode, authorizeRedirectUri, secretKey, accessToken, scope, refreshToken,
+ refreshTokenExpiryTime, accessTokenExpiryTime;
+
+ /// <summary>
+ /// Gets or sets the value of refreshTokenExpiresIn
+ /// </summary>
+ private int refreshTokenExpiresIn;
+
+ #endregion
+
+ #region Application Events
+
+ /// <summary>
+ /// This function is called when the application page is loaded into the browser.
+ /// </summary>
+ /// <param name="sender">object, that caused this event</param>
+ /// <param name="e">Event that invoked this function</param>
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ pnlHeader.Visible = false;
+ imagePanel.Visible = false;
+ smilpanel.Visible = false;
+ if (!Page.IsPostBack)
+ {
+ this.ReadConfigFile();
+ }
+
+ this.BypassCertificateError();
+ DateTime currentServerTime = DateTime.UtcNow;
+ lblServerTime.Text = String.Format("{0:ddd, MMM dd, yyyy HH:mm:ss}", currentServerTime) + " UTC";
+ if (!Page.IsPostBack)
+ {
+ if (Session["mim_session_appState"] != null && Session["mim_session_appState"].ToString().Equals("GetToken")
+ && Request["Code"] != null)
+ {
+ this.authCode = Request["Code"].ToString();
+ if (this.GetAccessToken(AccessTokenType.Authorization_Code) == true)
+ {
+ bool isUserSpecifiedValues = this.GetSessionValues();
+ if (isUserSpecifiedValues == true)
+ {
+ if (Session["Request"] != null && Session["Request"].ToString().Equals("GetMessageHeaders"))
+ {
+ this.GetMessageHeaders();
+ }
+ else if (Session["Request"] != null && Session["Request"].ToString().Equals("GetMessageContent"))
+ {
+ this.GetMessageContentByIDnPartNumber();
+ }
+ }
+ }
+ else
+ {
+ this.DrawPanelForFailure(statusPanel, "Failed to get Access token");
+ this.ResetTokenSessionVariables();
+ this.ResetTokenVariables();
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(statusPanel, ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// Event, that gets called when user clicks on Get message headers button,
+ /// performs validations and initiates api call to get header messages.
+ /// </summary>
+ /// <param name="sender">object that initiated this method</param>
+ /// <param name="e">Event Agruments</param>
+ protected void GetHeaderButton_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(txtHeaderCount.Text.Trim()))
+ {
+ this.DrawPanelForFailure(statusPanel, "Specify number of messages to be retrieved");
+ return;
+ }
+
+ Regex regex = new Regex(@"\d+");
+ if (!regex.IsMatch(txtHeaderCount.Text.Trim()))
+ {
+ this.DrawPanelForFailure(statusPanel, "Specify valid header count");
+ return;
+ }
+
+ txtHeaderCount.Text = txtHeaderCount.Text.Trim();
+ Session["HeaderCount"] = txtHeaderCount.Text;
+ Session["IndexCursor"] = txtIndexCursor.Text;
+
+ int headerCount = Convert.ToInt32(txtHeaderCount.Text.Trim());
+ if (headerCount < 1 || headerCount > 500)
+ {
+ this.DrawPanelForFailure(statusPanel, "Header Count must be a number between 1-500");
+ return;
+ }
+
+ // Read from config file and initialize variables
+ if (this.ReadConfigFile() == false)
+ {
+ return;
+ }
+
+ Session["Request"] = "GetMessageHeaders";
+
+ // Is valid address
+ bool isValid = false;
+
+ isValid = this.ReadAndGetAccessToken();
+
+ if (isValid == true)
+ {
+ pnlHeader.Visible = false;
+ this.GetMessageHeaders();
+ }
+ }
+
+ /// <summary>
+ /// Event, that gets called when user clicks on Get message content button,
+ /// performs validations and initiates api call to get message content
+ /// </summary>
+ /// <param name="sender">object that initiated this method</param>
+ /// <param name="e">Event Agruments</param>
+ protected void GetMessageContent_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(txtMessageId.Text))
+ {
+ this.DrawPanelForFailure(ContentPanelStatus, "Specify Message ID");
+ return;
+ }
+
+ if (string.IsNullOrEmpty(txtPartNumber.Text))
+ {
+ this.DrawPanelForFailure(ContentPanelStatus, "Specify Part Number of the message");
+ return;
+ }
+
+ Session["MessageID"] = txtMessageId.Text;
+ Session["PartNumber"] = txtPartNumber.Text;
+
+ // Read from config file and initialize variables
+ if (this.ReadConfigFile() == false)
+ {
+ return;
+ }
+
+ Session["Request"] = "GetMessageContent";
+
+ // Is valid address
+ bool isValid = false;
+
+ isValid = this.ReadAndGetAccessToken();
+
+ if (isValid == true)
+ {
+ this.GetMessageContentByIDnPartNumber();
+ }
+ }
+
+ #endregion
+
+ #region Application Specific Methods
+
+ #region Display status Functions
+
+ /// <summary>
+ /// Displays success message
+ /// </summary>
+ /// <param name="panelParam">Panel to draw success message</param>
+ /// <param name="message">Message to display</param>
+ private void DrawPanelForSuccess(Panel panelParam, string message)
+ {
+ if (panelParam.HasControls())
+ {
+ panelParam.Controls.Clear();
+ }
+
+ Table table = new Table();
+ table.CssClass = "successWide";
+ table.Font.Name = "Sans-serif";
+ table.Font.Size = 9;
+ TableRow rowOne = new TableRow();
+ TableCell rowOneCellOne = new TableCell();
+ rowOneCellOne.Font.Bold = true;
+ rowOneCellOne.Text = "SUCCESS:";
+ rowOne.Controls.Add(rowOneCellOne);
+ table.Controls.Add(rowOne);
+ TableRow rowTwo = new TableRow();
+ TableCell rowTwoCellOne = new TableCell();
+ rowTwoCellOne.Text = message;
+ rowTwo.Controls.Add(rowTwoCellOne);
+ table.Controls.Add(rowTwo);
+ panelParam.Controls.Add(table);
+ }
+
+ /// <summary>
+ /// Displays error message
+ /// </summary>
+ /// <param name="panelParam">Panel to draw success message</param>
+ /// <param name="message">Message to display</param>
+ private void DrawPanelForFailure(Panel panelParam, string message)
+ {
+ if (panelParam.HasControls())
+ {
+ panelParam.Controls.Clear();
+ }
+
+ Table table = new Table();
+ table.CssClass = "errorWide";
+ table.Font.Name = "Sans-serif";
+ table.Font.Size = 9;
+ TableRow rowOne = new TableRow();
+ TableCell rowOneCellOne = new TableCell();
+ rowOneCellOne.Font.Bold = true;
+ rowOneCellOne.Text = "ERROR:";
+ rowOne.Controls.Add(rowOneCellOne);
+ table.Controls.Add(rowOne);
+ TableRow rowTwo = new TableRow();
+ TableCell rowTwoCellOne = new TableCell();
+ rowTwoCellOne.Text = message.ToString();
+ rowTwo.Controls.Add(rowTwoCellOne);
+ table.Controls.Add(rowTwo);
+ panelParam.Controls.Add(table);
+ }
+
+ /// <summary>
+ /// Displays the deserialized output to a grid
+ /// </summary>
+ /// <param name="messageHeaders">Deserialized message header list</param>
+ private void DisplayGrid(MessageHeaderList messageHeaders)
+ {
+ try
+ {
+ DataTable headerTable = this.GetHeaderDataTable();
+
+ if (null != messageHeaders && null != messageHeaders.Headers)
+ {
+ pnlHeader.Visible = true;
+ lblHeaderCount.Text = messageHeaders.HeaderCount.ToString();
+ lblIndexCursor.Text = messageHeaders.IndexCursor;
+
+ DataRow row;
+ foreach (Header header in messageHeaders.Headers)
+ {
+ row = headerTable.NewRow();
+
+ row["MessageId"] = header.MessageId;
+ row["From"] = header.From;
+ row["To"] = header.To != null ? string.Join(",", header.To.ToArray()) : string.Empty;
+ row["Received"] = header.Received;
+ row["Text"] = header.Text;
+ row["Favourite"] = header.Favorite;
+ row["Read"] = header.Read;
+ row["Direction"] = header.Direction;
+ row["Type"] = header.Type;
+ headerTable.Rows.Add(row);
+ if (null != header.Type && header.Type.ToLower() == "mms")
+ {
+ foreach (MMSContent mmsCont in header.MmsContent)
+ {
+ DataRow mmsDetailsRow = headerTable.NewRow();
+ mmsDetailsRow["PartNumber"] = mmsCont.PartNumber;
+ mmsDetailsRow["ContentType"] = mmsCont.ContentType;
+ mmsDetailsRow["ContentName"] = mmsCont.ContentName;
+ headerTable.Rows.Add(mmsDetailsRow);
+ }
+ }
+ }
+
+ gvMessageHeaders.DataSource = headerTable;
+ gvMessageHeaders.DataBind();
+ }
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(statusPanel, ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// Creates a datatable with message header columns
+ /// </summary>
+ /// <returns>data table with the structure of the grid</returns>
+ private DataTable GetHeaderDataTable()
+ {
+ DataTable messageTable = new DataTable();
+ DataColumn column = new DataColumn("MessageId");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("PartNumber");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("ContentType");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("ContentName");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("From");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("To");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Received");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Text");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Favourite");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Read");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Type");
+ messageTable.Columns.Add(column);
+
+ column = new DataColumn("Direction");
+ messageTable.Columns.Add(column);
+
+ return messageTable;
+ }
+
+ #endregion
+
+ #region Access Token functions
+
+ /// <summary>
+ /// Read parameters from configuraton file
+ /// </summary>
+ /// <returns>true/false; true if all required parameters are specified, else false</returns>
+ private bool ReadConfigFile()
+ {
+ this.endPoint = ConfigurationManager.AppSettings["endPoint"];
+ if (string.IsNullOrEmpty(this.endPoint))
+ {
+ this.DrawPanelForFailure(statusPanel, "endPoint is not defined in configuration file");
+ return false;
+ }
+
+ this.apiKey = ConfigurationManager.AppSettings["api_key"];
+ if (string.IsNullOrEmpty(this.apiKey))
+ {
+ this.DrawPanelForFailure(statusPanel, "api_key is not defined in configuration file");
+ return false;
+ }
+
+ this.secretKey = ConfigurationManager.AppSettings["secret_key"];
+ if (string.IsNullOrEmpty(this.secretKey))
+ {
+ this.DrawPanelForFailure(statusPanel, "secret_key is not defined in configuration file");
+ return false;
+ }
+
+ this.authorizeRedirectUri = ConfigurationManager.AppSettings["authorize_redirect_uri"];
+ if (string.IsNullOrEmpty(this.authorizeRedirectUri))
+ {
+ this.DrawPanelForFailure(statusPanel, "authorize_redirect_uri is not defined in configuration file");
+ return false;
+ }
+
+ this.scope = ConfigurationManager.AppSettings["scope"];
+ if (string.IsNullOrEmpty(this.scope))
+ {
+ this.scope = "MIM";
+ }
+
+ string refreshTokenExpires = ConfigurationManager.AppSettings["refreshTokenExpiresIn"];
+ if (!string.IsNullOrEmpty(refreshTokenExpires))
+ {
+ this.refreshTokenExpiresIn = Convert.ToInt32(refreshTokenExpires);
+ }
+ else
+ {
+ this.refreshTokenExpiresIn = 24;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Get session values, user supplied and assign to controls.
+ /// </summary>
+ /// <returns>true/false; true if values supplied, else false</returns>
+ private bool GetSessionValues()
+ {
+ bool isValuesPresent = false;
+
+ if (null != Session["HeaderCount"])
+ {
+ txtHeaderCount.Text = Session["HeaderCount"].ToString();
+ isValuesPresent = true;
+ }
+
+ if (null != Session["IndexCursor"])
+ {
+ txtIndexCursor.Text = Session["IndexCursor"].ToString();
+ isValuesPresent = true;
+ }
+
+ if (null != Session["MessageID"])
+ {
+ txtMessageId.Text = Session["MessageID"].ToString();
+ isValuesPresent = true;
+ }
+
+ if (null != Session["PartNumber"])
+ {
+ txtPartNumber.Text = Session["PartNumber"].ToString();
+ isValuesPresent = true;
+ }
+
+ return isValuesPresent;
+ }
+
+ /// <summary>
+ /// This function resets access token related session variable to null
+ /// </summary>
+ private void ResetTokenSessionVariables()
+ {
+ Session["mim_session_access_token"] = null;
+ Session["mim_session_accessTokenExpiryTime"] = null;
+ Session["mim_session_refresh_token"] = null;
+ Session["mim_session_refreshTokenExpiryTime"] = null;
+ }
+
+ /// <summary>
+ /// This function resets access token related variable to null
+ /// </summary>
+ private void ResetTokenVariables()
+ {
+ this.accessToken = null;
+ this.refreshToken = null;
+ this.refreshTokenExpiryTime = null;
+ this.accessTokenExpiryTime = null;
+ }
+
+ /// <summary>
+ /// Reads access token information from session and validates the token and
+ /// based on validity, the method will redirect to auth server/return the access token
+ /// </summary>
+ /// <returns>true/false; true if success in getting access token, else false
+ /// </returns>
+ private bool ReadAndGetAccessToken()
+ {
+ bool ableToReadAndGetToken = true;
+
+ this.ReadTokenSessionVariables();
+
+ string tokentResult = this.IsTokenValid();
+
+ if (tokentResult.CompareTo("INVALID_ACCESS_TOKEN") == 0)
+ {
+ Session["mim_session_appState"] = "GetToken";
+ this.GetAuthCode();
+ }
+ else if (tokentResult.CompareTo("REFRESH_TOKEN") == 0)
+ {
+ if (this.GetAccessToken(AccessTokenType.Refresh_Token) == false)
+ {
+ this.DrawPanelForFailure(statusPanel, "Failed to get Access token");
+ this.ResetTokenSessionVariables();
+ this.ResetTokenVariables();
+ ableToReadAndGetToken = false;
+ }
+ }
+
+ if (string.IsNullOrEmpty(this.accessToken))
+ {
+ this.DrawPanelForFailure(statusPanel, "Failed to get Access token");
+ this.ResetTokenSessionVariables();
+ this.ResetTokenVariables();
+ ableToReadAndGetToken = false;
+ }
+
+ return ableToReadAndGetToken;
+ }
+
+ /// <summary>
+ /// Redirect to OAuth and get Authorization Code
+ /// </summary>
+ private void GetAuthCode()
+ {
+ try
+ {
+ Response.Redirect(string.Empty + this.endPoint + "/oauth/authorize?scope=" + this.scope + "&client_id=" + this.apiKey + "&redirect_url=" + this.authorizeRedirectUri);
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(statusPanel, ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// Reads access token related session variables to local variables
+ /// </summary>
+ /// <returns>true/false depending on the session variables</returns>
+ private bool ReadTokenSessionVariables()
+ {
+ if (Session["mim_session_access_token"] != null)
+ {
+ this.accessToken = Session["mim_session_access_token"].ToString();
+ }
+ else
+ {
+ this.accessToken = null;
+ }
+
+ if (Session["mim_session_accessTokenExpiryTime"] != null)
+ {
+ this.accessTokenExpiryTime = Session["mim_session_accessTokenExpiryTime"].ToString();
+ }
+ else
+ {
+ this.accessTokenExpiryTime = null;
+ }
+
+ if (Session["mim_session_refresh_token"] != null)
+ {
+ this.refreshToken = Session["mim_session_refresh_token"].ToString();
+ }
+ else
+ {
+ this.refreshToken = null;
+ }
+
+ if (Session["mim_session_refreshTokenExpiryTime"] != null)
+ {
+ this.refreshTokenExpiryTime = Session["mim_session_refreshTokenExpiryTime"].ToString();
+ }
+ else
+ {
+ this.refreshTokenExpiryTime = null;
+ }
+
+ if ((this.accessToken == null) || (this.accessTokenExpiryTime == null) || (this.refreshToken == null) || (this.refreshTokenExpiryTime == null))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Validates access token related variables
+ /// </summary>
+ /// <returns>string, returns VALID_ACCESS_TOKEN if its valid
+ /// otherwise, returns INVALID_ACCESS_TOKEN if refresh token expired or not able to read session variables
+ /// return REFRESH_TOKEN, if access token in expired and refresh token is valid</returns>
+ private string IsTokenValid()
+ {
+ if (Session["mim_session_access_token"] == null)
+ {
+ return "INVALID_ACCESS_TOKEN";
+ }
+
+ try
+ {
+ DateTime currentServerTime = DateTime.UtcNow.ToLocalTime();
+ if (currentServerTime >= DateTime.Parse(this.accessTokenExpiryTime))
+ {
+ if (currentServerTime >= DateTime.Parse(this.refreshTokenExpiryTime))
+ {
+ return "INVALID_ACCESS_TOKEN";
+ }
+ else
+ {
+ return "REFRESH_TOKEN";
+ }
+ }
+ else
+ {
+ return "VALID_ACCESS_TOKEN";
+ }
+ }
+ catch
+ {
+ return "INVALID_ACCESS_TOKEN";
+ }
+ }
+
+ /// <summary>
+ /// Neglect the ssl handshake error with authentication server
+ /// </summary>
+ private void BypassCertificateError()
+ {
+ ServicePointManager.ServerCertificateValidationCallback +=
+ delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
+ {
+ return true;
+ };
+ }
+
+ /// <summary>
+ /// Get access token based on the type parameter type values.
+ /// </summary>
+ /// <param name="type">If type value is Authorization_code, access token is fetch for authorization code flow
+ /// If type value isRefresh_Token, access token is fetch for authorization code floww based on the exisiting refresh token</param>
+ /// <returns>true/false; true if success, else false</returns>
+ private bool GetAccessToken(AccessTokenType type)
+ {
+ bool result = false;
+
+ Stream postStream = null;
+ try
+ {
+ DateTime currentServerTime = DateTime.UtcNow.ToLocalTime();
+ WebRequest accessTokenRequest = System.Net.HttpWebRequest.Create(string.Empty + this.endPoint + "/oauth/token");
+ accessTokenRequest.Method = "POST";
+
+ string oauthParameters = string.Empty;
+ if (type == AccessTokenType.Authorization_Code)
+ {
+ oauthParameters = "client_id=" + this.apiKey + "&client_secret=" + this.secretKey + "&code=" + this.authCode + "&grant_type=authorization_code&scope=" + this.scope;
+ }
+ else if (type == AccessTokenType.Refresh_Token)
+ {
+ oauthParameters = "grant_type=refresh_token&client_id=" + this.apiKey + "&client_secret=" + this.secretKey + "&refresh_token=" + this.refreshToken;
+ }
+
+ accessTokenRequest.ContentType = "application/x-www-form-urlencoded";
+ UTF8Encoding encoding = new UTF8Encoding();
+ byte[] postBytes = encoding.GetBytes(oauthParameters);
+ accessTokenRequest.ContentLength = postBytes.Length;
+ postStream = accessTokenRequest.GetRequestStream();
+ postStream.Write(postBytes, 0, postBytes.Length);
+ postStream.Close();
+
+ WebResponse accessTokenResponse = accessTokenRequest.GetResponse();
+ using (StreamReader accessTokenResponseStream = new StreamReader(accessTokenResponse.GetResponseStream()))
+ {
+ string access_token_json = accessTokenResponseStream.ReadToEnd();
+ JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer();
+ AccessTokenResponse deserializedJsonObj = (AccessTokenResponse)deserializeJsonObject.Deserialize(access_token_json, typeof(AccessTokenResponse));
+ if (deserializedJsonObj.access_token != null)
+ {
+ this.accessToken = deserializedJsonObj.access_token;
+ this.refreshToken = deserializedJsonObj.refresh_token;
+
+ DateTime refreshExpiry = currentServerTime.AddHours(this.refreshTokenExpiresIn);
+
+ Session["mim_session_accessTokenExpiryTime"] = currentServerTime.AddSeconds(Convert.ToDouble(deserializedJsonObj.expires_in));
+
+ if (deserializedJsonObj.expires_in.Equals("0"))
+ {
+ int defaultAccessTokenExpiresIn = 100; // In Years
+ Session["mim_session_accessTokenExpiryTime"] = currentServerTime.AddYears(defaultAccessTokenExpiresIn);
+ }
+
+ this.refreshTokenExpiryTime = refreshExpiry.ToLongDateString() + " " + refreshExpiry.ToLongTimeString();
+ Session["mim_session_access_token"] = this.accessToken;
+ this.accessTokenExpiryTime = Session["mim_session_accessTokenExpiryTime"].ToString();
+ Session["mim_session_refresh_token"] = this.refreshToken;
+ Session["mim_session_refreshTokenExpiryTime"] = this.refreshTokenExpiryTime;
+ Session["mim_session_appState"] = "TokenReceived";
+ accessTokenResponseStream.Close();
+ result = true;
+ }
+ else
+ {
+ this.DrawPanelForFailure(statusPanel, "Auth server returned null access token");
+ }
+ }
+ }
+ catch (WebException we)
+ {
+ string errorResponse = string.Empty;
+ try
+ {
+ using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream()))
+ {
+ errorResponse = sr2.ReadToEnd();
+ sr2.Close();
+ }
+ }
+ catch
+ {
+ errorResponse = "Unable to get access token";
+ }
+
+ this.DrawPanelForFailure(statusPanel, errorResponse + Environment.NewLine + we.Message);
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(statusPanel, ex.Message);
+ }
+ finally
+ {
+ if (null != postStream)
+ {
+ postStream.Close();
+ }
+ }
+
+ return result;
+ }
+
+ #endregion
+
+ #region Get Message Headers Functions
+
+ /// <summary>
+ /// Retreives the message headers based on headerCount and inderCursor
+ /// </summary>
+ private void GetMessageHeaders()
+ {
+ try
+ {
+ HttpWebRequest mimRequestObject1;
+
+ mimRequestObject1 = (HttpWebRequest)WebRequest.Create(string.Empty + this.endPoint + "/rest/1/MyMessages?HeaderCount=" + txtHeaderCount.Text);
+ if (!string.IsNullOrEmpty(txtIndexCursor.Text))
+ {
+ mimRequestObject1 = (HttpWebRequest)WebRequest.Create(string.Empty + this.endPoint + "/rest/1/MyMessages?HeaderCount=" + txtHeaderCount.Text + "&IndexCursor=" + txtIndexCursor.Text);
+ }
+
+ mimRequestObject1.Headers.Add("Authorization", "Bearer " + this.accessToken);
+ mimRequestObject1.Method = "GET";
+ mimRequestObject1.KeepAlive = true;
+
+ WebResponse mimResponseObject1 = mimRequestObject1.GetResponse();
+ using (StreamReader sr = new StreamReader(mimResponseObject1.GetResponseStream()))
+ {
+ string mimResponseData = sr.ReadToEnd();
+
+ JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer();
+ MIMResponse deserializedJsonObj = (MIMResponse)deserializeJsonObject.Deserialize(mimResponseData, typeof(MIMResponse));
+
+ if (null != deserializedJsonObj)
+ {
+ this.DrawPanelForSuccess(statusPanel, string.Empty);
+ this.DisplayGrid(deserializedJsonObj.MessageHeadersList);
+ }
+ else
+ {
+ this.DrawPanelForFailure(statusPanel, "No response from server");
+ }
+
+ sr.Close();
+ }
+ }
+ catch (WebException we)
+ {
+ string errorResponse = string.Empty;
+
+ try
+ {
+ using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream()))
+ {
+ errorResponse = sr2.ReadToEnd();
+ sr2.Close();
+ }
+ }
+ catch
+ {
+ errorResponse = "Unable to get response";
+ }
+
+ this.DrawPanelForFailure(statusPanel, errorResponse + Environment.NewLine + we.Message);
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(statusPanel, ex.Message);
+ return;
+ }
+ }
+
+ /// <summary>
+ /// Gets the message content for MMS messages based on Message ID and Part Number
+ /// </summary>
+ private void GetMessageContentByIDnPartNumber()
+ {
+ try
+ {
+ HttpWebRequest mimRequestObject1 = (HttpWebRequest)WebRequest.Create(string.Empty + this.endPoint + "/rest/1/MyMessages/" + txtMessageId.Text + "/" + txtPartNumber.Text);
+ mimRequestObject1.Headers.Add("Authorization", "Bearer " + this.accessToken);
+ mimRequestObject1.Method = "GET";
+ mimRequestObject1.KeepAlive = true;
+ int offset = 0;
+ WebResponse mimResponseObject1 = mimRequestObject1.GetResponse();
+ int remaining = Convert.ToInt32(mimResponseObject1.ContentLength);
+ using (var stream = mimResponseObject1.GetResponseStream())
+ {
+ var bytes = new byte[mimResponseObject1.ContentLength];
+ while (remaining > 0)
+ {
+ int read = stream.Read(bytes, offset, remaining);
+ if (read <= 0)
+ {
+ this.DrawPanelForFailure(ContentPanelStatus, String.Format("End of stream reached with {0} bytes left to read", remaining));
+ return;
+ }
+
+ remaining -= read;
+ offset += read;
+ }
+
+ string[] splitData = Regex.Split(mimResponseObject1.ContentType.ToLower(), ";");
+ string[] ext = Regex.Split(splitData[0], "/");
+
+ if (mimResponseObject1.ContentType.ToLower().Contains("application/smil"))
+ {
+ smilpanel.Visible = true;
+ TextBox1.Text = System.Text.Encoding.Default.GetString(bytes);
+ this.DrawPanelForSuccess(ContentPanelStatus, string.Empty);
+ }
+ else if (mimResponseObject1.ContentType.ToLower().Contains("text/plain"))
+ {
+ this.DrawPanelForSuccess(ContentPanelStatus, System.Text.Encoding.Default.GetString(bytes));
+ }
+ else
+ {
+ imagePanel.Visible = true;
+ this.DrawPanelForSuccess(ContentPanelStatus, string.Empty);
+ imagetoshow.Src = "data:" + splitData[0] + ";base64," + Convert.ToBase64String(bytes, Base64FormattingOptions.None);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ this.DrawPanelForFailure(ContentPanelStatus, ex.Message);
+ }
+ }
+
+ #endregion
+
+ #endregion
+}
+
+#region Data Structures
+
+/// <summary>
+/// Access Token Data Structure
+/// </summary>
+public class AccessTokenResponse
+{
+ /// <summary>
+ /// Gets or sets Access Token ID
+ /// </summary>
+ public string access_token
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets Refresh Token ID
+ /// </summary>
+ public string refresh_token
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets Expires in milli seconds
+ /// </summary>
+ public string expires_in
+ {
+ get;
+ set;
+ }
+}
+
+/// <summary>
+/// Response returned from MyMessages api
+/// </summary>
+public class MIMResponse
+{
+ /// <summary>
+ /// Gets or sets the value of message header list.
+ /// </summary>
+ public MessageHeaderList MessageHeadersList
+ {
+ get;
+ set;
+ }
+}
+
+/// <summary>
+/// Message Header List
+/// </summary>
+public class MessageHeaderList
+{
+ /// <summary>
+ /// Gets or sets the value of object containing a List of Messages Headers
+ /// </summary>
+ public List<Header> Headers
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of a number representing the number of headers returned for this request.
+ /// </summary>
+ public int HeaderCount
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of a string which defines the start of the next block of messages for the current request.
+ /// A value of zero (0) indicates the end of the block.
+ /// </summary>
+ public string IndexCursor
+ {
+ get;
+ set;
+ }
+}
+
+/// <summary>
+/// Object containing a List of Messages Headers
+/// </summary>
+public class Header
+{
+ /// <summary>
+ /// Gets or sets the value of Unique message identifier
+ /// </summary>
+ public string MessageId
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of message sender
+ /// </summary>
+ public string From
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of the addresses, whom the message need to be delivered.
+ /// If Group Message, this will contain multiple Addresses.
+ /// </summary>
+ public List<string> To
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets a value of message text
+ /// </summary>
+ public string Text
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets a value of message part descriptions
+ /// </summary>
+ public List<MMSContent> MmsContent
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of date/time message received
+ /// </summary>
+ public DateTime Received
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether its a favourite or not
+ /// </summary>
+ public bool Favorite
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether message is read or not
+ /// </summary>
+ public bool Read
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of type of message, TEXT or MMS
+ /// </summary>
+ public string Type
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of indicator, which indicates if message is Incoming or Outgoing “IN” or “OUT”
+ /// </summary>
+ public string Direction
+ {
+ get;
+ set;
+ }
+}
+
+/// <summary>
+/// Message part descriptions
+/// </summary>
+public class MMSContent
+{
+ /// <summary>
+ /// Gets or sets the value of content name
+ /// </summary>
+ public string ContentName
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of content type
+ /// </summary>
+ public string ContentType
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Gets or sets the value of part number
+ /// </summary>
+ public string PartNumber
+ {
+ get;
+ set;
+ }
+}
+
+#endregion
View
35 MIM/Csharp/app1/MSRestfulV2_1_CsharpMIMApp1.sln
@@ -0,0 +1,35 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "app1", ".", "{D08D8BA2-674E-4DB0-84D5-467F6CCFAD22}"
+ ProjectSection(WebsiteProperties) = preProject
+ TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
+ Debug.AspNetCompiler.VirtualPath = "/app1"
+ Debug.AspNetCompiler.PhysicalPath = "D:\Wdev SVN\Code\MSRestfulSampleApplications\Csharp\mim\app1\"
+ Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\app1\"
+ Debug.AspNetCompiler.Updateable = "true"
+ Debug.AspNetCompiler.ForceOverwrite = "true"
+ Debug.AspNetCompiler.FixedNames = "false"
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.VirtualPath = "/app1"
+ Release.AspNetCompiler.PhysicalPath = "D:\Wdev SVN\Code\MSRestfulSampleApplications\Csharp\mim\app1\"
+ Release.AspNetCompiler.TargetPath = "PrecompiledWeb\app1\"
+ Release.AspNetCompiler.Updateable = "true"
+ Release.AspNetCompiler.ForceOverwrite = "true"
+ Release.AspNetCompiler.FixedNames = "false"
+ Release.AspNetCompiler.Debug = "False"
+ VWDPort = "59665"
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D08D8BA2-674E-4DB0-84D5-467F6CCFAD22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D08D8BA2-674E-4DB0-84D5-467F6CCFAD22}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
102 MIM/Csharp/app1/README.txt
@@ -0,0 +1,102 @@
+******************************************************************************************
+* Licensed by AT&T under 'Software Development Kit Tools Agreement.' 2012
+* Copyright 2012 AT&T Intellectual Property. All rights reserved. http://developer.att.com
+* For more information contact developer.support@att.com<mailto:developer.support@att.com>
+******************************************************************************************
+
+ AT&T API Samples - MIM app 1
+ --------------------------------
+
+This application allows the AT&T subscriber access to message related data
+stored in the AT&T Messages environment.
+
+This file describes how to set up, configure and run the C# Applications of the
+AT&T APIPlatform Restful sample applications.
+It covers all steps required to register the application on DevConnect and, based
+on the generated API keys and secrets, create and run one's own full-fledged
+sample applications.
+
+ 1. Configuration
+ 2. Installation
+ 3. Parameters
+ 4. Running the application
+
+
+1. Configuration
+
+ Configuration consists of a few steps necessary to get an application registered
+ on DevConnect with the proper services and endpoints, depending on the type of
+ client-side application (autonomous/non-autonomous).
+
+ To register an application, go to https://devconnect-api.att.com/ and login with
+ your valid username and password. Next, choose "My Apps" from the bar at the top
+ of the page and click the "Setup a New Application" button.
+
+ Fill in the form, in particular all fields marked as "required".
+
+NOTE: You MUST select "Messaging On Behalf Of" in the list of services under field 'Services' in
+order to use this sample application code.
+
+ Having your application registered, you will get back an important pair of data:
+ an API key and Secret key. They are necessary to get your applications working
+ with the AT&T Platform APIs.
+
+ Initially your newly registered application is restricted to the "Sandbox"
+ environment only. To move it to production, you may promote it by clicking the
+ "Promote to production" button. Notice that you will get a different API key and
+ secret, so these values in your application should be adjusted accordingly.
+
+ Depending on the kind of authentication used, an application may be based on
+ either the Autonomous Client or the Web-Server Client OAuth flow
+ (see https://devconnect-api.att.com/docs/oauth20/autonomous-client-application-oauth-flow or
+ https://devconnect-api.att.com/docs/oauth20/web-server-client-application-oauth-flow
+ respectively).
+
+
+
+2. Installation
+
+** Requirements
+
+ To run the examples you need an IIS Server.
+
+ Download the application files from the download link published in AT&T portal
+ into webdomain of your IIS server.
+
+
+
+3. Parameters
+
+Each sample application contains a web.config file. It holds configurable parameters
+described in an easy to read format. Please populate the following parameters in
+web.config as specified below:
+
+1) api_key : This is mandatory parameter, set the value as per your
+ registered application 'API key' field value.
+
+2) secret_key : This is mandatory parameter, set the value as per your
+ registered application 'Secret key' field value.
+
+3) endPoint : This is mandatory parameter, set it to the end point URI
+ of AT&T Service.
+
+4) scope : MIM (Scope of the ATT service that will be invoked by
+ the Application)
+
+5) authorize_redirect_uri: This is mandatory key and value should be equal
+ to MOBO Service registered application 'OAuth Redirect URL'
+
+6) refreshTokenExpiresIn: This is optional key, which specifies the expiry time of
+ refresh token in Hrs. Default value is 24Hrs.
+
+Note: You must update parameters 1-2 after you promote your application from 'Sandbox'
+environment to 'Production' environment.
+
+
+
+4. Running the application
+
+Suppose you copied the sample app files in your IIS server webroot/mim/app1/ folder.
+In order to run the sample application, type in'http://IIS_HOSTNAME:8080/mim/app1/Default.aspx'
+(assuming you're using a HOSTNAME machine with IIS Server and have not changed the
+default port number, otherwise adjust accordingly) on your browser.
View
37 MIM/Csharp/app1/Web.config
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+ For more information on how to configure your ASP.NET application, please visit
+ http://go.microsoft.com/fwlink/?LinkId=169433
+ -->
+<configuration>
+ <system.web>
+ <compilation debug="true" targetFramework="4.0"/>
+ <customErrors mode="Off"></customErrors>
+ </system.web>
+ <appSettings>
+
+ <!-- This is mandatory parameter, set the value as per your registered application
+ 'API key' field value. -->
+ <add key="api_key" value=""/>
+
+ <!-- This is mandatory parameter, set the value as per your registered application
+ 'Secret key' field value. -->
+ <add key="secret_key" value=""/>
+
+ <!-- This is mandatory parameter, set it to the end point URI of AT&T Service. -->
+ <add key="endPoint" value="" />
+
+ <!-- Scope of the ATT service that will be invoked by the Application -->
+ <add key="scope" value=""/>
+
+ <!-- This is mandatory key and value should be equal
+ to MOBO Service registered application 'OAuth Redirect URL'
+ example: value="https://IIS-Server/webroot/mim/app1/Default.aspx -->
+ <add key="authorize_redirect_uri" value=""/>
+
+ <!-- This is optional key, which specifies the expiry time of refresh token in Hrs.
+ Default value is 24Hrs.-->
+ <add key="refreshTokenExpiresIn" value=""/>
+
+ </appSettings>
+</configuration>
View
BIN  MIM/Csharp/app1/images/Thumbs.db
Binary file not shown
View
BIN  MIM/Csharp/app1/images/att.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
39 MIM/Csharp/app1/style/common.css
@@ -0,0 +1,39 @@
+/*@charset "utf-8";*/
+/* CSS Document */
+
+html,body{ margin:0;padding:0}
+body{font: 12px arial,sans-serif;text-align:center; color: #000}
+p{margin:0 10px 10px}
+a{color: #69BBE5}
+h1 { font-size: 16px; margin: 0 0}
+h2 { font-size: 14px; margin: 0 0}
+div#header { background:url(../images/att.gif) left center no-repeat; margin: 10px 5px}
+.hcLeft { float:left; text-align: right; width: 39%; font-weight: bold}
+.hcRight { float:right; width: 59%}
+
+.content { border-top: 1px dashed #999}
+div#container{ text-align:left}
+.content p{line-height:1.4}
+div#footer{ font-size: 9px; text-align: center; border-top: 1px dashed #999; margin-top: 10px; padding-top: 10px}
+div#footer p{ width: 500px; margin:0 auto;padding:5px 10px}
+
+div#container{width:1000px;margin:0 auto}
+.navigation{float:left;width:500px}
+.extra{float:right;width:500px}
+div#extra1{float:right;width:500px; height: 97px}
+div#extra2{float:left;width:100%}
+div#extraleft{float:left;width:200px}
+div#footer{clear:both;width:100%}
+
+div#gallerywrapper { width: 900px; margin: 10px auto; padding: 10px}
+div#gallery { float: left; width: 150px; height: 190px; padding: 10px; margin-bottom: 15px; font-size: 9px}
+
+.label, .cell { font: 12px Arial, Sans-serif}
+.label { font-weight: bold}
+
+.error { margin: 0 auto; border: 3px outset red; background: #fcc; width: 250px; padding: 5px; font-size: 11px }
+.warning { margin: 0 auto; border: 3px outset yellow; background: #ffc; width: 250px; padding: 5px; font-size: 11px }
+.success { margin: 0 auto; border: 3px outset green; background: #cfc; width: 250px; padding: 5px; font-size: 11px }
+.errorWide { margin: 0 auto; border: 3px outset red; background: #fcc; width: 650px; padding: 5px; font-size: 11px }
+.warningWide { margin: 0 auto; border: 3px outset yellow; background: #ffc; width: 650px; padding: 5px; font-size: 11px }
+.successWide { margin: 0 auto; border: 3px outset green; background: #cfc; width: 650px; padding: 5px; font-size: 11px }
View
3  MIM/Java/app1/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
View
531 MIM/Java/app1/MIM.jsp
@@ -0,0 +1,531 @@
+<%
+//Licensed by AT&T under 'Software Development Kit Tools Agreement.' 2012
+//TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/
+//Copyright 2012 AT&T Intellectual Property. All rights reserved. http://developer.att.com
+//For more information contact developer.support@att.com
+%>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+<meta name="generator" content="HTML Tidy, see www.w3.org" />
+
+<title>AT&amp;T Sample Mim Application 1 - Basic Mim Service
+ Application</title>
+<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
+<link rel="stylesheet" type="text/css" href="style/common.css" />
+<style type="text/css">
+.style2 {
+ width: 491px;
+}
+
+#Submit1 {
+ width: 213px;
+}
+
+.style3 {
+ font-size: x-small;
+}
+</style>
+</head>
+
+<body>
+ <%@ page contentType="text/html; charset=iso-8859-1" language="java"%>
+ <%@ page import="org.apache.commons.httpclient.*"%>
+ <%@ page import="org.apache.commons.httpclient.methods.*"%>
+ <%@ page import="org.json.JSONObject"%>
+ <%@ page import="org.apache.commons.codec.binary.Base64"%>
+ <%@ page import="org.apache.http.HttpEntity"%>
+ <%@ page import="org.json.JSONArray"%>
+ <%@ page import="java.util.*"%>
+ <%@ page import="java.net.URL"%>
+ <%@ page import="java.net.URLConnection"%>
+ <%@ page import="java.net.URLEncoder,java.io.*"%>
+ <%@ page import="java.net.URLDecoder,java.io.*"%>
+ <%@ page import="org.apache.commons.httpclient.HttpClient"%>
+ <%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
+ <%@ page import="org.apache.http.HttpResponse"%>
+ <%@ page import="org.apache.http.util.EntityUtils"%>
+ <%@ page import="java.util.List,java.util.Iterator"%>
+ <%@ page import="sun.misc.BASE64Encoder"%>
+ <%@ page import="sun.misc.BASE64Decoder"%>
+ <%@ page import="org.apache.commons.codec.binary.Base64"%>
+ <%@ include file="config.jsp"%>
+ <%
+String scope = "MIM";
+
+//Buttons
+String getMsgHeadersButton = request.getParameter("getMsgHeadersButton");
+String msgContent = request.getParameter("msgContent");
+
+String postOauth = "MIM.jsp?getMsgHeadersButton=true";
+
+//Fields
+String HeaderCount = request.getParameter("HeaderCount");
+if(HeaderCount==null || HeaderCount.equalsIgnoreCase("null"))
+ HeaderCount = (String) session.getAttribute("headercount");
+if(HeaderCount==null || HeaderCount.equalsIgnoreCase("null"))
+ HeaderCount = "";
+session.setAttribute("headercount",HeaderCount);
+
+String IndexCursor = request.getParameter("IndexCursor");
+if(IndexCursor==null || IndexCursor.equalsIgnoreCase("null"))
+ IndexCursor = (String) session.getAttribute("IndexCursor");
+if(IndexCursor==null || IndexCursor.equalsIgnoreCase("null"))
+ IndexCursor = "";
+session.setAttribute("IndexCursor",IndexCursor);
+
+String MessageId = request.getParameter("MessageId");
+if(MessageId==null || MessageId.equalsIgnoreCase("null"))
+ MessageId = (String) session.getAttribute("MessageId");
+if(MessageId==null || MessageId.equalsIgnoreCase("null"))
+ MessageId = "";
+session.setAttribute("MessageId",MessageId);
+
+String PartNumber = request.getParameter("PartNumber");
+if(PartNumber==null || PartNumber.equalsIgnoreCase("null"))
+ PartNumber = (String) session.getAttribute("PartNumber");
+if(PartNumber==null || PartNumber.equalsIgnoreCase("null"))
+ PartNumber = "";
+session.setAttribute("PartNumber",PartNumber);
+%>
+ <div id="container">
+ <!-- open HEADER -->
+
+ <div id="header">
+ <div>
+ <div id="hcLeft">Server Time:</div>
+
+ <div id="hcRight">
+ <span id="serverTimeLabel"><%=new java.util.Date()%></span>
+ </div>
+ </div>
+
+ <div>
+ <div id="hcLeft">Client Time:</div>
+
+ <div id="hcRight">
+ <script language="JavaScript" type="text/javascript">
+ var myDate = new Date();
+ document.write(myDate);
+ </script>
+ </div>
+ </div>
+
+ <div>
+ <div id="hcLeft">User Agent:</div>
+
+ <div id="hcRight">
+ <script language="JavaScript" type="text/javascript">
+ document.write("" + navigator.userAgent);
+ </script>
+ </div>
+ </div>
+ <br clear="all" />
+ </div>
+ <!-- close HEADER -->
+
+ <div id="wrapper">
+ <div id="content">
+ <h1>AT&amp;T Sample Mim Application 1 - Basic Mim Service
+ Application</h1>
+
+ <h2>Feature 1: Get Message Header</h2>
+ </div>
+ </div>
+ <br clear="all" />
+
+ <form method="post" action="" id="msgHeader">
+ <div id="navigation">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td width="20%" valign="top" class="label">Header Count:</td>
+
+ <td class="cell"><input name="HeaderCount" type="text"
+ maxlength="6" id="HeaderCount" style="width: 70px;" /></td>
+ </tr>
+
+ <tr>
+ <td width="20%" valign="top" class="label">Index Cursor:</td>
+
+ <td class="cell"><input name="IndexCursor" type="text"
+ maxlength="30" id="IndexCursor" style="width: 291px;" /></td>
+ </tr>
+ </tbody>
+ </table>
+ <br clear="all" />
+ </div>
+
+ <div id="extraleft">
+ <div class="warning">
+ <strong>INFORMATION:</strong> Header Count is mandatory(1-500) and
+ Index cursor is optional. To Use MIM, mobile number should be
+ registered at messages.att.net
+ </div>
+ </div>
+
+ <div id="extra">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td class="cell"><input type="submit"
+ name="getMsgHeadersButton" value="Get Message Headers"
+ id="Submit1" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </form>
+ <br clear="all" /> <br clear="all" />
+ <div id="pnlHeader">
+ <%
+ if(getMsgHeadersButton!=null) {
+ String accessToken = request.getParameter("access_token");
+ if(accessToken==null || accessToken == "null"){
+ accessToken = (String)session.getAttribute("accessToken");
+ session.setAttribute("accessToken", accessToken);
+ }
+ if((accessToken==null) || (!scope.equalsIgnoreCase("MIM")) && (!scope.equalsIgnoreCase("SMS,MMS,WAP,DC,TL,PAYMENT,MOBO,MIM"))) {
+ session.setAttribute("scope", "MIM");
+ session.setAttribute("clientId", clientIdWeb);
+ session.setAttribute("clientSecret", clientSecretWeb);
+ session.setAttribute("postOauth", postOauth);
+ session.setAttribute("redirectUri", redirectUri);
+ response.sendRedirect("oauth.jsp?getExtCode=yes");
+ }
+
+ String url = FQDN + "/rest/1/MyMessages";
+ HttpClient client = new HttpClient();
+ GetMethod method = new GetMethod(url);
+ method.setQueryString("HeaderCount=" + HeaderCount);
+ method.addRequestHeader("Accept","application/json");
+ method.addRequestHeader("Content-Type","application/json");
+ method.addRequestHeader("Authorization","Bearer " + accessToken);
+ int statusCode1 = client.executeMethod(method);
+ System.out.println("AccessToken: " + accessToken);
+ System.out.println("method: " + method);
+ //System.out.println("StatusCode: " + statusCode);
+
+ System.out.println("StatusCode before if: "+ statusCode1 + " msgContent:" + msgContent );
+ if((statusCode1==200 || statusCode1==201) && msgContent==null) {
+ JSONObject rpcObject = new JSONObject(method.getResponseBodyAsString());
+ JSONObject mgeHdrList = rpcObject.getJSONObject("MessageHeadersList");
+ JSONArray headersArray = mgeHdrList.getJSONArray("Headers");
+
+ String [] paramsArray = {"MessageId" , "PartNumber", "ContentType", "ContentName", "From", "To", "Received", "Text", "Favourite", "Read", "Type", "Direction"}; %>
+ <div class="successWide">
+ <strong>SUCCESS</strong><br />
+ </div>
+ <div class="content" align="left">
+
+ <table>
+ <tr>
+ <td width="10%" valign="middle" class="label">Header Count:</td>
+ <td class="cell" align="left"><span id="lblHeaderCount"
+ class="label"><%=mgeHdrList.getString("HeaderCount")%></span></td>
+ </tr>
+ <tr>
+ <td width="10%" valign="middle" class="label">Index Cursor:</td>
+ <td class="cell" align="left"><span id="lblIndexCursor"
+ class="label"><%=mgeHdrList.getString("IndexCursor")%></span></td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <div>
+ <table id="gvMessageHeaders" cellspacing="0" cellpadding="3"
+ style="background-color: White; border-color: #CCCCCC; border-width: 1px; border-style: None; width: 100%; border-collapse: collapse;"
+ rules="all">
+ <tr style="color: White; background-color: #006699;">
+ <th scope="col" class="style3">MessageId</th>
+ <th scope="col" class="style3">PartNumber</th>
+ <th scope="col" class="style3">ContentType</th>
+ <th scope="col" class="style3">ContentName</th>
+ <th scope="col" class="style3">From</th>
+ <th scope="col" class="style3">To</th>
+ <th scope="col" class="style3">Received</th>
+ <th scope="col" class="style3">Text</th>
+ <th scope="col" class="style3">Favourite</th>
+ <th scope="col" class="style3">Read</th>
+ <th scope="col" class="style3">Type</th>
+ <th scope="col" class="style3">Direction</th>
+ </tr>
+ <%for (int i = 0; i < headersArray.length(); i++) {
+ JSONObject inHeaders = headersArray.getJSONObject(i);
+ %>
+ <tr class="style3">
+ <td class="style3"><%=inHeaders.getString("MessageId")%></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"><%=inHeaders.getString("From")%></td>
+ <td class="style3"><%=inHeaders.getString("To")%></td>
+ <td class="style3"><%=inHeaders.getString("Received")%></td>
+ <td class="style3"><%=inHeaders.getString("Favorite")%></td>
+ <%if(inHeaders.has("Text")){%>
+ <td class="style3"><%=inHeaders.getString("Text")%></td>
+ <%}%>
+ <td class="style3"><%=inHeaders.getString("Read")%></td>
+ <td class="style3"><%=inHeaders.getString("Type")%></td>
+ <td class="style3"><%=inHeaders.getString("Direction")%></td>
+ <%
+ if(inHeaders.has("MmsContent")){
+ JSONArray MmsContentArray = inHeaders.getJSONArray("MmsContent");
+ for (int x = 0; x < MmsContentArray.length(); x++) {
+ JSONObject inMmsContent = MmsContentArray.getJSONObject(x);%>
+
+ <tr>
+ <td class="style3"></td>
+ <td class="style3"><%=inMmsContent.getString("PartNumber")%></td>
+ <td class="style3"><%=inMmsContent.getString("ContentType")%></td>
+ <td class="style3"><%=inMmsContent.getString("ContentName")%></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ <td class="style3"></td>
+ </tr>
+ <%}
+ } %>
+ <tr></tr>
+ </tr>
+ <%}%>
+ </table>
+ </div></td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ <%}
+ else if( getMsgHeadersButton!=null && request.getParameter("HeaderCount")==""){
+ %><div class="errorWide">
+ <strong>ERROR:</strong> Header Count field is empty.<br />
+ </div><br /><%
+ method.releaseConnection();}
+ else if( getMsgHeadersButton!=null && request.getParameter("HeaderCount")=="" && request.getParameter("IndexCursor")!=""){
+ %><div class="errorWide">
+ <strong>ERROR:</strong> Header Count field is empty.<br />
+ </div><br /><%
+ method.releaseConnection();}
+ else if((statusCode1 != 200 || statusCode1 != 201) && msgContent ==null){ %>
+ <div class="errorWide">
+ <strong>ERROR:</strong><br />
+ <%=method.getResponseBodyAsString()%>
+ </div>
+ <br />
+ <%}
+ method.releaseConnection();
+ }%>
+
+
+
+ <div id="wrapper">
+ <div id="content">
+ <br clear="all" />
+
+
+ <h2>Feature 2: Get Message Content</h2>
+ </div>
+ </div>
+ <br clear="all" />
+
+
+ <form method="post" action="" id="msgContent">
+ <div id="navigation">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td width="20%" valign="top" class="label">Message ID:</td>
+
+ <td class="cell"><input name="MessageId" type="text"
+ maxlength="6" id="Text1" style="width: 291px;" /></td>
+ </tr>
+
+ <tr>
+ <td width="20%" valign="top" class="label">Part Number:</td>
+
+ <td class="cell"><input name="PartNumber" type="text"
+ maxlength="30" id="Text2" style="width: 291px;" /></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+
+ <div id="extra">
+ <table border="0" width="100%">
+ <tbody>
+ <tr>
+ <td class="cell"><input type="submit" name="msgContent"
+ value="Get Message Content" id="Submit1" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </form>
+ <br clear="all" />
+
+
+ <%
+
+ //If Check Delivery Status button was clicked, do this.
+ if(msgContent!=null) {
+
+
+ String accessToken = request.getParameter("access_token");
+ if(accessToken==null || accessToken == "null"){
+ accessToken = (String)session.getAttribute("accessToken");
+ session.setAttribute("accessToken", accessToken);
+ }
+ if((accessToken==null) || (!scope.equalsIgnoreCase("MIM")) && (!scope.equalsIgnoreCase("SMS,MMS,WAP,DC,TL,PAYMENT,MOBO,MIM"))) {
+ session.setAttribute("scope", "MIM");
+ session.setAttribute("clientId", clientIdWeb);
+ session.setAttribute("clientSecret", clientSecretWeb);
+ session.setAttribute("postOauth", postOauth);
+ session.setAttribute("redirectUri", redirectUri);
+ response.sendRedirect("oauth.jsp?getExtCode=yes");
+ }
+
+ //Initialize the client
+ String url = FQDN + "/rest/1/MyMessages/" + MessageId + "/" + PartNumber;
+ URL url1 = new URL(FQDN + "/rest/1/MyMessages/" + MessageId + "/" + PartNumber);
+
+ HttpClient client = new HttpClient();
+ GetMethod method = new GetMethod(url);
+ method.setQueryString("MessageId=" + MessageId + "&PartNumber=" + PartNumber);
+ method.addRequestHeader("Content-Type","application/json");
+ method.addRequestHeader("Accept","application/json");
+ method.addRequestHeader("Authorization","Bearer " + accessToken);
+ URLConnection conn = url1.openConnection();
+ conn.setRequestProperty("Authorization","Bearer " + accessToken);
+ BASE64Encoder encoder = new BASE64Encoder();
+
+
+ List <String> headerN = new java.util.ArrayList();
+ List <String> headerV = new java.util.ArrayList();
+ try{
+ for (int i=0; ; i++) {
+
+ String headerName = conn.getHeaderFieldKey(i);
+ String headerValue = conn.getHeaderField(i);
+ System.out.print("headerName: "+headerName+ " ");
+ System.out.println("header :" + headerValue);
+ headerN.add(headerName);
+ headerV.add(headerValue);
+ if (headerName == null && headerValue == null) {
+ // No more headers
+ break;
+ }
+ if (headerName == null) {
+ // The header value contains the server's HTTP version
+ }
+ }
+ } catch (Exception e) {
+ }
+ String cont = "";
+
+ String[] resHeaders = (String[]) headerN.toArray(new String[0]);
+ String[] resValues = (String[]) headerV.toArray(new String[0]);
+ String []tokens = new String [2];
+ String []tokens1 = new String [2];
+
+
+ if(resHeaders[4].equals("Content-Type")) //works
+ {
+ tokens = resValues[4].split(";");
+ System.out.println(tokens[0]); //tokens[0] contains IMAGE/JPEG
+
+ tokens1 = tokens[0].split("/"); //tokens1[0] contains IMAGE
+ System.out.println(tokens1[0]);
+ }
+ //Send the request, parse based on HTTP status code
+ int statusCode = client.executeMethod(method);
+ System.out.println("response bod is: "+method.getResponseBodyAsString());
+ if(statusCode==200) {
+ if((tokens1[0]).equalsIgnoreCase("TEXT")){%>
+ <div class="successWide" align="left">
+ <strong>SUCCESS:</strong><br /><%=method.getResponseBodyAsString()%><br />
+ </div>
+ <br />
+ <br />
+ <%
+ }
+
+ else if((tokens1[0]).equalsIgnoreCase("APPLICATION")){%>
+ <div class="successWide" align="left">
+ <strong>SUCCESS:</strong><br />
+ </div>
+ <br />
+ <br />
+ <div style="text-align: center">
+ <div id="smilpanel">
+ <textarea id="TextBox1" class="aspNetDisabled"
+ style="height: 100px; width: 500px;" disabled="disabled" cols="20"
+ rows="2" name="TextBox1"><%=method.getResponseBodyAsString()%></textarea>
+ </div>
+ </div>
+ <br />
+ <%}
+ else
+ if((tokens1[0]).equals("IMAGE")){
+ byte[] encoded = method.getResponseBodyAsString().getBytes();
+ Base64 dat = new Base64();
+
+ %>
+ <div id="imagePanel" style="text-align: center;">
+ <img src = "data:<%=tokens[0]%>;base64,<%=dat.encodeBase64String(method.getResponseBody())%>"/>
+ <br />
+ <%}
+ method.releaseConnection();
+ }
+ else if( msgContent!=null && request.getParameter("MessageId")==""){
+ %><div class="errorWide">
+ <strong>ERROR:</strong> Message Id field is empty.<br />
+ </div><br /><%
+ method.releaseConnection();}
+ else if( msgContent!=null && request.getParameter("MessageId")=="" && request.getParameter("PartNumber")!=""){
+ %><div class="errorWide">
+ <strong>ERROR:</strong> Message Id field is empty.<br />
+ </div><br /><%
+ method.releaseConnection();}
+ else if( msgContent!=null && request.getParameter("PartNumber")==""){
+ %><div class="errorWide">
+ <strong>ERROR:</strong> Part Number field is empty.<br />
+ </div><br /><%
+ method.releaseConnection();}
+ else {%>
+ <div class="errorWide">
+ <strong>ERROR:</strong><br />
+ <%=method.getResponseBodyAsString()%>
+ </div>
+ <br />
+ <%}
+} %>
+
+ <div id="footer">
+ <div
+ style="float: right; width: 20%; font-size: 9px; text-align: right">
+ Powered by AT&amp;T Cloud Architecture</div>
+
+ <p>