com.java4less.sms.tap
Class TapSender

java.lang.Object
  |
  +--com.java4less.sms.tap.TapSender

public class TapSender
extends java.lang.Object

Class to connect to a SMS Gateway (SMSC) and attempt to deliver a number of SMS messages using the Telelocator Alphanumeric Protocol (TAP).


Field Summary
 Logger logger
          Logger object to be used to monitor the protocol interactions.
 
Constructor Summary
TapSender(CommConnector connector, java.lang.String password)
           
 
Method Summary
 void close()
          Ends the TAP transaction.
 boolean open()
          Opens Communication Connexion and performs initial TAP protocol steps (logon).
 boolean sendMessage(SmsMessage m)
          Sends an SMS Message (low level method).
 boolean sendMessageList(java.util.ArrayList mlist)
          Send a number of messages (high level method).
 boolean sendOneMessage(SmsMessage message)
          Sends One Message (high level method).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public Logger logger
Logger object to be used to monitor the protocol interactions.
Default null value means no logging. Therefore, to activate logging you should provide a logging object. Example:
 TapSender sender = new TapSender( cx, "" ); 
 sender.logger = Logger.getLogger("com.java4less.sms.tap");
 sender.logger.setLevel( 7 );
 

Constructor Detail

TapSender

public TapSender(CommConnector connector,
                 java.lang.String password)
Parameters:
connector - Communitactions Connector that will be used to connect to the SMSC. Usually it's a modem connection but it could be also a direct serial connection or any other, as long as it allows to reach an SMSC that "talks" TAP.
password - TAP password. It will ve provided by the company that offers the TAP gateway. Very often is omitted, just use an empty string in such case.
Method Detail

sendOneMessage

public boolean sendOneMessage(SmsMessage message)
Sends One Message (high level method).
Simplified method, opens & closes connection to the SMSC/TAP server, catches exceptions and updates message status.
This method is intended mainly for testing purposes. You will usually prefer to send more than one message per connection using sendMessageList


sendMessageList

public boolean sendMessageList(java.util.ArrayList mlist)
Send a number of messages (high level method).
Updates each message status. You should check it to know if a particular message was accepted or not.

Parameters:
mlist - To use this method you should first prepare an ArrayList of SmsMessage objects.
Returns:
true if everything worked normally.
false if any exception was detected.

open

public boolean open()
             throws TapException,
                    CommException,
                    java.io.IOException
Opens Communication Connexion and performs initial TAP protocol steps (logon).
If no exception is thrown, you can start sending messages by calling sendMessage.

TapException
CommException
java.io.IOException

sendMessage

public boolean sendMessage(SmsMessage m)
                    throws TapException,
                           java.io.IOException
Sends an SMS Message (low level method). Requires a previous successful call to open().
if no exception is thrown, updates message status to ACCEPTED or REJECTED.
You can subsequently call this method again to send any number of messages, then call close() when you have finished.

Returns:
true if message was accepted.
TapException
java.io.IOException

close

public void close()
           throws BadCloseException
Ends the TAP transaction.
Performs the TAP termination steps and closes the communication channel.
it throws a BadCloseException in two cases :
- during the termination phase the server sent an RS control character that means that it now rejects some messages that it had accepted.
- the termination phase couldn't be performed so we don't have confirmation that the previous case doesn't apply.

BadCloseException