User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 456,509 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,661 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2969 | Replies: 5
Reply
Join Date: Sep 2007
Posts: 1
Reputation: Emret is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Emret Emret is offline Offline
Newbie Poster

Sending SMS from website over SMPP

  #1  
Sep 26th, 2007
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
Last edited by Emret : Sep 26th, 2007 at 9:22 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Posts: 74
Reputation: lookof2day is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: Sending SMS from website over SMPP

  #2  
Sep 26th, 2007
Have you checked the ConnectionSmpp object here
ConnectionSmpp con = ocm.getConnection();
            ocm.submit(con);

I mean is it containing a valid value??
Reply With Quote  
Join Date: Aug 2007
Posts: 74
Reputation: lookof2day is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: Sending SMS from website over SMPP

  #3  
Sep 26th, 2007
Also, when is the connect() method being called...??
Reply With Quote  
Join Date: Apr 2008
Posts: 2
Reputation: uudashr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
uudashr uudashr is offline Offline
Newbie Poster

Re: Sending SMS from website over SMPP

  #4  
Apr 24th, 2008
Hello,

You might want to try jsmpp http://code.google.com/p/jsmpp . This API should be easy to use.
Reply With Quote  
Join Date: Oct 2008
Posts: 1
Reputation: Suryam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Suryam Suryam is offline Offline
Newbie Poster

Re: Sending SMS from website over SMPP

  #5  
Oct 3rd, 2008
can anyone tell what r the packages used for this code..
it is very helpfull to me..
thanq
Reply With Quote  
Join Date: Apr 2008
Posts: 2
Reputation: uudashr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
uudashr uudashr is offline Offline
Newbie Poster

Re: Sending SMS from website over SMPP

  #6  
Oct 3rd, 2008
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.

Originally Posted by Suryam View Post
can anyone tell what r the packages used for this code..
it is very helpfull to me..
thanq
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 3:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC