Hi Hillel,
Do you need the java code for WAP PUSH? If so here it is:
-------------------------- Java code for wap push----------------------------
public boolean execute(String jar_url, String mobile) {
if (null == mobile) {
Log.debug("[Prasad] Unable to send message! target number is null!");
return false;
}
String content = generateContent(jar_url, mobile);
try {
if (null == mobile) {
Log.debug("[Prasad] Unable to send message! target number is null!");
return false;
}
String content = generateContent(jar_url, mobile);
try {
String push_url = "localhost:8080/xxxx.jar";
push_url = push_url + "?username=" + username + "&password="
+ password;
URL url = "" URL(push_url);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches (false);
connection
.setRequestProperty("Content-Type",
"multipart/related; boundary=asdlfkjiurwgasf; type=application/xml");
DataOutputStream output = new DataOutputStream(connection
.getOutputStream());
output.writeBytes(content);
output.flush();
output.close();
BufferedReader input = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
boolean responseOK = false;
String response = null;
while ((response = input.readLine()) != null) {
System.out.println (response);
if (response.indexOf("1001") != -1) {
responseOK = true;
}
}
if (!responseOK) {
Log.debug ("PPG did not accept the message");
return false;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
private String generateContent(String jar_url, String mobile) {
Random ran = new Random(100000);
int num = ran.nextInt();
String pid = "foodreg@" + num + ".com";
//Dates for SMS validation
Date cDate = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String fDate = format.format(cDate);
int i = cDate.getYear()+1900;
GregorianCalendar gc = new GregorianCalendar(i, cDate.getMonth(), cDate.getDay());
gc.add(GregorianCalendar.DATE , 60);
Date tempDate = gc.getTime();
// DateFormat df = DateFormat.getDateInstance();
String afterDate = format.format(tempDate);
// appending message
StringBuffer buffer = new StringBuffer();
buffer
.append("--asdlfkjiurwgasf\r\n")
.append("Content-Type: application/xml\r\n\r\n")
.append("<?xml version=\"1.0\"?>\r\n")
.append("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP//EN\"\r\n")
.append("\"http://www.wapforum.org/DTD/pap_1.0.dtd\">\r\n")
.append("<pap>\r\n")
.append("<push-message push-id=\"")
.append(pid.trim())
.append(
"\"\r\n deliver-before-timestamp="+afterDate+"\"T06:45:00Z\" \r\n")
.append("deliver-after-timestamp="+cDate+"\"T06:45:00Z\" ")
.append("progress-notes-requested=\"true\">\r\n")
.append("<address address-value=\"WAPPUSH=")
.append(mobile)
.append("/TYPE=PLMN\"/>\r\n")
.append(
"<quality-of-service delivery-method=\"unconfirmed\"\r\nnetwork-required=\"true\"\r\n network=\"GSM\"\r\nbearer-required=\"true\"\r\nbearer=\"SMS\"/>")
.append("</push-message>\r\n")
.append("</pap>\r\n\r\n")
.append("--asdlfkjiurwgasf\r\n")
.append("Content-Type: text/vnd.wap.si\r\n\r\n")
.append("<?xml version=\"1.0\"?>\r\n")
.append(
"<!DOCTYPE si PUBLIC \"-//WAPFORUM//DTD SI 1.0//EN\"\r\n")
.append("\" http://www.wapforum.org/DTD/si.dtd\">\r\n").append(
"<si>\r\n").append(
"<indication action="" si-id=\"").append(
pid).append("\" href=""
.append("Download the Foodreg Application").append(
"</indication>\r\n").append("</si>\r\n").append(
"--asdlfkjiurwgasf--\r\n\r\n");
// .append("--multipart-boundary--\r\n");
return buffer.toString();
}
push_url = push_url + "?username=" + username + "&password="
+ password;
URL url = "" URL(push_url);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches (false);
connection
.setRequestProperty("Content-Type",
"multipart/related; boundary=asdlfkjiurwgasf; type=application/xml");
DataOutputStream output = new DataOutputStream(connection
.getOutputStream());
output.writeBytes(content);
output.flush();
output.close();
BufferedReader input = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
boolean responseOK = false;
String response = null;
while ((response = input.readLine()) != null) {
System.out.println (response);
if (response.indexOf("1001") != -1) {
responseOK = true;
}
}
if (!responseOK) {
Log.debug ("PPG did not accept the message");
return false;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
private String generateContent(String jar_url, String mobile) {
Random ran = new Random(100000);
int num = ran.nextInt();
String pid = "foodreg@" + num + ".com";
//Dates for SMS validation
Date cDate = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String fDate = format.format(cDate);
int i = cDate.getYear()+1900;
GregorianCalendar gc = new GregorianCalendar(i, cDate.getMonth(), cDate.getDay());
gc.add(GregorianCalendar.DATE , 60);
Date tempDate = gc.getTime();
// DateFormat df = DateFormat.getDateInstance();
String afterDate = format.format(tempDate);
// appending message
StringBuffer buffer = new StringBuffer();
buffer
.append("--asdlfkjiurwgasf\r\n")
.append("Content-Type: application/xml\r\n\r\n")
.append("<?xml version=\"1.0\"?>\r\n")
.append("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP//EN\"\r\n")
.append("\"http://www.wapforum.org/DTD/pap_1.0.dtd\">\r\n")
.append("<pap>\r\n")
.append("<push-message push-id=\"")
.append(pid.trim())
.append(
"\"\r\n deliver-before-timestamp="+afterDate+"\"T06:45:00Z\" \r\n")
.append("deliver-after-timestamp="+cDate+"\"T06:45:00Z\" ")
.append("progress-notes-requested=\"true\">\r\n")
.append("<address address-value=\"WAPPUSH=")
.append(mobile)
.append("/TYPE=PLMN\"/>\r\n")
.append(
"<quality-of-service delivery-method=\"unconfirmed\"\r\nnetwork-required=\"true\"\r\n network=\"GSM\"\r\nbearer-required=\"true\"\r\nbearer=\"SMS\"/>")
.append("</push-message>\r\n")
.append("</pap>\r\n\r\n")
.append("--asdlfkjiurwgasf\r\n")
.append("Content-Type: text/vnd.wap.si\r\n\r\n")
.append("<?xml version=\"1.0\"?>\r\n")
.append(
"<!DOCTYPE si PUBLIC \"-//WAPFORUM//DTD SI 1.0//EN\"\r\n")
.append("\" http://www.wapforum.org/DTD/si.dtd\">\r\n").append(
"<si>\r\n").append(
"<indication action="" si-id=\"").append(
pid).append("\" href=""
.append("Download the Foodreg Application").append(
"</indication>\r\n").append("</si>\r\n").append(
"--asdlfkjiurwgasf--\r\n\r\n");
// .append("--multipart-boundary--\r\n");
return buffer.toString();
}
On 8/30/06, Hillel <[EMAIL PROTECTED]> wrote:
Hi,
Yes, please send the Java code. Do you know were you can find
specifications on the headers.
Thanks
