Class 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

      Fields 
      Modifier and Type Field Description
      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 successfully sent or not.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String extractCountryPrefix​(java.lang.String phoneNumber)
      Extract country prefix from phone number.
      void forgetCookie​(java.lang.String name, java.lang.String domain, java.lang.String path)
      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 setProblem​(java.lang.Object problem)
      Same as calling setProblem(problem, null).
      void setProblem​(java.lang.Object problem, java.lang.String param)
      Problem displayed when sending was unsuccessful.
      void setReferer​(java.lang.String referer)
      Referer (HTTP 'Referer' header) used for all following requests.
      void setSupplementalMessage​(java.lang.String supplMessage)
      Optional supplemental message from gateway that is shown after message sending.
      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

      • 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 successfully sent or not.
    • Constructor Detail

      • GatewayExecutor

        public GatewayExecutor​(SMS sms)
    • Method Detail

      • 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
      • setProblem

        public void setProblem​(java.lang.Object problem)
        Same as calling setProblem(problem, null).
      • setProblem

        public void setProblem​(java.lang.Object problem,
                               java.lang.String param)
        Problem displayed when sending was unsuccessful.
        Parameters:
        problem - problem from Problem enum
        param - some problems require additional string parameter, see their description
      • setSupplementalMessage

        public void setSupplementalMessage​(java.lang.String supplMessage)
        Optional supplemental 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
      • extractCountryPrefix

        public java.lang.String extractCountryPrefix​(java.lang.String phoneNumber)
        Extract country prefix from phone number.
        Parameters:
        phoneNumber - Phone number in fully international format. May be null or incomplete.
        Returns:
        Country prefix if valid one is found in the number. Empty string otherwise.