Here we would like to show you how to send a WAP Push message through SMPP using Java. This short tutorial will use the library and example source code from OpenSMPP. You can download the file from SourceForge.
The downloadable zipped file include source code and jar file libraries, and this article will modify this file SMPPTest.java to demonstrate how to do that.
Modify SMPPTest.java and include the following 2 functions:
private static final String HEXINDEX = "0123456789abcdef ABCDEF"; public static byte[] hexToByte(String s) { int l = s.length() / 2; byte data[] = new byte[l]; int j = 0; for (int i = 0; i < l; i++) { char c = s.charAt(j++); int n, b; n = HEXINDEX.indexOf(c); b = (n & 0xf) << 4; c = s.charAt(j++); n = HEXINDEX.indexOf(c); b += (n & 0xf); data[i] = (byte) b; } return data; }
The above function is used to convert Hexadecimal to binary data.
private void wappush() { debug.enter(this, "SMPPTest.submit()"); try { SubmitSM request = new SubmitSM(); SubmitSMResp response; // input values serviceType = getParam("Service type", serviceType); sourceAddress = getAddress("Source", sourceAddress); destAddress = getAddress("Destination", destAddress); replaceIfPresentFlag = getParam("Replace if present flag", replaceIfPresentFlag); payload = getParam("Payload", payload); scheduleDeliveryTime = getParam("Schedule delivery time", scheduleDeliveryTime); validityPeriod = getParam("Validity period", validityPeriod); esmClass = getParam("Esm class", (byte) 64); protocolId = getParam("Protocol id", protocolId); priorityFlag = getParam("Priority flag", priorityFlag); registeredDelivery = getParam("Registered delivery", registeredDelivery); dataCoding = getParam("Data encoding", (byte) 245); smDefaultMsgId = getParam("Sm default msg id", smDefaultMsgId); // set values request.setServiceType(serviceType); request.setSourceAddr(sourceAddress); request.setDestAddr(destAddress); request.setReplaceIfPresentFlag(replaceIfPresentFlag); request.setScheduleDeliveryTime(scheduleDeliveryTime); request.setValidityPeriod(validityPeriod); request.setEsmClass(esmClass); request.setProtocolId(protocolId); request.setPriorityFlag(priorityFlag); request.setRegisteredDelivery(registeredDelivery); request.setDataCoding(dataCoding); request.setSmDefaultMsgId(smDefaultMsgId); request.setShortMessageData(new ByteBuffer(hexToByte(payload))); // send the request int count = 1; System.out.println(); count = getParam( "How many times to submit this message (load test)", count); for (int i = 0; i < count; i++) { request.assignSequenceNumber(true); System.out.print("#" + i + " "); System.out.println("Submit request, wap push"); if (asynchronous) { session.submit(request); System.out.println(); } else { response = session.submit(request); System.out.println("Submit response " + response.debugString()); messageId = response.getMessageId(); } } } catch (Exception e) { event.write(e, ""); debug.write("Submit operation failed. " + e); System.out.println("Submit operation failed. " + e); } finally { debug.exit(this); } }
The above “wappush” function is a modification from “SubmitSM” function.
To run the test client:
java -classpath “log4j-1.2.13.jar:openSMPP.jar:./” SMPPTest
The following is the entry for each setting:
- 1 bind - 2 submit (t/tr) - 3 wappush (t/tr) - 4 submit multi (t/tr) - 5 data (t/tr) - 6 query (t/tr) - 7 replace (t/tr) - 8 cancel (t/tr) - 9 enquire link (t/tr) - 10 unbind - 11 receive message (tr/r) - 0 exit > 3 Service type [] Source address TON [1] Source address NPI [1] Source address [1111] Destination address TON [1] Destination address NPI [1] Destination address [6591234567] Replace if present flag [0] Payload [0605040b8423f0900601ae02056a0045c60d03676f6f676c652e636f6d00070103476f6 f676c652068656c6c6f000101] Schedule delivery time [] Validity period [] Esm class [64] Protocol id [0] Priority flag [0] Registered delivery [0] Data encoding [-11] Sm default msg id [0] How many times to submit this message (load test) [1]
The PDU for this:
0605040b8423f0900601ae02056a0045c60d03676f6f676c652e636f6d00070103476f6f676c652068656c6c6f000101
and the PDU will look like the following in Ethereal:
You can download the modified “SMPPTest.java” at http://www.artofmobile.com/download/SMPPTest.java