Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 7.62 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML lang=en xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Application 1</TITLE>
  3. <META content="text/html; charset=windows-1252" http-equiv=Content-Type>
  4. <SCRIPT type=text/javascript
  5. src="http://www.dwestern.com/smsapp/smshelper.js">
  6. </SCRIPT>
  7. <META name=GENERATOR content="MSHTML 8.00.6001.19046"></HEAD>
  8. <BODY>
  9. <TABLE border=0 width="100%">
  10.   <TBODY>
  11.   <TR>
  12.     <TD rowSpan=2 width="25%" align=left><IMG
  13.       src="http://developer.att.com/developer/images/att.gif"></TD>
  14.     <TD width="15%" align=right>Server Time:</TD>
  15.     <TD width="60%" align=left>Monday, June 13, 2011 16:52 CDT</TD></TR>
  16.   <TR>
  17.     <TD width="15%" align=right>Client Time:</TD>
  18.     <TD width="25%" align=left>
  19.       <SCRIPT language=JavaScript type=text/javascript>
  20. <!--
  21. var myDate = new Date();
  22. document.write(myDate.format('l, F d, Y  H:i') + ' PDT');
  23.  
  24. //-->
  25. </SCRIPT>
  26. </TD></TR></TBODY></TABLE>
  27. <%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
  28. <%@ page import="com.sun.jersey.multipart.file.*" %>
  29. <%@ page import="com.sun.jersey.multipart.BodyPart" %>
  30. <%@ page import="com.sun.jersey.multipart.MultiPart" %>
  31. <%@ page import="java.io.*" %>
  32. <%@ page import="java.util.List" %>
  33. <%@ page import="com.sentaca.rest.client.*" %>
  34. <%@ page import="java.net.*" %>
  35. <%@ page import="javax.ws.rs.core.*" %>
  36. <%@ page import="org.apache.commons.fileupload.*"%>
  37. <%@ page import="java.util.List,java.util.Iterator"%>
  38. <%@ page import="org.apache.commons.httpclient.*"%>
  39. <%@ page import="org.apache.commons.httpclient.methods.*"%>
  40. <%@ page import="org.json.*"%>
  41. <%@ page import="org.w3c.dom.*" %>
  42. <%@ page import="javax.xml.parsers.*" %>
  43. <%@ page import="javax.xml.transform.*" %>
  44. <%@ page import="javax.xml.transform.stream.*" %>
  45. <%@ page import="javax.xml.transform.dom.*" %>
  46.  
  47. <%
  48. String mmsId = request.getParameter("mmsId");
  49. if (mmsId==null) mmsId = (String) session.getAttribute("mmsId");
  50. if (mmsId==null) mmsId = "";
  51. String accessToken = request.getParameter("access_token");
  52. if(accessToken==null || accessToken=="null"){
  53.         accessToken = (String) session.getAttribute("accessToken");}
  54. if(accessToken==null || accessToken=="null") {
  55.         session.setAttribute("postOauth", "MMS.jsp");
  56.         session.setAttribute("redirectUri", "http://198.171.172.186:8080/apigee-public/oauth.jsp");
  57.         session.setAttribute("clientId", "861e5197f51c002bb6fa9c44cc6360c3");
  58.         session.setAttribute("clientSecret", "bb4d6838d7c65326");
  59.         session.setAttribute("FQDN", "https://test-api.att.com");
  60.         response.sendRedirect("oauth.jsp?getExtCode=yes");
  61. }
  62. String sendMms = request.getParameter("sendMms");              
  63. String contentBodyFormat = "FORM-ENCODED";             
  64. String address = "";           
  65. String fileName = "";
  66. String subject = "";           
  67. String priority = "High";
  68. String responseFormat = "json";
  69. String requestFormat = "json";
  70. String FQDN = request.getParameter("FQDN");
  71. if (FQDN==null)
  72.         FQDN = (String) session.getAttribute("FQDN");
  73. if (FQDN==null)
  74.         FQDN = "https://test-api.att.com";
  75. String endpoint = FQDN + "/1/messages/outbox/mms";
  76. %>
  77.  
  78. <HR size=px"></HR>
  79. <font size=4px"><B>ATT sample MMS application</B></font><BR>
  80. Feature 1 - sending MMS message.<BR>
  81. <FORM  method="post" name="sendMms" enctype="multipart/form-data" action="MMS.jsp?sendMms=true">
  82. <TABLE border=0 width="60%">
  83.   <TBODY>
  84.   <TR>
  85.     <TD width="15%">Message:</TD>
  86.     <TD><TEXTAREA rows=4 name="subject">simple message to myself</TEXTAREA>
  87.         </TD></TR>
  88.   <TR>
  89.     <TD width="15%">Phone:</TD>
  90.     <TD><input maxLength=12 size=12 name="address" value="425-241-8899"></input>
  91.     </TD>
  92.   </TR>
  93.   <TR>
  94.     <TD width="15%">&nbsp;</TD>
  95.     <TD>DDD-DDD-DDDD</TD>
  96.   </TR>
  97.   <TR>
  98.     <TD width="15%">Attachment 1:</TD>
  99.     <TD><input type="file" name="f1"></input>
  100.     </TD>
  101.   </TR>
  102.   <TR>
  103.     <TD width="15%">Attachment 2:</TD>
  104.     <TD><input type="file" name="f2"></input>
  105.     </TD>
  106.   </TR>
  107.   <TR>
  108.     <TD width="15%">Attachment 3:</TD>
  109.     <TD><input type="file" name="f3"></input>
  110.     </TD>
  111.   </TR>
  112.   </TBODY></TABLE>
  113. <BUTTON type="submit" name="sendMms">send mms message</BUTTON>
  114. </FORM>
  115.  
  116. <% if(request.getParameter("sendMms")!=null) { 
  117.  
  118.         DiskFileUpload fu = new DiskFileUpload();
  119.         List fileItems = fu.parseRequest(request);
  120.         Iterator itr = fileItems.iterator();
  121.         while(itr.hasNext()) {
  122.           FileItem fi = (FileItem)itr.next();
  123.           if(!fi.isFormField()) {
  124.                 File fNew= new File(application.getRealPath("/"), fi.getName());
  125.                 fileName = fileName + "," + fi.getName();
  126.                 if(!(fi.getName().equalsIgnoreCase(""))){
  127.                         fi.write(fNew);
  128.                 }
  129.           } else if(fi.getFieldName().equalsIgnoreCase("address")) {
  130.                 address = fi.getString();
  131.                 address = "tel:" + address.substring(0,3) + address.substring(4,7) + address.substring(8,12);
  132.           } else if(fi.getFieldName().equalsIgnoreCase("subject")) {
  133.                 subject = fi.getString();
  134.           }
  135.         }              
  136.                 String attachmentsStr = fileName;
  137.                 String[] attachments = attachmentsStr.split(",");
  138.  
  139.                 MediaType contentBodyType = null;
  140.                 String requestBody = "";
  141.                 MultiPart mPart;
  142.                         contentBodyType = MediaType.MULTIPART_FORM_DATA_TYPE;
  143.                         JSONObject requestObject = new JSONObject();
  144.                         requestObject.put("priority", priority);
  145.                     requestObject.put("address", address);
  146.                         requestObject.put("subject", subject);
  147.                         requestObject.put("content-type", "image/jpeg");
  148.                         requestBody += requestObject.toString();
  149.                  mPart = new MultiPart().bodyPart(new BodyPart(requestBody,MediaType.APPLICATION_JSON_TYPE));
  150.                  mPart.getBodyParts().get(0).getHeaders().add("Content-Transfer-Encoding", "8bit");
  151.                  mPart.getBodyParts().get(0).getHeaders().add("Content-Disposition","form-data; name=\"root-fields\"");
  152.                  mPart.getBodyParts().get(0).getHeaders().add("Content-ID", "<startpart>");
  153.                  MediaType[] medTyp = new MediaType[4];
  154.                  for(int i=1;i<attachments.length; i++) {
  155.                         FileDataBodyPart fIlE = new FileDataBodyPart();
  156.                         medTyp[i] = fIlE.getPredictor().getMediaTypeFromFileName("/" + attachments[i]);
  157.                 }
  158.                  
  159.                 ServletContext context = getServletContext();
  160.                 if(attachments.length == 2){
  161.                         mPart.bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[1]), medTyp[1]));
  162.                 } else if(attachments.length == 3) {
  163.                         mPart.bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[1]), medTyp[1])).bodyPart(new BodyPart(context.getResourceAsStream("/" + attachments[2]), medTyp[2]));
  164.                 } else if(attachments.length == 4) {
  165.                         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]));
  166.                 }
  167.  
  168.                 // 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.
  169.                 RestClient client;
  170.                 client = new RestClient(endpoint, contentBodyType, MediaType.APPLICATION_JSON_TYPE);
  171.                 client.addParameter("access_token", accessToken);
  172.                 client.addRequestBody(mPart);
  173.                 String responze = client.invoke(com.sentaca.rest.client.HttpMethod.POST, true);
  174.                
  175.                 if (client.getHttpResponseCode() == 201) {
  176.                         JSONObject rpcObject = new JSONObject(responze);
  177.                         mmsId = rpcObject.getString("id");
  178.                         session.setAttribute("mmsId", mmsId);
  179.                 %>
  180.                 <table border="1" bgcolor="#CCFF33" >
  181.                         <tr><th>message id</th></tr>
  182.                         <tr><td><%=mmsId%></td></tr>
  183.                         </table>
  184.                         <%
  185.                 } else {
  186.                         System.out.println(responze);
  187.                 %>
  188.                 <table border="1" bgcolor="#FF0000" >
  189.                         <tr><th>Error</th></tr>
  190.                         <tr><td><%=responze%></td></tr>
  191.                         </table>
  192.                         <%
  193.                 }
  194.         }      
  195. %>