Search in sources :

Example 1 with WrongLengthOfStringException

use of org.smpp.pdu.WrongLengthOfStringException in project opensmpp by OpenSmpp.

the class SMPPSender method loadProperties.

/**
 * Loads configuration parameters from the file with the given name.
 * Sets private variable to the loaded values.
 */
private void loadProperties(String fileName) throws IOException {
    System.out.println("Reading configuration file " + fileName + "...");
    FileInputStream propsFile = new FileInputStream(fileName);
    properties.load(propsFile);
    propsFile.close();
    System.out.println("Setting default parameters...");
    byte ton;
    byte npi;
    String addr;
    String bindMode;
    int rcvTimeout;
    ipAddress = properties.getProperty("ip-address");
    port = getIntProperty("port", port);
    systemId = properties.getProperty("system-id");
    password = properties.getProperty("password");
    ton = getByteProperty("addr-ton", addressRange.getTon());
    npi = getByteProperty("addr-npi", addressRange.getNpi());
    addr = properties.getProperty("address-range", addressRange.getAddressRange());
    addressRange.setTon(ton);
    addressRange.setNpi(npi);
    try {
        addressRange.setAddressRange(addr);
    } catch (WrongLengthOfStringException e) {
        System.out.println("The length of address-range parameter is wrong.");
    }
    ton = getByteProperty("source-ton", sourceAddress.getTon());
    npi = getByteProperty("source-npi", sourceAddress.getNpi());
    addr = properties.getProperty("source-address", sourceAddress.getAddress());
    setAddressParameter("source-address", sourceAddress, ton, npi, addr);
    ton = getByteProperty("destination-ton", destAddress.getTon());
    npi = getByteProperty("destination-npi", destAddress.getNpi());
    addr = properties.getProperty("destination-address", destAddress.getAddress());
    setAddressParameter("destination-address", destAddress, ton, npi, addr);
    serviceType = properties.getProperty("service-type", serviceType);
    systemType = properties.getProperty("system-type", systemType);
    bindMode = properties.getProperty("bind-mode", bindOption);
    if (bindMode.equalsIgnoreCase("transmitter")) {
        bindMode = "t";
    } else if (bindMode.equalsIgnoreCase("receiver")) {
        bindMode = "r";
    } else if (bindMode.equalsIgnoreCase("transciever")) {
        bindMode = "tr";
    } else if (!bindMode.equalsIgnoreCase("t") && !bindMode.equalsIgnoreCase("r") && !bindMode.equalsIgnoreCase("tr")) {
        System.out.println("The value of bind-mode parameter in " + "the configuration file " + fileName + " is wrong. " + "Setting the default");
        bindMode = "t";
    }
    bindOption = bindMode;
    // blocking in the library is needed.
    if (receiveTimeout == Data.RECEIVE_BLOCKING) {
        rcvTimeout = -1;
    } else {
        rcvTimeout = ((int) receiveTimeout) / 1000;
    }
    rcvTimeout = getIntProperty("receive-timeout", rcvTimeout);
    if (rcvTimeout == -1) {
        receiveTimeout = Data.RECEIVE_BLOCKING;
    } else {
        receiveTimeout = rcvTimeout * 1000;
    }
}
Also used : WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) FileInputStream(java.io.FileInputStream)

Example 2 with WrongLengthOfStringException

use of org.smpp.pdu.WrongLengthOfStringException in project opensmpp by OpenSmpp.

the class DeliveryInfoSender method deliver.

private void deliver(DeliveryInfoEntry entry) {
    debug.enter(this, "deliver");
    SubmitSM submit = entry.submit;
    DeliverSM deliver = new DeliverSM();
    deliver.setEsmClass((byte) Data.SM_SMSC_DLV_RCPT_TYPE);
    deliver.setSourceAddr(submit.getDestAddr());
    deliver.setDestAddr(submit.getDestAddr());
    // ISO-Latin-1
    deliver.setDataCoding((byte) 0x03);
    String msg = "";
    msg += "id:" + entry.messageId + " ";
    msg += "sub:" + entry.sub + " ";
    msg += "dlvrd:" + entry.dlvrd + " ";
    msg += "submit date:" + formatDate(entry.submitted) + " ";
    msg += "done date:" + formatDate(System.currentTimeMillis()) + " ";
    msg += "stat:" + states[entry.stat] + " ";
    msg += "err:" + entry.err + " ";
    String shortMessage = submit.getShortMessage();
    int msgLen = shortMessage.length();
    msg += "text:" + shortMessage.substring(0, (msgLen > 20 ? 20 : msgLen));
    try {
        deliver.setShortMessage(msg);
        deliver.setServiceType(submit.getServiceType());
    } catch (WrongLengthOfStringException e) {
    }
    try {
        entry.processor.serverRequest(deliver);
    } catch (Exception e) {
    }
    debug.exit(this);
}
Also used : WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) SubmitSM(org.smpp.pdu.SubmitSM) WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) DeliverSM(org.smpp.pdu.DeliverSM)

Example 3 with WrongLengthOfStringException

use of org.smpp.pdu.WrongLengthOfStringException in project opensmpp by OpenSmpp.

the class Simulator method sendMessage.

/**
 * Permits data to be sent to a specific client.
 * With the id of the client set by the user, the method <code>sendMessage</code>
 * gets back the specific reference to the client's <code>PDUProcessor</code>.
 * With this reference you are able to send data to the client.
 */
protected void sendMessage() throws IOException {
    if (smscListener != null) {
        int procCount = processors.count();
        if (procCount > 0) {
            String client;
            SimulatorPDUProcessor proc;
            listClients();
            if (procCount > 1) {
                System.out.print("Type name of the destination> ");
                client = keyboard.readLine();
            } else {
                proc = (SimulatorPDUProcessor) processors.get(0);
                client = proc.getSystemId();
            }
            for (int i = 0; i < procCount; i++) {
                proc = (SimulatorPDUProcessor) processors.get(i);
                if (proc.getSystemId().equals(client)) {
                    if (proc.isActive()) {
                        System.out.print("Type the message> ");
                        String message = keyboard.readLine();
                        DeliverSM request = new DeliverSM();
                        try {
                            request.setShortMessage(message);
                            proc.serverRequest(request);
                            System.out.println("Message sent.");
                        } catch (WrongLengthOfStringException e) {
                            System.out.println("Message sending failed");
                            event.write(e, "");
                        } catch (IOException ioe) {
                        } catch (PDUException pe) {
                        }
                    } else {
                        System.out.println("This session is inactive.");
                    }
                }
            }
        } else {
            System.out.println("No client connected.");
        }
    } else {
        System.out.println("You must start listener first.");
    }
}
Also used : SimulatorPDUProcessor(org.smpp.smscsim.SimulatorPDUProcessor) WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) PDUException(org.smpp.pdu.PDUException) DeliverSM(org.smpp.pdu.DeliverSM)

Aggregations

WrongLengthOfStringException (org.smpp.pdu.WrongLengthOfStringException)3 DeliverSM (org.smpp.pdu.DeliverSM)2 FileInputStream (java.io.FileInputStream)1 PDUException (org.smpp.pdu.PDUException)1 SubmitSM (org.smpp.pdu.SubmitSM)1 SimulatorPDUProcessor (org.smpp.smscsim.SimulatorPDUProcessor)1