use of com.cloudhopper.smpp.tlv.Tlv 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.tlv.Tlv 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);
}
}
}
use of com.cloudhopper.smpp.tlv.Tlv in project traccar by tananaev.
the class SmppClient method sendMessageSync.
public synchronized void sendMessageSync(String destAddress, String message, boolean command) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException, IllegalStateException {
if (getSession() != null && getSession().isBound()) {
SubmitSm submit = new SubmitSm();
byte[] textBytes;
textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
if (requestDlr) {
submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED);
}
if (textBytes != null && textBytes.length > 255) {
submit.addOptionalParameter(new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, textBytes, "message_payload"));
} else {
submit.setShortMessage(textBytes);
}
submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress) : new Address(sourceTon, sourceNpi, sourceAddress));
submit.setDestAddress(new Address(destTon, destNpi, destAddress));
SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout);
if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
Log.debug("SMS submitted, message id: " + submitResponce.getMessageId());
} else {
throw new IllegalStateException(submitResponce.getResultMessage());
}
} else {
throw new SmppChannelException("SMPP session is not connected");
}
}
Aggregations