Skip to content

Commit

Permalink
Provide access to SMPP Interface version in bind
Browse files Browse the repository at this point in the history
Both client side and server side code can now control what interface version is sent during binding.
  • Loading branch information
Stefan Thorvardarson committed Mar 2, 2012
1 parent 08a95b5 commit b3bafb3
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) {
request.getPassword().equals("test")) {

// accepting request and send bind response immediately
System.out.println("Accepting bind request");
System.out.println("Accepting bind request, interface version is " + request.getInterfaceVersion());
request.accept("sys");

try { Thread.sleep(20000); } catch (InterruptedException e) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jsmpp.bean.DeliveryReceipt;
import org.jsmpp.bean.ESMClass;
import org.jsmpp.bean.GSMSpecificFeature;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.MessageMode;
import org.jsmpp.bean.MessageType;
import org.jsmpp.bean.NumberingPlanIndicator;
Expand Down Expand Up @@ -149,9 +150,9 @@ public WaitBindTask(SMPPServerSession serverSession) {
public void run() {
try {
BindRequest bindRequest = serverSession.waitForBind(1000);
logger.info("Accepting bind for session {}", serverSession.getSessionId());
logger.info("Accepting bind for session {}, interface version {}", serverSession.getSessionId());
try {
bindRequest.accept("sys");
bindRequest.accept("sys", InterfaceVersion.IF_34);
} catch (PDUStringException e) {
logger.error("Invalid system id", e);
bindRequest.reject(SMPPConstant.STAT_ESME_RSYSERR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jsmpp.bean.DeliveryReceipt;
import org.jsmpp.bean.ESMClass;
import org.jsmpp.bean.GSMSpecificFeature;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.MessageMode;
import org.jsmpp.bean.MessageType;
import org.jsmpp.bean.NumberingPlanIndicator;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void run() {
BindRequest bindRequest = serverSession.waitForBind(1000);
logger.debug("Accepting bind for session {}", serverSession.getSessionId());
try {
bindRequest.accept("sys");
bindRequest.accept("sys", InterfaceVersion.IF_34);
} catch (PDUStringException e) {
logger.error("Invalid system id", e);
bindRequest.reject(SMPPConstant.STAT_ESME_RSYSERR);
Expand Down
15 changes: 12 additions & 3 deletions jsmpp/src/main/java/org/jsmpp/DefaultPDUSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jsmpp.bean.MessageState;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.OptionalParameter;
import org.jsmpp.bean.OptionalParameter.Tag;
import org.jsmpp.bean.RegisteredDelivery;
import org.jsmpp.bean.ReplaceIfPresentFlag;
import org.jsmpp.bean.TypeOfNumber;
Expand Down Expand Up @@ -106,10 +107,18 @@ public byte[] sendBind(OutputStream os, BindType bindType,
* java.lang.String)
*/
public byte[] sendBindResp(OutputStream os, int commandId,
int sequenceNumber, String systemId) throws PDUStringException,
int sequenceNumber, String systemId, InterfaceVersion interfaceVersion) throws PDUStringException,
IOException {

byte[] b = pduComposer.bindResp(commandId, sequenceNumber, systemId);

OptionalParameter p[];
if(interfaceVersion != null) {
OptionalParameter interfaceVersionParam = new OptionalParameter.Byte(Tag.SC_INTERFACE_VERSION, interfaceVersion.value());
p = new OptionalParameter[] {interfaceVersionParam};
} else {
p = new OptionalParameter[] {};
}

byte[] b = pduComposer.bindResp(commandId, sequenceNumber, systemId, p);
writeAndFlush(os, b);
return b;
}
Expand Down
2 changes: 1 addition & 1 deletion jsmpp/src/main/java/org/jsmpp/PDUSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ byte[] sendBind(OutputStream os, BindType bindType, int sequenceNumber,
* @throws IOException if an IO error occur.
*/
byte[] sendBindResp(OutputStream os, int commandId, int sequenceNumber,
String systemId) throws PDUStringException, IOException;
String systemId, InterfaceVersion interfaceVersion) throws PDUStringException, IOException;

/**
* Send unbind command.
Expand Down
4 changes: 2 additions & 2 deletions jsmpp/src/main/java/org/jsmpp/SynchronizedPDUSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public byte[] sendBind(OutputStream os, BindType bindType,
* java.lang.String)
*/
public byte[] sendBindResp(OutputStream os, int commandId,
int sequenceNumber, String systemId) throws PDUStringException,
int sequenceNumber, String systemId, InterfaceVersion interfaceVersion) throws PDUStringException,
IOException {
synchronized (os) {
return pduSender.sendBindResp(os, commandId, sequenceNumber,
systemId);
systemId, interfaceVersion);
}
}

Expand Down
17 changes: 16 additions & 1 deletion jsmpp/src/main/java/org/jsmpp/session/BindParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.jsmpp.session;

import org.jsmpp.bean.BindType;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.TypeOfNumber;

Expand All @@ -32,6 +33,7 @@ public class BindParameter {
private TypeOfNumber addrTon;
private NumberingPlanIndicator addrNpi;
private String addressRange;
private InterfaceVersion interfaceVersion;

/**
* Construct with all mandatory parameters.
Expand All @@ -47,15 +49,22 @@ public class BindParameter {
public BindParameter(BindType bindType, String systemId, String password,
String systemType, TypeOfNumber addrTon,
NumberingPlanIndicator addrNpi, String addressRange) {
this(bindType, systemId, password, systemType, addrTon, addrNpi, addressRange, InterfaceVersion.IF_34);
}

public BindParameter(BindType bindType, String systemId, String password,
String systemType, TypeOfNumber addrTon,
NumberingPlanIndicator addrNpi, String addressRange, InterfaceVersion interfaceVersion) {
this.bindType = bindType;
this.systemId = systemId;
this.password = password;
this.systemType = systemType;
this.addrTon = addrTon;
this.addrNpi = addrNpi;
this.addressRange = addressRange;
this.interfaceVersion = interfaceVersion;
}

public BindType getBindType() {
return bindType;
}
Expand Down Expand Up @@ -100,6 +109,9 @@ public int hashCode() {
+ ((systemId == null) ? 0 : systemId.hashCode());
result = prime * result
+ ((systemType == null) ? 0 : systemType.hashCode());
result = prime * result
+ ((interfaceVersion == null) ? 0 : interfaceVersion.hashCode());

return result;
}

Expand Down Expand Up @@ -199,5 +211,8 @@ public boolean equals(Object obj) {
return true;
}

public InterfaceVersion getInterfaceVersion() {
return interfaceVersion;
}

}
30 changes: 26 additions & 4 deletions jsmpp/src/main/java/org/jsmpp/session/BindRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jsmpp.PDUStringException;
import org.jsmpp.bean.Bind;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.ProcessRequestException;
Expand All @@ -43,14 +44,15 @@ public class BindRequest {
private final TypeOfNumber addrTon;
private final NumberingPlanIndicator addrNpi;
private final String addressRange;
private final InterfaceVersion interfaceVersion;

private final int originalSequenceNumber;
private boolean done;

private final ServerResponseHandler responseHandler;
public BindRequest(int sequenceNumber, BindType bindType, String systemId, String password,
String systemType, TypeOfNumber addrTon, NumberingPlanIndicator addrNpi,
String addressRange, ServerResponseHandler responseHandler) {
String addressRange, InterfaceVersion interfaceVersion, ServerResponseHandler responseHandler) {
this.originalSequenceNumber = sequenceNumber;
this.responseHandler = responseHandler;

Expand All @@ -61,14 +63,15 @@ public BindRequest(int sequenceNumber, BindType bindType, String systemId, Strin
this.addrTon = addrTon;
this.addrNpi = addrNpi;
this.addressRange = addressRange;
this.interfaceVersion = interfaceVersion;
}

public BindRequest(Bind bind, ServerResponseHandler responseHandler) {
this(bind.getSequenceNumber(), BindType.valueOf(bind.getCommandId()), bind.getSystemId(),
bind.getPassword(), bind.getSystemType(),
TypeOfNumber.valueOf(bind.getAddrTon()),
NumberingPlanIndicator.valueOf(bind.getAddrNpi()),
bind.getAddressRange(), responseHandler);
bind.getAddressRange(), InterfaceVersion.valueOf(bind.getInterfaceVersion()), responseHandler);
}

@Deprecated
Expand Down Expand Up @@ -104,8 +107,12 @@ public String getAddressRange() {
return addressRange;
}

public InterfaceVersion getInterfaceVersion() {
return interfaceVersion;
}
/**
* Accept the bind request.
* Accept the bind request. Will not send the optional parameter sc_interface_version in
* the bind response message.
*
* @param systemId is the system identifier that will be send to ESME.
* @throws PDUStringException if the system id is not valid.
Expand All @@ -114,13 +121,28 @@ public String getAddressRange() {
* @see #reject(ProcessRequestException)
*/
public void accept(String systemId) throws PDUStringException, IllegalStateException, IOException {
accept(systemId, null);
}

/**
* Accept the bind request. The provided interface version will be put into the optional parameter
* sc_interface_version in the bind response message.
*
* @param systemId is the system identifier that will be send to ESME.
* @param interfaceVersion is the interface version that will be sent to the ESME
* @throws PDUStringException if the system id is not valid.
* @throws IllegalStateException if the acceptance or rejection has been made.
* @throws IOException is the connection already closed.
* @see #reject(ProcessRequestException)
*/
public void accept(String systemId, InterfaceVersion interfaceVersion) throws PDUStringException, IllegalStateException, IOException {
StringValidator.validateString(systemId, StringParameter.SYSTEM_ID);
lock.lock();
try {
if (!done) {
done = true;
try {
responseHandler.sendBindResp(systemId, bindType, originalSequenceNumber);
responseHandler.sendBindResp(systemId, interfaceVersion, bindType, originalSequenceNumber);
} finally {
condition.signal();
}
Expand Down
5 changes: 3 additions & 2 deletions jsmpp/src/main/java/org/jsmpp/session/SMPPServerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jsmpp.bean.DataCoding;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.ESMClass;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.MessageState;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.OptionalParameter;
Expand Down Expand Up @@ -317,10 +318,10 @@ public void sendUnbindResp(int sequenceNumber) throws IOException {
pduSender().sendUnbindResp(out, SMPPConstant.STAT_ESME_ROK, sequenceNumber);
}

public void sendBindResp(String systemId, BindType bindType, int sequenceNumber) throws IOException {
public void sendBindResp(String systemId, InterfaceVersion interfaceVersion, BindType bindType, int sequenceNumber) throws IOException {
sessionContext.bound(bindType);
try {
pduSender().sendBindResp(out, bindType.responseCommandId(), sequenceNumber, systemId);
pduSender().sendBindResp(out, bindType.responseCommandId(), sequenceNumber, systemId, interfaceVersion);
} catch (PDUStringException e) {
logger.error("Failed sending bind response", e);
// TODO uudashr: we have double checking when accept the bind request
Expand Down
2 changes: 1 addition & 1 deletion jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public String connectAndBind(String host, int port,
pduReaderWorker = new PDUReaderWorker();
pduReaderWorker.start();
String smscSystemId = sendBind(bindParam.getBindType(), bindParam.getSystemId(), bindParam.getPassword(), bindParam.getSystemType(),
InterfaceVersion.IF_34, bindParam.getAddrTon(), bindParam.getAddrNpi(), bindParam.getAddressRange(), timeout);
bindParam.getInterfaceVersion(), bindParam.getAddrTon(), bindParam.getAddrNpi(), bindParam.getAddressRange(), timeout);
sessionContext.bound(bindParam.getBindType());

enquireLinkSender = new EnquireLinkSender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jsmpp.bean.Bind;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.CancelSm;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.MessageState;
import org.jsmpp.bean.QuerySm;
import org.jsmpp.bean.ReplaceSm;
Expand All @@ -33,7 +34,7 @@
*
*/
public interface ServerResponseHandler extends BaseResponseHandler {
void sendBindResp(String systemId, BindType bindType, int sequenceNumber)
void sendBindResp(String systemId, InterfaceVersion interfaceVersion, BindType bindType, int sequenceNumber)
throws IOException;

void sendSubmitSmResponse(MessageId messageId, int sequenceNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jsmpp.bean.Bind;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.InterfaceVersion;

import static org.testng.Assert.*;

Expand Down Expand Up @@ -115,6 +116,7 @@ public void testNonSingleWait() {
private static final Bind dummyBind() {
Bind bind = new Bind();
bind.setCommandId(BindType.BIND_RX.commandId());
bind.setInterfaceVersion(InterfaceVersion.IF_34.value());
return bind;
}
}
2 changes: 1 addition & 1 deletion jsmpp/src/test/java/org/jsmpp/session/BindRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BindRequestTest {
@BeforeMethod
public void setUp() {
responseHandler = new DummyResponseHandler();
bindRequest = new BindRequest(1, BindType.BIND_TRX, null, null, null, null, null, null, responseHandler);
bindRequest = new BindRequest(1, BindType.BIND_TRX, null, null, null, null, null, null, null, responseHandler);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jsmpp.bean.CancelSm;
import org.jsmpp.bean.Command;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.InterfaceVersion;
import org.jsmpp.bean.MessageState;
import org.jsmpp.bean.QuerySm;
import org.jsmpp.bean.ReplaceSm;
Expand Down Expand Up @@ -84,7 +85,7 @@ public MessageId processSubmitSm(SubmitSm submitSm)
return null;
}

public void sendBindResp(String systemId, BindType bindType, int sequenceNumber)
public void sendBindResp(String systemId, InterfaceVersion interfaceVersion, BindType bindType, int sequenceNumber)
throws IOException {
if (connectionClosed) {
throw new IOException("Connection closed");
Expand Down

0 comments on commit b3bafb3

Please sign in to comment.