Package org.gsm.oneapi.responsebean.mms

Examples of org.gsm.oneapi.responsebean.mms.MMSSendResponse


  @param callbackData (optional) will be passed back to the notifyURL location, so you can use it to identify the message the receipt relates to (or any other useful data, such as a function name)
      
  @see MMSSendResponse
  */
  public MMSSendResponse sendMMS(String senderAddress, String[] address, String message, ArrayList<FileItem> attachments, String senderName, String clientCorrelator, String notifyURL, String callbackData) {
    MMSSendResponse response=new MMSSendResponse();
   
    FormParameters formParameters=new FormParameters();
    formParameters.put("senderAddress", senderAddress);
    for (String addr:address) if (address!=null) formParameters.put("address", addr);   
    formParameters.put("message", message);       
    formParameters.put("clientCorrelator", clientCorrelator);
    formParameters.put("notifyURL", notifyURL);
    formParameters.put("senderName", senderName);
    formParameters.put("callbackData", callbackData);
       
    if (true /* validation goes here */) {

      String endpoint=endPoints.getSendMMSEndpoint();
     
        int responseCode=0;
          String contentType = null;
     
      try {
            MimeMultipart mp = new MimeMultipart("mixed");

            InternetHeaders rootHdr = new InternetHeaders();

            rootHdr.addHeader("Content-Type", "application/x-www-form-urlencoded");
            rootHdr.addHeader("Content-Disposition", "form-data; name=\"root-fields\"");

            byte[] rootData = JSONRequest.formEncodeLineSeparaterParams(formParameters).getBytes();
            mp.addBodyPart(new MimeBodyPart(rootHdr, rootData));
           
            if (attachments!=null && attachments.size()>0) {
              for (int i=0; i<attachments.size(); i++) {
                FileItem attachment=attachments.get(i);
                if (attachment!=null) {
                  logger.debug("Attaching file ["+i+"] name="+attachment.getName()+" type="+attachment.getContentType());
                  InternetHeaders attachmentHdr = new InternetHeaders();
                  if (attachment.getContentType()!=null) attachmentHdr.addHeader("Content-Type", attachment.getContentType());
                  if (attachment.getName()!=null) attachmentHdr.addHeader("Content-Disposition", "form-data; name=\""+attachment.getName()+"\"");
                  byte[] dataBytes=attachment.get();
                  MimeBodyPart mpa=new MimeBodyPart(attachmentHdr, dataBytes);
                  mp.addBodyPart(mpa);
                }
              }
            }
     
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            mp.writeTo(baos);
           
            String content=baos.toString();
            String boundary = content.substring(2, content.indexOf("\r\n"));

       
        if (dumpRequestAndResponse) JSONRequest.dumpRequestVariables(endpoint, authorisationHeader, formParameters);
 
        HttpURLConnection con = JSONRequest.setupConnection(endpoint, authorisationHeader);
            con.setRequestMethod("POST");
            UUID separator=UUID.randomUUID();
           
            con.setRequestProperty("Content-Type", "multipart/form-data; boundary=\""+boundary+"\"");
            con.setDoOutput(true);
           
            OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
              out.write(content);
              out.close();
             
//              System.out.println("Sending:\n"+content);
//                         
            responseCode = con.getResponseCode();
              contentType = con.getContentType();
           
              response=mmsSendResponseProcessor.getResponse(con, OneAPIServlet.CREATED);
      } catch (Exception e) {
        response.setHTTPResponseCode(responseCode);
        response.setContentType(contentType);
       
        response.setRequestError(new RequestError(RequestError.SERVICEEXCEPTION, "SVCJAVA", e.getMessage(), e.getClass().getName()));
 
        logger.error("Exception "+e.getMessage()+" "+e.getLocalizedMessage());
      }
    }
    return response;
View Full Code Here

TOP

Related Classes of org.gsm.oneapi.responsebean.mms.MMSSendResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.