Permalink
Browse files

.

  • Loading branch information...
attdevsupport
attdevsupport committed Jul 11, 2012
1 parent 55b9f0c commit daf89dbe561115035050315e3e42f6885b74e259
Showing with 104 additions and 98 deletions.
  1. +34 −30 Speech/Java/app1/README.txt
  2. +53 −52 Speech/Java/app1/Speech.jsp
  3. +17 −16 Speech/Java/app1/getToken.jsp
@@ -1,15 +1,9 @@
-<!--
-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
--->
-
-AT&T API Samples - Speech app 1
+
+ AT&T API Samples - SMS app 1
------------------------------
-This file describes how to set up, configure and run the Java Applications of the AT&T HTML5 Program sample applications.
-It covers all steps required to register the application on DevConnect and, based on the generated API keys and secrets,
+This file describes how to set up, configure and run the Java Applications of the AT&T HTML5 Program 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
@@ -20,25 +14,30 @@ create and run one's own full-fledged sample applications.
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).
+ 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.
+ 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 Speech in the list of services under field 'Services' in order to use this sample application code.
+ Be careful while filling in the "OAuth Redirect URL" field. It should contain the URL that the oAuth provider will redirect
+ users to when he/she successfully authenticates and authorizes your application. For this application, it should point to
+ the oauth.jsp file inside this application folder. For example, if running on a local machine in a default Tomcat installation,
+ your OAuth Redirect URL might be http://localhost:8080/SampleApp/oauth.jsp
+
+NOTE: You MUST select SMS 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 HTML5 APIs. See 'Adjusting parameters' below to learn how to use
+ 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 HTML5 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
+ 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).
@@ -47,36 +46,41 @@ create and run one's own full-fledged sample applications.
** Requirements
- To run the examples you need a Java environment and at least Apache Tomcat 6, or another Java web server such as Jetty.
+ To run the examples you need a Java environment and at least Apache Tomcat 6, or another Java web server such as Jetty.
** 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 a separate folder and
+ In case multiple applications need to be run at the same time, make sure to put each app in a separate folder and
adjust your OAuth Redirect URL accordingly.
-
3. Parameters
-Each sample application contains a config.jsp file. It holds configurable parameters described in an easy to read format.
+Each sample application contains a config.jsp file. It holds configurable parameters described in an easy to read format.
Please populate the following parameters in config.jsp as specified below:
-1) clientIdWeb : {set the value as per your registered appliaction 'API key' field value}
+1) savedAccessToken { This will be populated with a saved access token}
+
+2) savedAccessTokenExpiry { This represents when the saved access token will expire }
-2) clientSecretWeb : {set the value as per your registered appliaction 'Secret key' field value}
+3) savedRefreshToken { This will be populated with a refresh token }
-3) FQDN : https://api.att.com
+4) savedRefreshTokenExpiry {This represents when the saved refresh token will expire}
-Note: If your application is promoted from Sandbox environment to Production environment and you decide to use production
+
+
+Note: If your application is promoted from Sandbox environment to Production environment and you decide to use production
application settings, you must update parameters 1-2 as per production application details.
4. Running the application
- To run the application, put the entire contents of the application folder into a separate folder named SampleApp inside the webapps
- folder in your Apache Tomcat home directory. If you have specified a different home directory in Tomcat for your web applications,
- put it there instead.
+ To run the application, put the entire contents of the application folder into a separate folder named SampleApp inside the webapps
+ folder in your Apache Tomcat home directory. If you have specified a different home directory in Tomcat for your web applications,
+ put it there instead.
Depending on your security settings in Apache Tomcat, you might need to enable write access to the OauthStorage.jsp file.
- Once you start tomcat, typically using the command "<your-tomcat-root-folder>/bin/startup.sh", your application becomes available
- in a web browser, so you may visit: http://localhost:8080/SampleAppFolder/Speech.jsp to see it working.
+ Once you start tomcat, typically using the command "<your-tomcat-root-folder>/bin/startup.sh", your application becomes available
+ in a web browser, so you may visit: http://localhost:8080/SampleApp/SMS.jsp to see it working.
+
+
View
@@ -5,6 +5,58 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.a
Copyright 2011 AT&T Intellectual Property. All rights reserved. http://developer.att.com
For more information contact developer.support@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="com.sun.jersey.multipart.file.*" %>
+<%@ page import="com.sun.jersey.multipart.BodyPart" %>
+<%@ page import="com.sun.jersey.multipart.MultiPart" %>
+<%@ page import="com.att.rest.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.ws.rs.core.*" %>
+<%@ page import="org.json.*"%>
+<%@ page import="org.json.JSONObject"%>
+<%@ page import="org.json.JSONArray"%>
+<%@ page import="org.w3c.dom.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="javax.xml.transform.*" %>
+<%@ page import="javax.xml.transform.stream.*" %>
+<%@ page import="org.apache.commons.fileupload.*"%>
+<%@ page import="javax.xml.transform.dom.*" %>
+<%@ page import="java.io.*" %>
+<%@ page import="java.util.List"%>
+<%@ page import="java.util.Iterator"%>
+<%@ page import="java.io.File"%>
+<%@ page import="org.apache.commons.fileupload.*"%>
+<%@ page import="org.apache.commons.fileupload.disk.*"%>
+<%@ page import="org.apache.commons.fileupload.servlet.*"%>
+<%@ include file="getToken.jsp"%>
+<%@ page import="java.util.*"%>
+<%@ page import="java.net.URL"%>
+<%@ page import="java.net.URLConnection"%>
+<%@ page import="java.net.URLEncoder,java.io.*"%>
+<%@ page import="org.apache.commons.httpclient.HttpClient"%>
+<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
+<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
+<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
+<%@ page import="org.apache.http.util.EntityUtils"%>
+<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
+<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
+<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
+<%@ page import="org.apache.http.HttpEntity"%>
+<%@ page import="org.apache.http.HttpResponse"%>
+<%@ page import="org.apache.http.client.methods.HttpPost"%>
+
+<%@ page import="org.apache.http.client.ResponseHandler"%>
+
+<%@ page import="org.apache.http.client.methods.HttpGet"%>
+<%@ page import="org.apache.http.impl.client.BasicResponseHandler"%>
+
+<%@ page import="org.apache.commons.httpclient.HttpClient"%>
+<%@ page import="org.apache.commons.httpclient.HostConfiguration"%>
+<%@ page import="org.apache.commons.httpclient.methods.GetMethod"%>
+<%@ page import="org.apache.http.entity.mime.content.StringBody"%>
+<%@ page import="org.apache.http.entity.FileEntity"%>
<!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">
@@ -73,7 +125,7 @@ For more information contact developer.support@att.com
<div id = "extraleft">
<div class="warning">
<strong>Note:</strong><br />
- If no file is chosen, a <a href="./bostonSeltics.wav">default .wav</a>will be loaded on submit.<br />
+ If no file chosen, a <a href="./bostonSeltics.wav">default.wav</a> will be loaded on submit.<br />
<strong>Speech file format constraints:</strong> <br />
* 16 bit PCM WAV, single channel, 8 kHz sampling<br />
* AMR (narrowband), 12.2 kbit/s, 8 kHz sampling<br />
@@ -97,58 +149,7 @@ For more information contact developer.support@att.com
</form>
<br clear="all" />
- <%@ 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="com.sun.jersey.multipart.file.*" %>
-<%@ page import="com.sun.jersey.multipart.BodyPart" %>
-<%@ page import="com.sun.jersey.multipart.MultiPart" %>
-<%@ page import="com.att.rest.*" %>
-<%@ page import="java.net.*" %>
-<%@ page import="javax.ws.rs.core.*" %>
-<%@ page import="org.json.*"%>
-<%@ page import="org.json.JSONObject"%>
-<%@ page import="org.json.JSONArray"%>
-<%@ page import="org.w3c.dom.*" %>
-<%@ page import="javax.xml.parsers.*" %>
-<%@ page import="javax.xml.transform.*" %>
-<%@ page import="javax.xml.transform.stream.*" %>
-<%@ page import="org.apache.commons.fileupload.*"%>
-<%@ page import="javax.xml.transform.dom.*" %>
-<%@ page import="java.io.*" %>
-<%@ page import="java.util.List"%>
-<%@ page import="java.util.Iterator"%>
-<%@ page import="java.io.File"%>
-<%@ page import="org.apache.commons.fileupload.*"%>
-<%@ page import="org.apache.commons.fileupload.disk.*"%>
-<%@ page import="org.apache.commons.fileupload.servlet.*"%>
-<%@ include file="getToken.jsp"%>
-<%@ page import="java.util.*"%>
-<%@ page import="java.net.URL"%>
-<%@ page import="java.net.URLConnection"%>
-<%@ page import="java.net.URLEncoder,java.io.*"%>
-<%@ page import="org.apache.commons.httpclient.HttpClient"%>
-<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
-<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
-<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
-<%@ page import="org.apache.http.util.EntityUtils"%>
-<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
-<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
-<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
-<%@ page import="org.apache.http.HttpEntity"%>
-<%@ page import="org.apache.http.HttpResponse"%>
-<%@ page import="org.apache.http.client.methods.HttpPost"%>
-
-<%@ page import="org.apache.http.client.ResponseHandler"%>
-
-<%@ page import="org.apache.http.client.methods.HttpGet"%>
-<%@ page import="org.apache.http.impl.client.BasicResponseHandler"%>
-<%@ page import="org.apache.commons.httpclient.HttpClient"%>
-<%@ page import="org.apache.commons.httpclient.HostConfiguration"%>
-<%@ page import="org.apache.commons.httpclient.methods.GetMethod"%>
-<%@ page import="org.apache.http.entity.mime.content.StringBody"%>
-<%@ page import="org.apache.http.entity.FileEntity"%>
<%
@@ -1,10 +1,3 @@
-<!--
-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 contentType="text/html; charset=iso-8859-1" language="java" %>
<%@ page import="org.apache.commons.httpclient.*"%>
<%@ page import="org.apache.commons.httpclient.methods.*"%>
@@ -13,17 +6,17 @@ For more information contact developer.support@att.com
<%@ page import="java.io.*" %>
<%@ include file="OauthStorage.jsp" %>
<%@ include file="config.jsp" %>
+<%@ page import="java.lang.Math"%>
<%
-//Initialize some variables here, check if relevant variables were passed in, if not then check session, otherwise set default.
+
String scope = "SPEECH";
String accessToken = "";
String refreshToken = "";
String expires_in = "null";
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
@@ -38,13 +31,17 @@ Long date = System.currentTimeMillis();
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");
+
+ if (expires_in.equals("0"))
+ {
+ savedAccessTokenExpiry = date + (Long.parseLong("3155692597470")); //100 years
+ }
+ 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();
+ 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();
@@ -57,13 +54,17 @@ Long date = System.currentTimeMillis();
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");
+
+ if (expires_in.equals("0"))
+ {
+ savedRefreshTokenExpiry = date + (Long.parseLong("86400000")); //24 hours
+ }
+ savedAccessTokenExpiry = date + (Long.parseLong(expires_in)*1000);
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();
}
-%>
+%>

0 comments on commit daf89db

Please sign in to comment.