use of com.cloudhopper.smpp.pdu.BaseBindResp in project load-balancer by RestComm.
the class UserSpace method validateConnection.
private void validateConnection(MServerConnectionImpl customer) {
if (logger.isDebugEnabled())
logger.debug("Validate connection for customer with sessionId : " + customer.getSessionId());
BaseBindResp bindResponse = (BaseBindResp) customer.getBindRequest().createResponse();
bindResponse.setSystemId("loadbalancer");
if (customer.getConfig().getInterfaceVersion() >= SmppConstants.VERSION_3_4 && ((BaseBind<?>) customer.getBindRequest()).getInterfaceVersion() >= SmppConstants.VERSION_3_4) {
Tlv scInterfaceVersion = new Tlv(SmppConstants.TAG_SC_INTERFACE_VERSION, new byte[] { customer.getConfig().getInterfaceVersion() });
bindResponse.addOptionalParameter(scInterfaceVersion);
}
if (!(customer.getConfig().getPassword().equals(this.password))) {
if (logger.isDebugEnabled())
logger.debug("LB sending fail bind response for customer with sessionId : " + customer.getSessionId());
// SEND BIND FAILED TO CUSTOMER
bindResponse.setCommandStatus(SmppConstants.STATUS_INVPASWD);
customer.sendBindResponse(bindResponse);
} else {
if (logger.isDebugEnabled())
logger.debug("LB sending successful bind response for customer with sessionId : " + customer.getSessionId());
this.customers.put(customer.getSessionId(), customer);
// SEND BIND SUCCESFULL TO CUSTOMER
bindResponse.setCommandStatus(SmppConstants.STATUS_OK);
customer.sendBindResponse(bindResponse);
}
}
use of com.cloudhopper.smpp.pdu.BaseBindResp in project load-balancer by RestComm.
the class BinderRunnable method run.
@SuppressWarnings("rawtypes")
@Override
public void run() {
boolean connectSuccesful = true;
while (!client.connect()) {
logger.warn("Connection to " + client.getConfig().getHost() + ":" + client.getConfig().getPort() + " failed we will try next server");
index++;
if (index == nodes.size())
index = 0;
if (index == nodes.indexOf(firstNode)) {
connectSuccesful = false;
break;
}
client.getConfig().setHost(nodes.get(index).getIp());
if (!client.getConfig().isUseSsl())
client.getConfig().setPort(Integer.parseInt((String) nodes.get(index).getProperties().get("smppPort")));
else
client.getConfig().setPort(Integer.parseInt((String) nodes.get(index).getProperties().get("smppSslPort")));
logger.warn("Next server : " + client.getConfig().getHost() + ":" + client.getConfig().getPort());
}
if (connectSuccesful) {
client.bind();
} else {
if (client.getClientState() == ClientState.INITIAL) {
BaseBindResp bindResponse = (BaseBindResp) ((BaseBind) packet).createResponse();
bindResponse.setCommandStatus(SmppConstants.STATUS_SYSERR);
bindResponse.setSystemId(client.getConfig().getSystemId());
if (client.getConfig().getInterfaceVersion() >= SmppConstants.VERSION_3_4 && ((BaseBind) packet).getInterfaceVersion() >= SmppConstants.VERSION_3_4) {
Tlv scInterfaceVersion = new Tlv(SmppConstants.TAG_SC_INTERFACE_VERSION, new byte[] { client.getConfig().getInterfaceVersion() });
bindResponse.addOptionalParameter(scInterfaceVersion);
}
serverSessions.get(sessionId).sendBindResponse(bindResponse);
client.setClientState(ClientState.CLOSED);
clientSessions.remove(sessionId);
serverSessions.remove(sessionId);
} else {
serverSessions.get(sessionId).sendUnbindRequest(new Unbind());
clientSessions.remove(sessionId);
}
}
}
Aggregations