Using NowSMS propreitary URL Submission

Using NowSMS propreitary URL Submission SearchSearch
Author Message
Yoram Givon
New member
Username: Yoram_gi

Post Number: 1
Registered: 11-2003
Posted on Wednesday, November 19, 2003 - 08:18 pm:   

Hi,
I am trying to write some Java code to use the proprietary URL submission method, however it seems I need some help.

I have tried to use the sendRedirect in a Java servlet only to find out that this method does not support POST and only uses GET, which the NowSMS MMSC server does not accept.

If any one can send me some sample Java code or any other suggestion I would be very glad :-)

Thank you

Y.G
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 1186
Registered: 10-2002
Posted on Thursday, November 20, 2003 - 02:01 pm:   

Hi Yoram,

One potential solution for you ... if you can put the content pieces on to another web server, you can issue an HTTP GET, specifying the URL for each content piece in "MMSFILE" parameters of the GET request.

Toward the bottom of the following link, this approach is explained:

http://www.nowsms.com/documentation/ProductDocumentation/mms_notifications_and_c ontent/Submitting_MMS_Messages_URL.htm

I wish I had a Java example of this ... I do have a PHP example at the following link:

http://support.nowsms.com/discus/messages/1/1113.html

I did a quick search of the web for possible solutions for the Java environment. The proprietary URL submission method uses standard HTTP file upload procedures, so that it works with standard web browsers. It uses the MIME type "multipart/form-data". So you might have some luck searching for Java routines that talk about HTTP file upload or "multipart/form-data".

Here are a few links that might be helpful:

http://www.devx.com/Java/Article/17679?trk=DXRSS_LATEST

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_2056480 7.html

http://www.oop-reserch.com/cross_servlet.html


Assuming that you find a good solution, please let us know what works best for you.

-bn
Matthias Regensburger
Unregistered guest
Posted on Thursday, November 20, 2003 - 02:43 pm:   

Hi,

try the HTTPClient API from Apache. This API has support for multipart/form-data POST.
I have written a small java application for sending MMS to the NowSMS server with the HTTPClient API. I also wrote a small java program, to search for new incoming MMS in the MMS-IN directory and this program parses the header file and the associated txt files. It's really simple to develop such a program.

Greetings
Yoram Givon
New member
Username: Yoram_gi

Post Number: 2
Registered: 11-2003
Posted on Tuesday, November 25, 2003 - 08:37 am:   

Thank you very much :-)
Yoram Givon
New member
Username: Yoram_gi

Post Number: 3
Registered: 11-2003
Posted on Saturday, November 29, 2003 - 07:27 pm:   

Following is a Java code using the apache HttpClient.

Use freely

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.*;

import java.io.*;
import java.util.*;


public class HttpClientTutorial {

private static String url = "http://127.0.0.1:8800";


public static void main(String[] args) {

// Create an instance of HttpClient.
HttpClient client = new HttpClient();

// Create a method instance.
MultipartPostMethod method = new MultipartPostMethod(url);

int i;

String strPhoneNumber,strMMSFrom,strMMSSubject,strMMSText;

strPhoneNumber = "+97255123456";
strMMSFrom= "yoram@pelemedia.com";
strMMSSubject = "TestingServlet";
strMMSText = "Testing the servlet including a pre compiled MMS";

StringPart prtPhoneNumber = new StringPart("PhoneNumber",strPhoneNumber);
StringPart prtMMSFrom = new StringPart("MMSFrom",strMMSFrom);
StringPart prtMMSSubject = new StringPart("MMSSubject",strMMSSubject);
StringPart prtMMSText = new StringPart("MMSTExt",strMMSText);

//Using AddPart, you build the multipart post
method.addPart(prtPhoneNumber);
method.addPart(prtMMSFrom);
method.addPart(prtMMSSubject);
method.addPart(prtMMSText);

//The file part is the tricky one, but not that tricy :-)
try
{
File filMMSFile = new File("D:/Pelemedia/Development/MMS/test.MMS");
FilePart prtMMSFile = new FilePart("MMSFile",filMMSFile,"application/vnd.wap.multipart.related","iso-8859- 1");

method.addPart(prtMMSFile);

} catch (IOException e)
{
System.err.println("Failed to download file.");
e.printStackTrace();
}


//You can also use a simple addParameter which will just build you post in a "GET" way
/*
method.addParameter("PhoneNumber",strPhoneNumber);
method.addParameter("MMSFrom",strMMSFrom);
method.addParameter("MMSSubject",strMMSSubject);
method.addParameter("MMSText",strMMSText);
*/


// Execute the method.
int statusCode = -1;
int attempt = 0;
// We will retry up to 3 times.
while (statusCode == -1 && attempt < 3) {
try {
// execute the method.
statusCode = client.executeMethod(method);
} catch (HttpRecoverableException e) {
System.err.println(
"A recoverable exception occurred, retrying." +
e.getMessage());
} catch (IOException e) {
System.err.println("Failed to download file.");
e.printStackTrace();
System.exit(-1);
}
}
// Check that we didn't run out of retries.
if (statusCode == -1) {
System.err.println("Failed to recover from exception.");
System.exit(-2);
}

// Read the response body.
byte[] responseBody = method.getResponseBody();

// Release the connection.
method.releaseConnection();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.err.println(new String(responseBody));

}
}