esmska.transfer
Class GatewayExecutor

java.lang.Object
  extended by esmska.transfer.GatewayExecutor

public class GatewayExecutor
extends java.lang.Object

Class containing methods, which can be called from gateway scripts. For each gateway script a separate class should be created.


Field Summary
static java.lang.String ERROR_FIX_IN_PROGRESS
           
static java.lang.String ERROR_GATEWAY_MESSAGE
          Message preceding gateway provided error message.
static java.lang.String ERROR_LIMIT_REACHED
          Message that user has not waited long enough to send another message or message quota has been reached.
static java.lang.String ERROR_LONG_TEXT
          Message that message text was too long.
static java.lang.String ERROR_NO_CREDIT
          Message that user does not have sufficient credit.
static java.lang.String ERROR_NO_REASON
          Message that sending failed but gateway hasn't provided any reason for it.
static java.lang.String ERROR_SIGNATURE_NEEDED
          Message that sender signature was wrong.
static java.lang.String ERROR_UNKNOWN
          Message that unknown error happened, maybe error in the script.
static java.lang.String ERROR_WRONG_AUTH
          Message that login or password was wrong.
static java.lang.String ERROR_WRONG_CODE
          Message that security code was wrong.
static java.lang.String ERROR_WRONG_NUMBER
          Message that recepient number was wrong.
static java.lang.String ERROR_WRONG_SIGNATURE
          Message that sender signature was wrong.
static java.lang.String INFO_CREDIT_REMAINING
          Message saying how much credit is remaining.
static java.lang.String INFO_FREE_SMS_REMAINING
          Message saying how many free SMS are remaining.
static java.lang.String INFO_STATUS_NOT_PROVIDED
          Message used when gateway provides no info whether message was successfuly sent or not.
 
Constructor Summary
GatewayExecutor(SMS sms)
           
 
Method Summary
 void forgetCookie(java.lang.String name, java.lang.String domain, java.lang.String path)
          For description see GatewayConnector.forgetCookie( java.lang.String, java.lang.String, java.lang.String)
 java.lang.Object getURL(java.lang.String url, java.lang.String[] params)
          Make a GET request to a provided URL
 java.lang.Object postURL(java.lang.String url, java.lang.String[] params, java.lang.String[] postData)
          Make a POST request with specified data to a provided URL.
 java.lang.String recognizeImage(byte[] imageBytes, java.lang.String hint)
          Ask user to recognize provided image code
 void setErrorMessage(java.lang.String errorMessage)
          Same as calling setErrorMessage(String, null)
 void setErrorMessage(java.lang.String errorMessage, java.lang.String[] params)
          Error message displayed when sending was unsuccessful.
 void setGatewayMessage(java.lang.String gatewayMessage)
          Additional optional message from gateway that is shown after message sending.
 void setReferer(java.lang.String referer)
          Referer (HTTP 'Referer' header) used for all following requests.
 void sleep(long milliseconds)
          Pauses the execution for specified amount of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_WRONG_NUMBER

public static final java.lang.String ERROR_WRONG_NUMBER
Message that recepient number was wrong.


ERROR_WRONG_CODE

public static final java.lang.String ERROR_WRONG_CODE
Message that security code was wrong.


ERROR_LONG_TEXT

public static final java.lang.String ERROR_LONG_TEXT
Message that message text was too long.


ERROR_WRONG_SIGNATURE

public static final java.lang.String ERROR_WRONG_SIGNATURE
Message that sender signature was wrong.


ERROR_SIGNATURE_NEEDED

public static final java.lang.String ERROR_SIGNATURE_NEEDED
Message that sender signature was wrong.


ERROR_WRONG_AUTH

public static java.lang.String ERROR_WRONG_AUTH
Message that login or password was wrong.


ERROR_LIMIT_REACHED

public static final java.lang.String ERROR_LIMIT_REACHED
Message that user has not waited long enough to send another message or message quota has been reached.


ERROR_NO_CREDIT

public static final java.lang.String ERROR_NO_CREDIT
Message that user does not have sufficient credit.


ERROR_NO_REASON

public static final java.lang.String ERROR_NO_REASON
Message that sending failed but gateway hasn't provided any reason for it.


ERROR_GATEWAY_MESSAGE

public static final java.lang.String ERROR_GATEWAY_MESSAGE
Message preceding gateway provided error message.


ERROR_UNKNOWN

public static java.lang.String ERROR_UNKNOWN
Message that unknown error happened, maybe error in the script.


ERROR_FIX_IN_PROGRESS

public static java.lang.String ERROR_FIX_IN_PROGRESS

INFO_FREE_SMS_REMAINING

public static final java.lang.String INFO_FREE_SMS_REMAINING
Message saying how many free SMS are remaining.


INFO_CREDIT_REMAINING

public static final java.lang.String INFO_CREDIT_REMAINING
Message saying how much credit is remaining.


INFO_STATUS_NOT_PROVIDED

public static final java.lang.String INFO_STATUS_NOT_PROVIDED
Message used when gateway provides no info whether message was successfuly sent or not.

Constructor Detail

GatewayExecutor

public GatewayExecutor(SMS sms)
Method Detail

forgetCookie

public void forgetCookie(java.lang.String name,
                         java.lang.String domain,
                         java.lang.String path)
For description see GatewayConnector.forgetCookie( java.lang.String, java.lang.String, java.lang.String)


getURL

public java.lang.Object getURL(java.lang.String url,
                               java.lang.String[] params)
                        throws java.io.IOException
Make a GET request to a provided URL

Parameters:
url - base url where to connect, without any parameters or "?" at the end. In special cases when you don't use params, you can use url as a full url. But don't forget that parameters values must be url-encoded, which you can't do properly in JavaScript.
params - array of url params in form [key1,value1,key2,value2,...]
Returns:
content of the response. It may be String (when requesting HTML page) or just an array of bytes (when requesting eg. an image).
Throws:
java.io.IOException - when there is some problem in connecting

postURL

public java.lang.Object postURL(java.lang.String url,
                                java.lang.String[] params,
                                java.lang.String[] postData)
                         throws java.io.IOException
Make a POST request with specified data to a provided URL.

Parameters:
url - base url where to connect, without any parameters or "?" at the end. In special cases when you don't use params, you can use url as a full url. But don't forget that parameters values must be url-encoded, which you can't do properly in JavaScript.
params - array of url params in form [key1,value1,key2,value2,...]
postData - array of data to be sent in the request in form [key1,value1,key2,value2,...]. This data will be properly url-encoded before sending.
Returns:
content of the response. It may be String (when requesting HTML page) or just an array of bytes (when requesting eg. an image).
Throws:
java.io.IOException - when there is some problem in connecting

recognizeImage

public java.lang.String recognizeImage(byte[] imageBytes,
                                       java.lang.String hint)
                                throws java.lang.InterruptedException,
                                       java.lang.reflect.InvocationTargetException,
                                       java.util.concurrent.ExecutionException
Ask user to recognize provided image code

Parameters:
imageBytes - image bytearray. Java must be able to display this image (PNG, GIF, JPEG, maybe something else).
hint - optional hint that can gateway say to user.
Returns:
Recognized image code. Never returns null, may return empty string.
Throws:
java.lang.InterruptedException
java.lang.reflect.InvocationTargetException
java.util.concurrent.ExecutionException

setErrorMessage

public void setErrorMessage(java.lang.String errorMessage,
                            java.lang.String[] params)
Error message displayed when sending was unsuccessful. You can use simple HTML tags (HTML 3.2).

Some predefined messages take additional parameters:

Parameters:
errorMessage - error message, may be one of predefined
params - may be empty or null, mandatory for some predefined messages

setErrorMessage

public void setErrorMessage(java.lang.String errorMessage)
Same as calling setErrorMessage(String, null)


setGatewayMessage

public void setGatewayMessage(java.lang.String gatewayMessage)
Additional optional message from gateway that is shown after message sending.


setReferer

public void setReferer(java.lang.String referer)
Referer (HTTP 'Referer' header) used for all following requests. Use null for resetting current value back to none.


sleep

public void sleep(long milliseconds)
           throws java.lang.InterruptedException
Pauses the execution for specified amount of time. Nothing happens if the amount is negative.

Throws:
java.lang.InterruptedException