Created
May 3, 2012 20:59
-
-
Save t2-support-gists/2589430 to your computer and use it in GitHub Desktop.
MMS Java app3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AT&T API Samples - MMS app 3 | |
| ------------------------------ | |
| 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 | |
| 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". | |
| 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 | |
| Also be careful when filling in the "MMS MO Listener URL" field. This should point to the mmslistener.jsp file packaged with | |
| this application. This listener URL must be a public URL or IP address that the gateway will be able to reach. For example, if | |
| running this application on a server with IP address 1.2.3.4 in a default Tomcat instance, your listener URL might be | |
| https://1.2.3.4:8080/SampleApp/mmslistener.jsp | |
| NOTE: You MUST select MMS 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 | |
| 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 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 | |
| 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. | |
| Please populate the following parameters in config.jsp as specified below: | |
| 1) clientIdAut : {set the value as per your registered appliaction 'API key' field value} | |
| 2) clientSecretAut : {set the value as per your registered appliaction 'Secret key' field value} | |
| 3) FQDN : https://api.att.com | |
| 4) shortCode1 : short-code 1 | |
| 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. | |
| 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/SampleApp/MMS3.jsp to see it working. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% | |
| String clientIdAut = ""; | |
| String clientSecretAut = ""; | |
| String shortCode1 = ""; | |
| String shortCode2 = ""; | |
| String FQDN = "https://api.att.com"; | |
| %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%@ page contentType="application/json" language="java" %><%@ page import="java.io.*" %><%@ page import="java.util.Arrays" %><%@ page import="java.util.Collections" %><%@ page import="java.util.Comparator" %><%@ include file="config.jsp" %><% | |
| String senderAddress = ""; | |
| String date = ""; | |
| String text = ""; | |
| File directory = new File(application.getRealPath("/MoMmsImages/")); | |
| File[] files = directory.listFiles(); | |
| Arrays.sort(files, new Comparator<File>(){ | |
| public int compare(File f1, File f2) | |
| { | |
| return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); | |
| } }); | |
| Collections.reverse(Arrays.asList(files)); | |
| %>{"totalNumberOfImagesSent":"<%=directory.listFiles().length%>","imageList":[<% | |
| if(directory.listFiles().length>0) { | |
| int i = 0; | |
| for(File imageFile : files){ | |
| String imageFileName = imageFile.getName(); | |
| RandomAccessFile inFile1 = new RandomAccessFile(application.getRealPath("MoMmsData/" + imageFileName + ".txt"),"r"); | |
| senderAddress = inFile1.readLine(); | |
| date = inFile1.readLine(); | |
| text = inFile1.readLine(); | |
| if(text==null || text.equalsIgnoreCase("null")) | |
| text = ""; | |
| if(text.indexOf(194)!=-1) | |
| text = text.substring(0, text.length()-2); | |
| inFile1.close(); | |
| if((i==directory.listFiles().length-1) || (i==9)) { | |
| %>{"path":"MoMmsImages/<%=imageFileName%>","senderAddress":"<%=senderAddress%>","date":"<%=date%>","text":"<%=text%>"}]}<% | |
| } else { | |
| %>{"path":"MoMmsImages/<%=imageFileName%>","senderAddress":"<%=senderAddress%>","date":"<%=date%>","text":"<%=text%>"},<% | |
| } | |
| i += 1; | |
| if(i==10) | |
| break; | |
| } | |
| } | |
| %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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&T Sample MMS Application 3 - MMS Gallery 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="java.io.*" %> | |
| <%@ page import="java.util.Arrays" %> | |
| <%@ page import="java.util.Collections" %> | |
| <%@ page import="java.util.Comparator" %> | |
| <%@ page import="org.apache.commons.httpclient.*"%> | |
| <%@ page import="org.apache.commons.httpclient.methods.*"%> | |
| <%@ page import="org.json.*"%> | |
| <%@ include file="config.jsp" %> | |
| <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&T Sample MMS Application 3 - MMS Gallery Application</h1> | |
| <h2>Feature 1: Web gallery of MMS photos sent to short code</h2> | |
| </div> | |
| </div> | |
| <% | |
| String senderAddress = ""; | |
| String date = ""; | |
| String text = ""; | |
| String url = request.getRequestURL().toString().substring(0,request.getRequestURL().toString().lastIndexOf("/")) + "/getImageData.jsp"; | |
| HttpClient client = new HttpClient(); | |
| GetMethod method = new GetMethod(url); | |
| int statusCode = client.executeMethod(method); | |
| JSONObject jsonResponse = new JSONObject(method.getResponseBodyAsString()); | |
| JSONArray imageList = new JSONArray(jsonResponse.getString("imageList")); | |
| String totalNumberOfImagesSent = jsonResponse.getString("totalNumberOfImagesSent"); | |
| %> | |
| <br /> | |
| <p>Photos sent to short code <%=shortCode1%>: <%=totalNumberOfImagesSent%></p> | |
| <div id="gallerywrapper"> | |
| <% | |
| for(int i=0; i<10; i++) { | |
| JSONObject image = new JSONObject(imageList.getString(i)); | |
| %> | |
| <div id="gallery"><img src="<%=image.getString("path")%>" width="150" border="0" /><br /><strong>Sent from:</strong> <%=image.getString("senderAddress")%><br /><strong>On:</strong> <%=image.getString("date")%><div><%=image.getString("text")%></div></div> | |
| <% | |
| } | |
| method.releaseConnection(); | |
| %> | |
| </div> | |
| <br clear="all" /> | |
| <div id="footer"> | |
| <div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&T Virtual Mobile</div> | |
| <p>© 2011 AT&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&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> | |
| </div> | |
| </div> | |
| </body></html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| 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 developer.support@att.com | |
| --> | |
| <%@ page contentType="text/html; charset=iso-8859-1" language="java" %> | |
| <%@ page import="java.util.*" %> | |
| <%@ page import="org.apache.commons.fileupload.servlet.*" %> | |
| <%@ page import="org.apache.commons.fileupload.*" %> | |
| <%@ page import="org.apache.commons.fileupload.disk.*" %> | |
| <%@ page import="java.io.*" %> | |
| <%@ page import="java.net.*" %> | |
| <%@ page import="java.util.*" %> | |
| <%@ page import="java.text.*" %> | |
| <%@ page import="org.apache.commons.codec.binary.Base64" %> | |
| <% | |
| LinkedHashMap<String, String> paramLinkedMap = new LinkedHashMap<String, String>(); | |
| try{ | |
| String data=null; | |
| InputStream is = request.getInputStream(); | |
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
| byte buf[] = new byte[1024]; | |
| int letti; | |
| while ((letti = is.read(buf)) > 0) | |
| baos.write(buf, 0, letti); | |
| data = new String(baos.toByteArray()); | |
| String senderAddress = data.split("<SenderAddress>tel:")[1].split("</SenderAddress>")[0].substring(2); | |
| Date d = new Date(); | |
| DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); | |
| df.setTimeZone(TimeZone.getTimeZone("PST")); | |
| DateFormat tf = DateFormat.getTimeInstance(DateFormat.LONG, Locale.US); | |
| tf.setTimeZone(TimeZone.getTimeZone("PST")); | |
| String date = df.format(d) + ", " +tf.format(d); | |
| String[] parts = data.split("--Nokia-mm-messageHandler-BoUnDaRy"); | |
| String[] lowerParts = parts[2].split("BASE64"); | |
| String type = lowerParts[0].split("image/")[1].split(";")[0]; | |
| byte[] outFile = Base64.decodeBase64(lowerParts[1]); | |
| int random = (int)(Math.random()*10000000); | |
| FileOutputStream fous = new FileOutputStream(application.getRealPath("/MoMmsImages/"+random+"."+type)); | |
| fous.write(outFile); | |
| fous.close(); | |
| String decodedText = ""; | |
| if(parts.length>4) { | |
| String textPart = parts[3].split("BASE64")[1]; | |
| decodedText = new String(Base64.decodeBase64(textPart)); | |
| decodedText = decodedText.trim(); | |
| } | |
| StringTokenizer st = new StringTokenizer(data, "&"); | |
| String token; | |
| while(st.hasMoreTokens()){ | |
| token = st.nextToken(); | |
| paramLinkedMap.put(URLDecoder.decode(token.substring(0, token.indexOf("="))), | |
| URLDecoder.decode(token.substring(token.indexOf("=")+1, token.length()))); | |
| } | |
| PrintWriter outWrite = new PrintWriter(new BufferedWriter(new FileWriter(application.getRealPath("/MoMmsData/" + random + "." + type + ".txt"))), false); | |
| String toSave = senderAddress + "\n" + date + "\n" + decodedText; | |
| outWrite.write(toSave); | |
| outWrite.close(); | |
| }catch(Exception e){ | |
| } | |
| %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% | |
| String savedAccessToken = "ad13138f408bbdaabbdafa355b0b9ee8"; | |
| Long savedAccessTokenExpiry = Long.parseLong("1324062272533"); | |
| String savedRefreshToken = "eb039c57a6efa7216e06a5114cce4a7f6576f2f3"; | |
| Long savedRefreshTokenExpiry = Long.parseLong("1324148665334"); | |
| %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment