Hello code monkeys :p

I need some guidance with an application that I am working on.

The idea for the application is as follows:

The user is presented with a search field where he/she is supposed to enter a control number. This control number has a relation to a certain mobile phone number in a database.
Now, when the user inputs a control number that exist in the database I want an SMS to be sent to the phone number that is related to the control number.

The plan is to use SMPP for sending the SMS. I already have an application that utilize the SMPP procotol, but here it is set up as a Tranceiver with asynchronous threads and a connection observer.
The thing is, I don't need this connection observer thingy since there won't be any incoming messages to handle. All I want is to be able to send an SMS so I guess I should bind the connection as a Transmitter. I have been goofing around with the Java code for nearly two days trying to get it to work but the problem seems to be that the connection is not set up properly. Can anyone help me out? Here is the code I have so far (still to be considered laboratory work)

public class OutgoingControlMessage extends Thread {
    public ConnectionSmpp conn;
    protected static Logger logger = Logger.getLogger(OutgoingControlMessage.class);
    boolean retry=false;
    boolean exit =false;
    String outgoingMessage="";
    String phNr="";
    /** Creates a new instance of OutgoingControlMessage */
    public OutgoingControlMessage(String message, String inPhNr) {
        outgoingMessage = message;
        phNr = inPhNr;
    }
    
    public void connect(){
        GetMainProperty getProp = new GetMainProperty();
        getProp.activateProperties();
        try {
            conn = null;
             conn = new ConnectionSmpp("212.247.165.8", 3600);
            //conn = new ConnectionSmpp(getProp.getIpnr(), getProp.getPort(), true);
            //conn.addObserver(this);
        } catch (UnknownHostException uhe) {
            logger.error("UnknownHostException" + uhe);
            uhe.printStackTrace();
            System.exit(0);
        }
        
        retry = false;
        int MaxNumTryes = 0;
        
        while (!retry) {
            MaxNumTryes += 1;
            if (MaxNumTryes >= 6){
                retry = true;
            }
            
            try {
                conn.bind(ConnectionSmpp.TRANSMITTER, "Testing", getProp.getSystempass(), getProp.getSystemtype());
                conn.autoAckMessages(true); //ackar automatiskt till Tele2
                MaxNumTryes = 0;
                retry = true;
            } catch (IOException ioe) {
                logger.error("IOException:" + ioe);
                ioe.printStackTrace();
                try { //om problem med bind, sleep 1 sek och försök igen
                    sleep(10 * 1000);
                } catch (InterruptedException ie) {
                    logger.error(ie);
                    ie.printStackTrace();
                }
            }
        }
    }
    public void submit(ConnectionSmpp conn){
        try {
            SubmitSM mess = processRequest(); //NullPointerException here
            SubmitSMResp smr = (SubmitSMResp)conn.sendRequest(mess);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    private SubmitSM processRequest() throws BadCommandIDException{
        SubmitSM sm = (SubmitSM)conn.newInstance(SMPPPacket.SUBMIT_SM); //NullPointerException here
        Address rcvr = new Address();
        rcvr.setAddress(phNr);
        sm.setDestination(rcvr);
        Address SendLocation = new Address();
        try {
            SendLocation.setTON(0);
            SendLocation.setNPI(1);
            SendLocation.setAddress("72694");
            sm.setSource(SendLocation);
            logPacket(sm, "Outgoing:");
        } catch (Exception ex) {
            outgoingMessage = "Något gick förfärligt fel. Vederbörande ombedes att omgående söka assistans";
            ex.printStackTrace();
        }
        sm.setMessageText(outgoingMessage);
        return sm;
    }
    
    private void logPacket(SMPPPacket packet, String direction) {
        String phone;
        if (direction.equals("Outgoing:")) //utgående meddelande
            phone = packet.getDestination().getAddress();
        else //ingående meddelande
            phone = packet.getSource().getAddress();
        logger.info(direction + ": " + phone +  " - " + packet.getMessageText());
    }
    
     public ConnectionSmpp getConnection() {
         //logger.info(conn.toString());
        return conn;
    }
    
    public void run() {
        while (!exit) {
            connect();
            synchronized(this) {
                try {
                    wait();
                } catch (InterruptedException ie) {
                    logger.error("Interrupted Exception: " + ie);
                    ie.printStackTrace();
                }
            }
        }
    }
}

and in the index.jsp file I have:

String phNr = "46737562581";
            OutgoingControlMessage ocm = new OutgoingControlMessage("Tjohej",phNr);
            ocm.start();
            ConnectionSmpp con = ocm.getConnection();
            ocm.submit(con);

I get some NullPointerExceptions that I have commented in the code above. I am not sure of the reasons for these exceptions. It seems that the connection is null for some reason.

I desperately need some help now, I am really stuck and we are running short on time in the project.

Thanks in advance!

//Emret

Have you checked the ConnectionSmpp object here

ConnectionSmpp con = ocm.getConnection();
            ocm.submit(con);

I mean is it containing a valid value??

can anyone tell what r the packages used for this code..
it is very helpfull to me..
thanq

If what you mean is jsmpp then you can should see on the folder src/java/examples on package org.jsmpp.examples

Those examples is very useful for now.

can anyone tell what r the packages used for this code..
it is very helpfull to me..
thanq

If what you mean is jsmpp then you can should see on the folder src/java/examples on package org.jsmpp.examples

Those examples is very useful for now.

Have you tried using a simple HTTP API?
SMS over HTTP is quite efffective for sending SMS on the internet.

This article has been dead for over six months. Start a new discussion instead.