Search in sources :

Example 1 with Tlv

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);
    }
}
Also used : BaseBindResp(com.cloudhopper.smpp.pdu.BaseBindResp) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 2 with Tlv

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);
        }
    }
}
Also used : BaseBindResp(com.cloudhopper.smpp.pdu.BaseBindResp) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) Unbind(com.cloudhopper.smpp.pdu.Unbind) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 3 with Tlv

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");
    }
}
Also used : Address(com.cloudhopper.smpp.type.Address) SubmitSmResp(com.cloudhopper.smpp.pdu.SubmitSmResp) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

Tlv (com.cloudhopper.smpp.tlv.Tlv)3 BaseBind (com.cloudhopper.smpp.pdu.BaseBind)2 BaseBindResp (com.cloudhopper.smpp.pdu.BaseBindResp)2 SubmitSm (com.cloudhopper.smpp.pdu.SubmitSm)1 SubmitSmResp (com.cloudhopper.smpp.pdu.SubmitSmResp)1 Unbind (com.cloudhopper.smpp.pdu.Unbind)1 Address (com.cloudhopper.smpp.type.Address)1 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)1