Hillel wrote:

Hi,

I saw your Post to help a fellow Kannel user.

Please will you send me your Java code to build a push SI as I'd like to see
how its done in Java.

Thanks

Hi Hillel (anybody else who might be interested in code like this),

//*snip*

URL sendURL = null; // will contain URL for sending SMS with Kannel
HttpURLConnection httpConn = null; // Http connection for sending S

String urlInPreparation = "http://localhost:<port>/sendsms?user=foo&pass=bar" // get carrier specific Kannel URL for sending SMS

String udh = "%06%05%04%0B%84%23%F0";

String wbxml  = "%01" + //Transaction ID
       "%06" + // PDU Type (push)
       "%04" + // Headers Length (content-type + headers)
       "%03" + // Length of content type
       "%AE" + // Content-Type: application/vnd.wap.sic
       "%81" + // Charset
       "%EA" + // UTF-8
       // End Headers
       // see si_binary_output
       "%02" +  // Version number (wbxml_version)
       "%05" +  // Unknown Public Identifier (si_public_id)
       "%6A" +  // charset= (sibxml->charset)
       "%00" +  // String table length
       "%45" + // <si>
           "%C6" + // <indication...
           "%0b" + "%03" + url + "%00" +    // href=$url
"%11" + "%03" + Integer.toString((int) (Math.random()* 1000000000)) + "@pushsi" + "%00" + // si-id=
           "%08" + // action="signal-high"
           //"%0A" . "%C3%07%20%01%10%21%20%02%23"; // created=
           //"%10" . "%C3%04%20%02%06%30"; // valid=
           "%01"; // end indication params
       try {
       wbxml += "%03" + URLEncoder.encode(text, "UTF-8") + "%00";
       } catch (Exception e) {
       System.err.println("...");
       e.printStackTrace();
       }
       wbxml += "%01" + // </indication>
       "%01"; // </si>

// add query parameters to urlInPreparation
try {
urlInPreparation += "&to=" + URLEncoder.encode(msisdn, "UTF-8"); // add query parameter "to" with it's value urlInPreparation += "&text=" + wbxml; // add query parameter "text" with it's value urlInPreparation += "&udh=" + udh; // add query parameter "text" with it's value
} catch (Exception e) {
   System.err.println("...");
   e.printStackTrace();
}

// send SMS to kannel
try {
   sendURL = new URL(urlInPreparation); // set URL
httpConn = (HttpURLConnection) (sendURL.openConnection()); // bind URL to connection
} catch (Exception e) {
   retval = false;
   System.err.println("...");
   e.printStackTrace();
}

//*snip*


DISCLAIMER: there still might be any errors in this code, so please mail me your suggestions, critics, etc. I'll always be glad to learn.


Ciao,
Chris.

Reply via email to