How to convert SI message to GSM SMS Data using Java

After publishing the article on “How to send WAP Push data through SMPP”, there is a lot of requests on how to formulate the GSM SMS User Data.

Basically, the following is an example in java with remark in the code to explain how this is done:

public String toSmsBinary() {
  /**
   GSM SMS User Data
   06: UDH Length which is 6
   05: 16 bit address
   04: Length(4)
   0B84: Destination Port(2948)
   23F0: Source Port(9200)

   Wireless Session Protocol
   90: Transaction ID
   06: PDU Type(Push)
   01: Headers Length is 1
   AE: Content-Type is application/vnd.wap.sic

   */
  StringBuilder ud = new StringBuilder().append("0605040b8423f0900601ae");
  ud.append(toWBXML());
  return ud.toString();

}

The above function creates the GSM SMS User Data and Wireless Session Protocol (WSP) header.

public String toWBXML() {
  /**
   02: Version number - WBXML version 1.2
   05: SI 1.0 Public Identifier
   6A: Charset=UTF-8 (MIBEnum 106)
   00: String table length
   45: si, with content
   */
  StringBuilder wbxml = new StringBuilder().append("02056a0045");
  wbxml.append(indicationToWBXML());
  wbxml.append("01");
  return wbxml.toString();
}

The above function creates the WAP Binary XML header and the following function will formulate the rest of the WAP Binary XML body.

  public String indicationToWBXML() {
    StringBuilder wbxml = new StringBuilder().append("c6");
    if (siId != null && siId.length() > 0) {
//si-id attribute
      wbxml.append("11");
// string literal
      wbxml.append("03");
// si-id string
      wbxml.append(hexDump(siId.getBytes()));
// end string
      wbxml.append("00");
    }

    if (href != null && href.length() > 0) {
      if (href.startsWith("http://www.")) {
        wbxml.append("0d");
        href = href.substring(11);
      }
      else if (href.startsWith("https://www.")) {
        wbxml.append("0f");
        href = href.substring(12);
      }
      else if (href.startsWith("http://")) {
        wbxml.append("0c");
        href = href.substring(7);
      }
      else if (href.startsWith("https://")) {
        wbxml.append("0e");
        href = href.substring(8);
      }
//String literal
      wbxml.append("03");
      wbxml.append(hexDump(href.getBytes()));
// end string
      wbxml.append("00");

      wbxml.append(getDecodedAction());

// >
      wbxml.append("01");
// The text value of the URL
      wbxml.append("03");

      byte[] bytes = value.getBytes();
      wbxml.append(hexDump(bytes));
      wbxml.append("00");

    }
    wbxml.append("01");
    return wbxml.toString();
  }

You can download the full source code at SiWapPush.java.