org.marre
Class SmsSender

java.lang.Object
  extended byorg.marre.SmsSender

public class SmsSender
extends java.lang.Object

High level API to the smsj library. If you only need to send some basic SMS messages than you only have to use this API. Ex:

 try
 {
     // Send SMS with clickatell
     SmsSender smsSender = SmsSender.getClickatellSender("username", "password", "apiid");
     String msg = "A sample SMS.";
     // International number to reciever without leading "+"
     String reciever = "464545425463";
     // Number of sender (not supported on all transports)
     String sender = "46534534535";
     // Connect
     smsSender.connect();
     // Send message
     smsSender.send("A sample SMS.", reciever, sender);
     // Disconnect
     smsSender.disconnect();
 }
 catch (IOException ex)
 {
     ex.printStackTrace();
 }
 catch (SmsException ex)
 {
     ex.printStackTrace();
 }
 

Version:
$Id: SmsSender.java,v 1.11 2005/11/26 17:06:45 c95men Exp $
Author:
Markus Eriksson

Field Summary
protected  SmsTransport transport_
          The sms transport that is used to send the messages.
 
Constructor Summary
SmsSender(java.lang.String transport, java.util.Properties props)
          Creates a SmsSender object by using the given transport and properties.
 
Method Summary
 void connect()
          Connect to the server.
 void disconnect()
          Call this when you are done with the SmsSender object.
protected  void finalize()
          Probably never called, but good to have if the caller forget to disconnect().
static SmsSender getClickatellSender(java.lang.String propsFilename)
          Convenience method to create a SmsSender object that knows how to send messages with the Clickatell service.
static SmsSender getClickatellSender(java.lang.String username, java.lang.String password, java.lang.String apiid)
          Convenience method to create a SmsSender object that knows how to send messages with the Clickatell service.
static SmsSender getGsmSender(java.lang.String portName)
          Convenience method to create a SmsSender object that knows how to send messages with a GSM phone attached to the serial port on your computer.
static SmsSender getPsWinCommXmlSender(java.lang.String propsFilename)
          Convenience method to create a SmsSender object that knows how to send messages via PSWinComm
static SmsSender getPsWinCommXmlSender(java.lang.String username, java.lang.String password)
          Convenience method to create a SmsSender object that knows how to send messages via PSWinComm
static SmsSender getUcpSender(java.lang.String propsFilename)
          Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.
static SmsSender getUcpSender(java.lang.String address, int port)
          Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.
static SmsSender getUcpSender(java.lang.String address, int port, java.lang.String ucp60Uid, java.lang.String ucp60Pwd)
          Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.
 java.lang.String sendMmsNotification(java.lang.String contentLocation, long size, java.lang.String subject, java.lang.String dest)
          Sends a simple MMS Notification.
 java.lang.String sendMsgWaitingEmail(int count, java.lang.String dest)
          Sends a email message waiting message indication.
 java.lang.String sendMsgWaitingFax(int count, java.lang.String dest)
          Sends a fax message waiting message indication.
 java.lang.String sendMsgWaitingVoice(int count, java.lang.String dest)
          Sends a voice message waiting message indication.
 java.lang.String sendNokiaBookmark(java.lang.String title, java.lang.String url, java.lang.String dest)
          Sends an OTA Bookmark (Nokia specification) to the given recipient
 java.lang.String sendSms(SmsMessage msg, java.lang.String dest, java.lang.String sender)
          Sends a SmsMessage.
 java.lang.String sendTextSms(java.lang.String text, java.lang.String dest)
          Sends an ordinary SMS to the given recipient.
 java.lang.String sendTextSms(java.lang.String text, java.lang.String dest, java.lang.String sender)
          Sends an ordinary SMS to the given recipient.
 java.lang.String sendUnicodeTextSms(java.lang.String text, java.lang.String dest)
          Sends an ordinary SMS to the given recipient.
 java.lang.String sendUnicodeTextSms(java.lang.String text, java.lang.String dest, java.lang.String sender)
          Sends an ordinary SMS to the given recipient.
 java.lang.String sendWapSiPushMsg(java.lang.String url, java.lang.String text, java.lang.String dest)
          Sends a Wap Push SI containing to the given recipient.
 java.lang.String sendWapSlPushMsg(java.lang.String url, java.lang.String dest)
          Sends a Wap Push SL containing to the given recipient.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transport_

protected SmsTransport transport_
The sms transport that is used to send the messages.

Constructor Detail

SmsSender

public SmsSender(java.lang.String transport,
                 java.util.Properties props)
          throws SmsException
Creates a SmsSender object by using the given transport and properties.

You can also use getClickatellSender(...) to create a SmsSender object

Parameters:
transport - Classname of the SmsTransport class
props - Properties to initialize the transport with
Throws:
SmsException
Method Detail

getClickatellSender

public static SmsSender getClickatellSender(java.lang.String username,
                                            java.lang.String password,
                                            java.lang.String apiid)
                                     throws SmsException
Convenience method to create a SmsSender object that knows how to send messages with the Clickatell service.

Parameters:
username - Clickatell username
password - Clickatell password
apiid - Clickatell api-id
Returns:
A SmsSender object that uses the ClickatellTransport to send messages
Throws:
SmsException

getClickatellSender

public static SmsSender getClickatellSender(java.lang.String propsFilename)
                                     throws SmsException,
                                            java.io.IOException
Convenience method to create a SmsSender object that knows how to send messages with the Clickatell service.

Parameters:
propsFilename - Filename of a properties file containing properties for the clickatell transport.
Returns:
A SmsSender object that uses the ClickatellTransport to send messages
Throws:
SmsException
java.io.IOException

getGsmSender

public static SmsSender getGsmSender(java.lang.String portName)
                              throws SmsException
Convenience method to create a SmsSender object that knows how to send messages with a GSM phone attached to the serial port on your computer.

Parameters:
portName - Serial port where your phone is located. Ex "COM1:"
Returns:
A SmsSender object that uses the GsmTranport to send messages
Throws:
SmsException

getUcpSender

public static SmsSender getUcpSender(java.lang.String address,
                                     int port)
                              throws SmsException
Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.

Parameters:
address - A string with the ip address or host name of the SMSC
port - An integer with the ip port on which the SMSC listens
Returns:
A SmsSender object that uses the UcpTranport to send messages
Throws:
SmsException

getUcpSender

public static SmsSender getUcpSender(java.lang.String address,
                                     int port,
                                     java.lang.String ucp60Uid,
                                     java.lang.String ucp60Pwd)
                              throws SmsException
Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.

Parameters:
address - A string with the ip address or host name of the SMSC
port - An integer with the ip port on which the SMSC listens
ucp60Uid - A string containing the UCP60 userid
ucp60Pwd - A string containing the UCP60 password
Returns:
A SmsSender object that uses the UcpTranport to send messages
Throws:
SmsException

getUcpSender

public static SmsSender getUcpSender(java.lang.String propsFilename)
                              throws SmsException,
                                     java.io.IOException
Convenience method to create a SmsSender object that knows how to send messages with a UCP SMSC.

Parameters:
propsFilename - A string containt a filename with the serialized Properties object for the transport
Returns:
A SmsSender object that uses the UcpTranport to send messages
Throws:
SmsException
java.io.IOException

getPsWinCommXmlSender

public static SmsSender getPsWinCommXmlSender(java.lang.String username,
                                              java.lang.String password)
                                       throws SmsException
Convenience method to create a SmsSender object that knows how to send messages via PSWinComm

Parameters:
username - PsWinComm username
password - PsWinComm password
Returns:
A SmsSender object that uses the PsWinXmlTransport to send messages
Throws:
SmsException

getPsWinCommXmlSender

public static SmsSender getPsWinCommXmlSender(java.lang.String propsFilename)
                                       throws SmsException,
                                              java.io.IOException
Convenience method to create a SmsSender object that knows how to send messages via PSWinComm

Parameters:
propsFilename - Filename of a properties file containing properties for the pswincomm transport.
Returns:
A SmsSender object that uses the PsWinXmlTransport to send messages
Throws:
SmsException
java.io.IOException

sendTextSms

public java.lang.String sendTextSms(java.lang.String text,
                                    java.lang.String dest,
                                    java.lang.String sender)
                             throws SmsException,
                                    java.io.IOException
Sends an ordinary SMS to the given recipient. There is no limit on the number of concatenated SMS that this message will use. It will send the message with the GSM charset (Max 160 chars/SMS).

Parameters:
text - Message to send
dest - Destination number (international format without leading +).
sender - Sender number (international format without leading +). Can also be an alphanumerical string like "SMSJ". This is property is not supported by all transports.
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendTextSms

public java.lang.String sendTextSms(java.lang.String text,
                                    java.lang.String dest)
                             throws SmsException,
                                    java.io.IOException
Sends an ordinary SMS to the given recipient. There is no limit on the number of concatenated SMS that this message will use. It will send the message with the GSM charset (Max 160 chars/SMS).

Parameters:
text - Message to send
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendUnicodeTextSms

public java.lang.String sendUnicodeTextSms(java.lang.String text,
                                           java.lang.String dest,
                                           java.lang.String sender)
                                    throws SmsException,
                                           java.io.IOException
Sends an ordinary SMS to the given recipient. No limit on the number of concatenated SMS that this message will use. Will send the message with the UCS2 charset (MAX 70 chars/SMS).

Parameters:
text - Message to send
dest - Destination number (international format without leading +).
sender - Sender number (international format without leading +). Can also be an alphanumerical string like "SMSJ". This is property is not supported by all transports.
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendUnicodeTextSms

public java.lang.String sendUnicodeTextSms(java.lang.String text,
                                           java.lang.String dest)
                                    throws SmsException,
                                           java.io.IOException
Sends an ordinary SMS to the given recipient. No limit on the number of concatenated SMS that this message will use. Will send the message with the UCS2 charset (MAX 70 chars/SMS).

Parameters:
text - Message to send
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendNokiaBookmark

public java.lang.String sendNokiaBookmark(java.lang.String title,
                                          java.lang.String url,
                                          java.lang.String dest)
                                   throws SmsException,
                                          java.io.IOException
Sends an OTA Bookmark (Nokia specification) to the given recipient

Parameters:
title - String with the title of the bookmark
url - String with the url referenced by the bookmark
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendWapSiPushMsg

public java.lang.String sendWapSiPushMsg(java.lang.String url,
                                         java.lang.String text,
                                         java.lang.String dest)
                                  throws SmsException,
                                         java.io.IOException
Sends a Wap Push SI containing to the given recipient.

Parameters:
text - String with the description of the service
url - String with the url referenced by the SI
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendWapSlPushMsg

public java.lang.String sendWapSlPushMsg(java.lang.String url,
                                         java.lang.String dest)
                                  throws SmsException,
                                         java.io.IOException
Sends a Wap Push SL containing to the given recipient.

Parameters:
url - String with the url referenced by the SL
dest - Destination number in international format
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendMmsNotification

public java.lang.String sendMmsNotification(java.lang.String contentLocation,
                                            long size,
                                            java.lang.String subject,
                                            java.lang.String dest)
                                     throws SmsException,
                                            java.io.IOException
Sends a simple MMS Notification.

Parameters:
contentLocation - Where the mms pdu can be downloaded from.
size - The size of the message.
subject - The subject of the message.
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendMsgWaitingVoice

public java.lang.String sendMsgWaitingVoice(int count,
                                            java.lang.String dest)
                                     throws SmsException,
                                            java.io.IOException
Sends a voice message waiting message indication.

Parameters:
count - Number of messages waiting. Set to 0 to clear the message waiting flag in the phone.
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendMsgWaitingFax

public java.lang.String sendMsgWaitingFax(int count,
                                          java.lang.String dest)
                                   throws SmsException,
                                          java.io.IOException
Sends a fax message waiting message indication.

Parameters:
count - Number of messages waiting. Set to 0 to clear the message waiting flag in the phone.
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendMsgWaitingEmail

public java.lang.String sendMsgWaitingEmail(int count,
                                            java.lang.String dest)
                                     throws SmsException,
                                            java.io.IOException
Sends a email message waiting message indication.

Parameters:
count - Number of messages waiting. Set to 0 to clear the message waiting flag in the phone.
dest - Destination number (international format without leading +).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

sendSms

public java.lang.String sendSms(SmsMessage msg,
                                java.lang.String dest,
                                java.lang.String sender)
                         throws SmsException,
                                java.io.IOException
Sends a SmsMessage.

Parameters:
msg - The message to send.
dest - Destination number (international format without leading +) Ex. 44546754235
sender - Destination number (international format without leading +). Can also be an alphanumerical string. Ex "SMSJ". (not supported by all transports).
Returns:
Returns a local message id for the sent message. It is possible that the message id is null.
Throws:
SmsException
java.io.IOException

connect

public void connect()
             throws SmsException,
                    java.io.IOException
Connect to the server. Must be called before any send method.

Throws:
SmsException
java.io.IOException

disconnect

public void disconnect()
                throws SmsException,
                       java.io.IOException
Call this when you are done with the SmsSender object. It will free any resources that we have used.

Throws:
SmsException
java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Probably never called, but good to have if the caller forget to disconnect().

Throws:
java.lang.Throwable
See Also:
Object.finalize()


Copyright © 2002-2005 Markus Eriksson. All Rights Reserved.