Skip to content

Instantly share code, notes, and snippets.

@t2-support-gists
Created May 3, 2012 20:59
Show Gist options
  • Save t2-support-gists/2589429 to your computer and use it in GitHub Desktop.
Save t2-support-gists/2589429 to your computer and use it in GitHub Desktop.
MMS Java RESTFul App 1
<!--
Licensed by AT&T under 'Software Development Kit Tools Agreement.'
2013 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION:
http://developer.att.com/sdk_agreement/ Copyright 2013 AT&T Intellectual
Property. All rights reserved. http://developer.att.com For more information
contact [email protected] -->
-->
AT&T API Platform Sample Application
-------------------------------------
This file describes how to set up, configure, and run the Java Application
using AT&T's API Platform services. It covers all steps required to register
the application, and create and run one's own full-fledged sample applications
based on the generated API keys and secrets.
1. Configuration
Configuration consists of a few steps necessary to get an application
registered 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--particularly all fields marked as "required."
NOTE: You MUST select the application used 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 APIs. See 'Adjusting parameters' below to learn how to
use these keys.
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 will need the Java Runtime Environment (JRE), Java
Development Kit (JDK), and Apache Maven.
** Setting up multiple sample applications simultaneously
In case multiple applications need to be run at the same time, make sure to
put each app in separate folders.
3. Parameters
Each sample application contains an application.properties file. This file
is located in the 'src/main/resources/' folder. This file holds configurable
parameters described in an easy-to-read format. Please modify the
application.properties file using the comments specified within the file.
Note: If your application is promoted from Sandbox environment to Production
environment and you decide to use production application settings, you must
update parameters as per production application details.
4. Running the application
The project follows Apache Maven's Standard Directory Layout and can be
built using Apache Maven. For information about Apache Maven and for more
detailed instructions, consult Apache Maven's documentation.
Using a terminal, change the current directory to the root folder of the
sample application (the directory should contain pom.xml). Run the following
command in order to build and run the application:
mvn clean jetty:run
This command should run the application on port 8080. Make sure no other
application is running on port 8080. In order to change the port, consult
Jetty's documentation. To connect to the sample application, open a web
browser and visit 'http://localhost:8080/<appname>' replacing <appname> with
the application's name.
<%
String clientIdAut = "";
String clientSecretAut = "";
String shortCode1 = "";
String FQDN = "https://api.att.com";
%>
<%@ 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.json.JSONArray"%>
<%@ page import="java.io.*" %>
<%@ include file="OauthStorage.jsp" %>
<%@ include file="config.jsp" %>
<%
//Initialize some variables here, check if relevant variables were passed in, if not then check session, otherwise set default.
String scope = "MMS";
String accessToken = "";
String refreshToken = "";
String expires_in = "";
Long date = System.currentTimeMillis();
//This application uses the Autonomous Client OAuth consumption model
//Check if there is a valid access token that has not expired
if(date < savedAccessTokenExpiry) {
accessToken = savedAccessToken;
} else if(date < savedRefreshTokenExpiry) { //Otherwise if there is a refresh token that has not expired, use that to renew and save to file
String url = FQDN + "/oauth/token";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
String b = "client_id=" + clientIdAut + "&client_secret=" + clientSecretAut + "&grant_type=refresh_token&refresh_token=" + savedRefreshToken;
method.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
method.setRequestBody(b);
int statusCode = client.executeMethod(method);
JSONObject rpcObject = new JSONObject(method.getResponseBodyAsString());
accessToken = rpcObject.getString("access_token");
refreshToken = rpcObject.getString("refresh_token");
expires_in = rpcObject.getString("expires_in");
savedAccessTokenExpiry = date + (Long.parseLong(expires_in)*1000);
savedRefreshTokenExpiry = date + Long.parseLong("86400000");
method.releaseConnection();
PrintWriter outWrite = new PrintWriter(new BufferedWriter(new FileWriter(application.getRealPath("/OauthStorage.jsp"))), false);
String toSave = "\u003C\u0025\nString savedAccessToken = \"" + accessToken + "\";\nLong savedAccessTokenExpiry = Long.parseLong(\"" + savedAccessTokenExpiry + "\");\nString savedRefreshToken = \"" + refreshToken + "\";\nLong savedRefreshTokenExpiry = Long.parseLong(\"" + savedRefreshTokenExpiry + "\");\n\u0025\u003E";
outWrite.write(toSave);
outWrite.close();
} else if(date > savedRefreshTokenExpiry) { //Otherwise get a new access token and refresh token, and save them to file
String url = FQDN + "/oauth/token";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
String b = "client_id=" + clientIdAut + "&client_secret=" + clientSecretAut + "&grant_type=client_credentials&scope=" + scope;
method.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
method.setRequestBody(b);
int statusCode = client.executeMethod(method);
JSONObject rpcObject = new JSONObject(method.getResponseBodyAsString());
accessToken = rpcObject.getString("access_token");
refreshToken = rpcObject.getString("refresh_token");
expires_in = rpcObject.getString("expires_in");
savedAccessTokenExpiry = date + (Long.parseLong(expires_in)*1000);
savedRefreshTokenExpiry = date + Long.parseLong("86400000");
method.releaseConnection();
PrintWriter outWrite = new PrintWriter(new BufferedWriter(new FileWriter(application.getRealPath("/OauthStorage.jsp"))), false);
String toSave = "\u003C\u0025\nString savedAccessToken = \"" + accessToken + "\";\nLong savedAccessTokenExpiry = Long.parseLong(\"" + savedAccessTokenExpiry + "\");\nString savedRefreshToken = \"" + refreshToken + "\";\nLong savedRefreshTokenExpiry = Long.parseLong(\"" + savedRefreshTokenExpiry + "\");\n\u0025\u003E";
outWrite.write(toSave);
outWrite.close();
}
%>
<%@ Page Language="C#" %>
<
<!DOCTYPE html>
<!--
Licensed by AT&T under 'Software Development Kit Tools Agreement.'
September 2011
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION:
http://developer.att.com/sdk_agreement/
Copyright 2011 AT&T Intellectual Property. All rights reserved.
http://developer.att.com
For more information contact [email protected]
-->
<!--[if lt IE 7]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<title>AT&amp;T Sample Speech Application - Speech to Text (Generic) </title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style/common.css">
</head>
<body>
<div id="pageContainer" class="pageContainer">
<div id="header">
<div class="logo" id="top">
</div>
<div id="menuButton" class="hide">
<a id="jump" href="#nav">Main Navigation</a>
</div>
<ul class="links" id="nav">
<li><a href="#" target="_blank">Full Page<img src="images/max.png"></img></a> <span
class="divider">|&nbsp;</span> </li>
<!-- href value changes for each app -->
<li><a href="https://gist.github.com/3036563" target="_blank">Source<img src="images/opensource.png" /></a>
<span class="divider">|&nbsp;</span> </li>
<!-- href value changes for each app -->
<li><a href="https://github.com/attdevsupport/ATT_APIPlatform_SampleApps_Dev/tree/master/RESTFul/Speech/Ruby/app1"
target="_blank">Download<img src="images/download.png"></a> <span class="divider">|&nbsp;</span>
</li>
<!-- href value changes for each app -->
<li><a href="https://github.com/attdevsupport/ATT_APIPlatform_SampleApps_Dev/blob/master/RESTFul/Speech/Ruby/app1/README.txt"
target="_blank">Help</a> </li>
<li id="back"><a href="#top">Back to top</a> </li>
</ul>
<!-- end of links -->
</div>
<!-- end of header -->
<div class="content">
<div class="contentHeading">
<h1>
AT&amp;T Sample Application - Speech to Text</h1>
<div id="introtext">
<div>
<b>Server Time:</b> Wed, January 09, 2013 18:19:16 UTC</div>
<div>
<b>Client Time:</b>
<script> document.write("" + new Date());</script>
</div>
<div>
<b>User Agent:</b>
<script> document.write("" + navigator.userAgent);</script>
</div>
</div>
<!-- end of introtext -->
</div>
<!-- end of contentHeading -->
<div class="formBox" id="formBox">
<div id="formContainer" class="formContainer">
<form name="SpeechToText" action="SpeechToText" method="post" enctype="multipart/form-data">
<div id="formData">
<h3>
Speech Context:</h3>
<select name="SpeechContext">
<option value="Generic" selected="selected">Generic</option>
<option value="TV">TV</option>
<option value="BusinessSearch">BusinessSearch</option>
<option value="Websearch">Websearch</option>
<option value="SMS">SMS</option>
<option value="Voicemail">Voicemail</option>
<option value="QuestionAndAnswer">QuestionAndAnswer</option>
</select>
<h3>
Audio File:</h3>
<select name="audio_file">
<option value="bostonseltics.wav" selected="selected">bostonseltics.wav</option>
<option value="california.amr">california.amr</option>
<option value="coffee.amr">coffee.amr</option>
<option value="doctors.wav">doctors.wav</option>
<option value="nospeech.wav">nospeech.wav</option>
<option value="samplerate_conflict_error.wav">samplerate_conflict_error.wav</option>
<option value="this_is_a_test.spx">this_is_a_test.spx</option>
<option value="too_many_channels_error.wav">too_many_channels_error.wav</option>
</select>
</br>
<div id="chunked">
<b>Send Chunked:</b>
<input name="chkChunked" value="Send Chunked" type="checkbox">
</div>
<h3>
X-Arg:</h3>
<textarea id="x_arg" type="text" name="x_arg" readonly="readonly" rows="4" value="test=123">test=123</textarea>
<br>
<button type="submit" name="SpeechToText">
Submit</button>
</div>
</form>
</div>
</div>
<!-- This is for success -->
<div class="successWide" align="left">
<strong>SUCCESS:</strong>
<br />
Response parameters listed below.
</div>
<table class="kvp">
<thead>
<tr>
<th class="label">
Parameter
</th>
<th class="label">
Value
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cell" align="center">
<em>ResponseId</em>
</td>
<td class="cell" align="center">
<em>be6266832bb6e9edd496a55aa8b42513</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Status</em>
</td>
<td class="cell" align="center">
<em>OK</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Hypothesis</em>
</td>
<td class="cell" align="center">
<em>boston celtics</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>LanguageId</em>
</td>
<td class="cell" align="center">
<em>en-US</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Confidence</em>
</td>
<td class="cell" align="center">
<em>1</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Grade</em>
</td>
<td class="cell" align="center">
<em>accept</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>ResultText</em>
</td>
<td class="cell" align="center">
<em>Boston celtics.</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Words</em>
</td>
<td class="cell" align="center">
<em>Boston, celtics.</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>WordScores</em>
</td>
<td class="cell" align="center">
<em>1, 1</em>
</td>
</tr>
</tbody>
</table>
<!-- This is for error -->
<div class="errorWide">
<strong>ERROR:</strong>
<br />
{"RequestError": { "ServiceException": { "MessageId": "SVC0001", "Text": "audiostream-wav:
too many channels [2]", "Variables": "" } }}
</div>
</div>
<!-- end of content -->
<div id="footer">
<div id="ft">
<div id="powered_by">
Powered by AT&amp;T Cloud Architecture
</div>
<p>
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>
<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:[email protected]">[email protected]</a>
<br>
<br>
© 2012 AT&amp;T Intellectual Property. All rights reserved. <a href="http://developer.att.com/"
target="_blank">http://developer.att.com</a>
</p>
</div>
<!-- end of ft -->
</div>
<!-- end of footer -->
</div>
<!-- end of page_container -->
</body>
</html>
<!DOCTYPE html>
<!--
Licensed by AT&T under 'Software Development Kit Tools Agreement.'
September 2011
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION:
http://developer.att.com/sdk_agreement/
Copyright 2011 AT&T Intellectual Property. All rights reserved.
http://developer.att.com
For more information contact [email protected]
-->
<!--[if lt IE 7]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<title>AT&amp;T Sample Speech Application - Speech to Text (Generic) </title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta id="Meta1" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style/common.css">
</head>
<body>
<div id="Div1" class="pageContainer">
<div id="Div2">
<div class="logo" id="Div3">
</div>
<div id="Div4" class="hide">
<a id="A1" href="#nav">Main Navigation</a>
</div>
<ul class="links" id="Ul1">
<li><a href="#" target="_blank">Full Page<img src="images/max.png"></img></a> <span
class="divider">|&nbsp;</span> </li>
<li><a href="https://gist.github.com/3036563" target="_blank">Source<img src="images/opensource.png" /></a>
<span class="divider">|&nbsp;</span> </li>
<li><a href="https://github.com/attdevsupport/ATT_APIPlatform_SampleApps_Dev/tree/master/RESTFul/Speech/Ruby/app1"
target="_blank">Download<img src="images/download.png"></a> <span class="divider">|&nbsp;</span>
</li>
<li><a href="https://github.com/attdevsupport/ATT_APIPlatform_SampleApps_Dev/blob/master/RESTFul/Speech/Ruby/app1/README.txt"
target="_blank">Help</a> </li>
<li id="Li1"><a href="#top">Back to top</a> </li>
</ul>
<!-- end of links -->
</div>
<!-- end of header -->
<div class="content">
<div class="contentHeading">
<h1>
AT&amp;T Sample Application - Speech to Text</h1>
<div id="Div5">
<div>
<b>Server Time:</b> Wed, January 09, 2013 18:19:16 UTC</div>
<div>
<b>Client Time:</b>
<script> document.write("" + new Date());</script>
</div>
<div>
<b>User Agent:</b>
<script> document.write("" + navigator.userAgent);</script>
</div>
</div>
<!-- end of introtext -->
</div>
<!-- end of contentHeading -->
<div class="formBox" id="Div6">
<div id="Div7" class="formContainer">
<form name="SpeechToText" action="SpeechToText" method="post" enctype="multipart/form-data">
<div id="Div8">
<h3>
Speech Context:</h3>
<select name="SpeechContext">
<option value="Generic" selected="selected">Generic</option>
<option value="TV">TV</option>
<option value="BusinessSearch">BusinessSearch</option>
<option value="Websearch">Websearch</option>
<option value="SMS">SMS</option>
<option value="Voicemail">Voicemail</option>
<option value="QuestionAndAnswer">QuestionAndAnswer</option>
</select>
<h3>
Audio File:</h3>
<select name="audio_file">
<option value="bostonseltics.wav" selected="selected">bostonseltics.wav</option>
<option value="california.amr">california.amr</option>
<option value="coffee.amr">coffee.amr</option>
<option value="doctors.wav">doctors.wav</option>
<option value="nospeech.wav">nospeech.wav</option>
<option value="samplerate_conflict_error.wav">samplerate_conflict_error.wav</option>
<option value="this_is_a_test.spx">this_is_a_test.spx</option>
<option value="too_many_channels_error.wav">too_many_channels_error.wav</option>
</select>
</br>
<div id="Div9">
<b>Send Chunked:</b>
<input name="chkChunked" value="Send Chunked" type="checkbox">
</div>
<h3>
X-Arg:</h3>
<textarea id="Textarea1" type="text" name="x-arg" readonly="readonly" rows="4" value="test=123">test=123</textarea>
<br>
<button type="submit" name="SpeechToText">
Submit</button>
</div>
</form>
</div>
</div>
<!-- This is for success -->
<div class="successWide" align="left">
<strong>SUCCESS:</strong>
<br />
Response parameters listed below.
</div>
<table class="kvp">
<thead>
<tr>
<th class="label">
Parameter
</th>
<th class="label">
Value
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cell" align="center">
<em>ResponseId</em>
</td>
<td class="cell" align="center">
<em>be6266832bb6e9edd496a55aa8b42513</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Status</em>
</td>
<td class="cell" align="center">
<em>OK</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Hypothesis</em>
</td>
<td class="cell" align="center">
<em>boston celtics</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>LanguageId</em>
</td>
<td class="cell" align="center">
<em>en-US</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Confidence</em>
</td>
<td class="cell" align="center">
<em>1</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Grade</em>
</td>
<td class="cell" align="center">
<em>accept</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>ResultText</em>
</td>
<td class="cell" align="center">
<em>Boston celtics.</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>Words</em>
</td>
<td class="cell" align="center">
<em>Boston, celtics.</em>
</td>
</tr>
<tr>
<td class="cell" align="center">
<em>WordScores</em>
</td>
<td class="cell" align="center">
<em>1, 1</em>
</td>
</tr>
</tbody>
</table>
<!-- This is for error -->
<div class="errorWide">
<strong>ERROR:</strong>
<br />
{"RequestError": { "ServiceException": { "MessageId": "SVC0001", "Text": "audiostream-wav:
too many channels [2]", "Variables": "" } }}
</div>
</div>
<!-- end of content -->
<div id="Div10">
<div id="Div11">
<div id="Div12">
Powered by AT&amp;T Cloud Architecture
</div>
<p>
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>
<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:[email protected]">[email protected]</a>
<br>
<br>
© 2012 AT&amp;T Intellectual Property. All rights reserved. <a href="http://developer.att.com/"
target="_blank">http://developer.att.com</a>
</p>
</div>
<!-- end of ft -->
</div>
<!-- end of footer -->
</div>
<!-- end of page_container -->
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<title>AT&amp;T Sample MMS Application 1 - Basic SMS 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"/ >
<script type="text/javascript" src="js/helper.js">
</script>
<body>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%@ page import="com.sun.jersey.multipart.file.*" %>
<%@ page import="com.sun.jersey.multipart.BodyPart" %>
<%@ page import="com.sun.jersey.multipart.MultiPart" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.List" %>
<%@ page import="com.att.rest.*" %>
<%@ page import="java.net.*" %>
<%@ page import="javax.ws.rs.core.*" %>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.util.List,java.util.Iterator"%>
<%@ page import="org.json.*"%>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="javax.xml.transform.*" %>
<%@ page import="javax.xml.transform.stream.*" %>
<%@ page import="javax.xml.transform.dom.*" %>
<%@ page import="org.apache.commons.httpclient.*"%>
<%@ page import="org.apache.commons.httpclient.methods.*"%>
<%@ include file="getToken.jsp" %>
<%
String redirectUri = "";
String getMmsDeliveryStatus = request.getParameter("getMmsDeliveryStatus");
String mmsId = request.getParameter("mmsId");
if (mmsId==null) mmsId = (String) session.getAttribute("mmsId");
if (mmsId==null) mmsId = "";
String sendMms = request.getParameter("sendMms");
String contentBodyFormat = "FORM-ENCODED";
String address = request.getParameter("address");
if(address==null || address.equalsIgnoreCase("null"))
address = (String) session.getAttribute("addressSms2");
if(address==null || address.equalsIgnoreCase("null"))
address = "425-802-8620";
String fileName = "";
String subject = (String) session.getAttribute("subject");
if(subject==null || subject.equalsIgnoreCase("null"))
subject = "simple message to myself";
String priority = "High";
String responseFormat = "json";
String requestFormat = "json";
String endpoint = FQDN + "/rest/mms/2/messaging/outbox";
String senderAddress = shortCode1;
//If Send MMS button was clicked, do this to get some parameters from the form.
if(request.getParameter("sendMms")!=null) {
try{
DiskFileUpload fu = new DiskFileUpload();
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField()) {
File fNew= new File(application.getRealPath("/"), fi.getName());
fileName = fileName + "," + fi.getName();
if(!(fi.getName().equalsIgnoreCase(""))){
fi.write(fNew);
}
} else if(fi.getFieldName().equalsIgnoreCase("address")) {
address = fi.getString();
session.setAttribute("addressSms2",address);
} else if(fi.getFieldName().equalsIgnoreCase("subject")) {
subject = fi.getString();
session.setAttribute("subject",subject);
}
}
} catch(Exception e){};
}
%>
<div id="container">
<!-- open HEADER --><div id="header">
<div>
<div id="hcRight">
<%=new java.util.Date()%>
</div>
<div id="hcLeft">Server Time:</div>
</div>
<div>
<div id="hcRight"><script language="JavaScript" type="text/javascript">
var myDate = new Date();
document.write(myDate);
</script></div>
<div id="hcLeft">Client Time:</div>
</div>
<div>
<div id="hcRight"><script language="JavaScript" type="text/javascript">
document.write("" + navigator.userAgent);
</script></div>
<div id="hcLeft">User Agent:</div>
</div>
<br clear="all" />
</div><!-- close HEADER -->
<div id="wrapper">
<div id="content">
<h1>AT&amp;T Sample MMS Application 1 - Basic MMS Service Application</h1>
<h2>Feature 1: Send MMS Message</h2>
</div>
</div>
<form method="post" name="sendMms" enctype="multipart/form-data" action="MMS.jsp?sendMms=true">
<div id="navigation">
<table border="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top" class="label">Phone:</td>
<td class="cell"><input maxlength="16" size="12" name="address" value="<%=address%>" style="width: 90%">
</td>
</tr>
<tr>
<td valign="top" class="label">Message:</td>
<td class="cell"><textarea rows="4" name="subject" style="width: 90%"><%=subject%></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div id="extra">
<div class="warning">
<strong>WARNING:</strong><br />
total size of all attachments cannot exceed 600 KB.
</div>
<table border="0" width="100%">
<tbody>
<tr>
<td valign="top" class="label">Attachment 1:</td>
<td class="cell"><input name="f1" type="file">
</td>
</tr>
<tr>
<td valign="top" class="label">Attachment 2:</td>
<td class="cell"><input name="f2" type="file">
</td>
</tr>
<tr>
<td valign="top" class="label">Attachment 3:</td>
<td class="cell"><input name="f3" type="file">
</td>
</tr>
</tbody></table>
<table>
<tbody>
<tr>
<td><button type="submit" name="sendMms">Send MMS Message</button></td>
</tr>
</tbody></table>
</div>
<br clear="all" />
<div align="center"></div>
</form>
<%
//If Send MMS button was clicked, do this.
if(request.getParameter("sendMms")!=null) {
//Check for a few known formats the user could have entered the address, adjust accordingly
String invalidAddress = null;
if((address.indexOf("-")==3) && (address.length()==12))
address = "tel:" + address.substring(0,3) + address.substring(4,7) + address.substring(8,12);
else if((address.indexOf(":")==3) && (address.length()==14))
address = address;
else if((address.indexOf("-")==-1) && (address.length()==10))
address = "tel:" + address;
else if((address.indexOf("-")==-1) && (address.length()==11))
address = "tel:" + address.substring(1);
else if((address.indexOf("-")==-1) && (address.indexOf("+")==0) && (address.length()==12))
address = "tel:" + address.substring(2);
else
invalidAddress = "yes";
if(invalidAddress==null) {
if(fileName.equalsIgnoreCase(""))
fileName = (String) session.getAttribute("fileName");
String attachmentsStr = fileName;
String[] attachments = attachmentsStr.split(",");
MediaType contentBodyType = null;
String requestBody = "";
MultiPart mPart;
contentBodyType = MediaType.MULTIPART_FORM_DATA_TYPE;
JSONObject requestObject = new JSONObject();
requestObject.put("Priority", priority);
requestObject.put("Address", address);
requestObject.put("Subject", subject);
requestObject.put("content-type", "image/jpeg");
requestBody += requestObject.toString();
mPart = new MultiPart().bodyPart(new BodyPart(requestBody,MediaType.APPLICATION_JSON_TYPE));
mPart.getBodyParts().get(0).getHeaders().add("Content-Transfer-Encoding", "8bit");
mPart.getBodyParts().get(0).getHeaders().add("Content-Disposition","form-data; name=\"root-fields\"");
mPart.getBodyParts().get(0).getHeaders().add("Content-ID", "<startpart>");
MediaType[] medTyp = new MediaType[4];
for(int i=1;i<attachments.length; i++) {
FileDataBodyPart fIlE = new FileDataBodyPart();
medTyp[i] = fIlE.getPredictor().getMediaTypeFromFileName("/" + attachments[i]);
}
ServletContext context = getServletContext();
if(attachments.length == 2){
mPart.bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[1]), medTyp[1]));
} else if(attachments.length == 3) {
mPart.bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[1]), medTyp[1])).bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[2]), medTyp[2]));
} else if(attachments.length == 4) {
mPart.bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[1]), medTyp[1])).bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[2]), medTyp[2])).bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[3]), medTyp[3]));
}
// This currently uses a proprietary rest client to assemble the request body that does not follow SMIL standards. It is recommended to follow SMIL standards to ensure attachment delivery.
RestClient client;
client = new RestClient(endpoint, contentBodyType, MediaType.APPLICATION_JSON_TYPE);
client.addParameter("access_token", accessToken);
client.addRequestBody(mPart);
String responze = client.invoke(com.att.rest.HttpMethod.POST, true);
if (client.getHttpResponseCode() == 201) {
JSONObject rpcObject = new JSONObject(responze);
mmsId = rpcObject.getString("Id");
session.setAttribute("mmsId", mmsId);
%>
<div class="successWide">
<strong>SUCCESS:</strong><br />
<strong>Message ID:</strong> <%=mmsId%>
</div><br/>
<%
} else {
%>
<div class="errorWide">
<strong>ERROR:</strong><br />
<%=responze%>
</div><br/>
<%
}
} else { %>
<div class="errorWide">
<strong>ERROR:</strong><br />
Invalid Address Entered
</div><br/>
<% }
}
%>
<div id="wrapper">
<div id="content">
<h2><br />
Feature 2: Get Delivery Status</h2>
</div>
</div>
<form method="post" name="getMmsDeliveryStatus" action="MMS.jsp">
<div id="navigation">
<table border="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top" class="label">Message ID:</td>
<td class="cell"><input size="12" name="mmsId" value="<%=mmsId%>" style="width: 90%">
</td>
</tr>
</tbody></table>
</div>
<div id="extra">
<table border="0" width="100%">
<tbody>
<tr>
<td class="cell"><button type="submit" name="getMmsDeliveryStatus">Get Status</button>
</td>
</tr>
</tbody></table>
</div>
<br clear="all" />
</form>
<%
//If Check Delivery Status button was clicked, do this.
if(getMmsDeliveryStatus!=null) {
String url = FQDN + "/rest/mms/2/messaging/outbox/" + mmsId;
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url);
method.setQueryString("access_token=" + accessToken + "&id=" + mmsId);
method.addRequestHeader("Accept","application/" + responseFormat);
int statusCode = client.executeMethod(method);
if(statusCode==200) {
JSONObject jsonResponse = new JSONObject(method.getResponseBodyAsString());
JSONObject deliveryInfoList = new JSONObject(jsonResponse.getString("DeliveryInfoList"));
JSONArray deliveryInfoArray = new JSONArray(deliveryInfoList.getString("DeliveryInfo"));
JSONObject deliveryInfo = new JSONObject(deliveryInfoArray.getString(0));
%>
<div class="successWide">
<strong>SUCCESS:</strong><br />
<strong>Status:</strong> <%=deliveryInfo.getString("DeliveryStatus")%><br />
<strong>Resource URL:</strong> <%=deliveryInfoList.getString("ResourceURL")%>
</div><br/>
<%
} else {
%>
<div class="errorWide">
<strong>ERROR:</strong><br />
<%=method.getResponseBodyAsString()%>
</div><br/>
<%
}
method.releaseConnection();
}
%>
<div id="footer">
<div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&amp;T Virtual Mobile</div>
<p>&#169; 2011 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:[email protected]">[email protected]</a>
</div>
</div>
</body></html>
<%
String savedAccessToken = "ad13138f408bbdaabbdafa355b0b9ee8";
Long savedAccessTokenExpiry = Long.parseLong("4062272533");
String savedRefreshToken = "eb039c57a6efa7216e06a5114cce4a7f6576f2f3";
Long savedRefreshTokenExpiry = Long.parseLong("4148665334");
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment