我会直接提出我的问题。
我正在使用Logica smpp,我想将短信发送给多个号码。下面的代码给出例外。
public void submitMulti() {
String serviceType = "";
byte replaceIfPresentFlag = 0;
String scheduleDeliveryTime = null;
String validityPeriod = null;
byte esmClass = 0;
//######################
//byte protocolId = 0;
//byte dataCoding = 0;
byte protocolId = 0; //0x00; commented is for flash
byte dataCoding = (byte) 0x08; //0x18
byte smsClass = 0x00;
//######################
byte ton = 1;
byte npi = 1;
byte priorityFlag = 0;
byte registeredDelivery = 0; //TODO registered delivery
byte smDefaultMsgId = (byte) 12; //0;
try {
SubmitMultiSM request = new SubmitMultiSM();
SubmitMultiSMResp response;
// input values and set some :-)
String sourceAddress = "123456789012";
int numberOfDestination = 10;
for (int i = 0; i < numberOfDestination; i++) {
request.addDestAddress(new DestinationAddress(new Address(ton,npi,"923458503302")));
}
// set other values
request.setServiceType(serviceType);
request.setSourceAddr(sourceAddress);
request.setReplaceIfPresentFlag(replaceIfPresentFlag);
request.setShortMessage("Hy");
request.setScheduleDeliveryTime(scheduleDeliveryTime);
request.setValidityPeriod(validityPeriod);
request.setEsmClass(esmClass);
request.setProtocolId(protocolId);
request.setPriorityFlag(priorityFlag);
request.setRegisteredDelivery(registeredDelivery);
request.setDataCoding(dataCoding);
request.setSmDefaultMsgId(smDefaultMsgId);
String ipAddress = Bundle.getInstance().getValue(Bundle.Application_Contants.IP_ADDRESS.toString());
int port = Integer.valueOf(Bundle.getInstance().getValue(Bundle.Application_Contants.PORT.toString()));
long receiveTimeOut = Long.valueOf(Bundle.getInstance().getValue(Bundle.Application_Contants.RECEIVE_TIMEOUT.toString()));
TCPIPConnection connection = new TCPIPConnection(ipAddress,port);
connection.setReceiveTimeout(receiveTimeOut);
customSession = new Session(connection);
// send the request
System.out.println("Submit Multi request " + request.debugString());
if (!asynchronous) {
customSession.submitMulti(request);
} else {
response = customSession.submitMulti(request);
System.out.println("Submit Multi response " + response.debugString());
messageId = response.getMessageId();
}
} catch (Exception e) {
log.error(e,e);
System.out.println("Submit Multi operation failed. " + e.getMessage());
} finally {
}
}
而且例外是:
java.lang.NullPointerException
at org.smpp.Session.send(Session.java:1100)
at org.smpp.Session.send(Session.java:1173)
at org.smpp.Session.submitMulti(Session.java:727)
at com.noetic.topUpBooster.smpp.JarConnection.submitMulti(JarConnection.java:413)
at com.noetic.sdp.alerts.JarCheck.run(JarCheck.java:34)
Submit Multi operation failed. null
有没有人有想法?
答案 0 :(得分:0)
假设您的代码充当ESME,必须先发送绑定请求(通过BindTransmitter或BindTransciever),然后才能发送任何SubmitSM,SubmitMultiSM或DataSM。