Package esmska.transfer
Class GatewayExecutor
- java.lang.Object
-
- esmska.transfer.GatewayExecutor
-
public class GatewayExecutor extends java.lang.ObjectClass containing methods, which can be called from gateway scripts. For each gateway script a separate class should be created.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGatewayExecutor.Problem
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringINFO_CREDIT_REMAININGMessage saying how much credit is remaining.static java.lang.StringINFO_FREE_SMS_REMAININGMessage saying how many free SMS are remaining.static java.lang.StringINFO_STATUS_NOT_PROVIDEDMessage used when gateway provides no info whether message was successfully sent or not.
-
Constructor Summary
Constructors Constructor Description GatewayExecutor(SMS sms)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringextractCountryPrefix(java.lang.String phoneNumber)Extract country prefix from phone number.voidforgetCookie(java.lang.String name, java.lang.String domain, java.lang.String path)java.lang.ObjectgetURL(java.lang.String url, java.lang.String[] params)Make a GET request to a provided URLjava.lang.ObjectpostURL(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.StringrecognizeImage(byte[] imageBytes, java.lang.String hint)Ask user to recognize provided image codevoidsetProblem(java.lang.Object problem)Same as calling setProblem(problem, null).voidsetProblem(java.lang.Object problem, java.lang.String param)Problem displayed when sending was unsuccessful.voidsetReferer(java.lang.String referer)Referer (HTTP 'Referer' header) used for all following requests.voidsetSupplementalMessage(java.lang.String supplMessage)Optional supplemental message from gateway that is shown after message sending.voidsleep(long milliseconds)Pauses the execution for specified amount of time.
-
-
-
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
-
forgetCookie
public void forgetCookie(java.lang.String name, java.lang.String domain, java.lang.String path)
-
getURL
public java.lang.Object getURL(java.lang.String url, java.lang.String[] params) throws java.io.IOExceptionMake 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.IOExceptionMake 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.ExecutionExceptionAsk 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.InterruptedExceptionjava.lang.reflect.InvocationTargetExceptionjava.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 enumparam- 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.InterruptedExceptionPauses 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.
-
-