public class API
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
aMemory
The 5 memory Strings available in the GUI
|
static java.util.Hashtable |
globalVars
The global variables, which remain accessible as long as the GUI is not closed.
|
static java.lang.String |
inputFile
input file from the commandline
|
protected static int |
iScriptResultCode |
static java.lang.String |
lastError
Contains the last error that occurred or null on OK
|
protected static long |
lScriptStart |
protected static long |
lScriptStop |
static java.lang.String |
password
password from the commandline
|
static java.lang.String |
scriptFile
current script file
|
static java.lang.String |
username
username from the commandline
|
static java.util.Vector |
vScriptFiles
the script file call stack - current scriptfile is at index 0
|
static java.lang.String |
webserviceFile
webservice file from the commandline
|
static ApiWebserviceFile |
wsFile
The webservice file open in the GUI or opened with API.loadWebserviceFile
|
Constructor and Description |
---|
API() |
Modifier and Type | Method and Description |
---|---|
void |
closeWebserviceFile()
Closes the webservice file
This should always be done at the end of the script to release
a potentially hold write lock on the file.
|
boolean |
copyFile(java.lang.String source,
java.lang.String target)
Helper method to easily copy a file
|
int |
countInputFields(XMLElement xelem)
Counts the amount of input fields in a request or user input GUI
|
boolean |
fillInputFields(ApiRequest request,
java.util.Vector inputData)
Fills the input fields from the strings in a Vector
The vector size must match the amount of input fields in the request (marked with wst_title attribute) |
java.lang.String |
getAppPath()
Returns the path of WebserviceTool.eve
|
java.util.Vector |
getAppVersion()
Returns the version and the build number of this application
Example: Wenn the full version string is "5.4.1 (142)" then the
version is "5.4.1" and the build number is 142
|
ApiRequest |
getRequestByID(long uniqueID)
Gets an ApiRequest instance by ID.
|
ApiRequest |
getRequestByName(java.lang.String webserviceName,
java.lang.String requestName)
Gets an ApiRequest instance by name.
|
eve.io.File |
getRequestFile(ApiRequest request)
Gets the File of the request file
|
long |
getScriptRunTime()
Returns the run time of the current script (if still running) or
the run time of the last script
|
ApiWebservice |
getWebservice(ApiRequest areq)
Gets the ApiWebservice to which an ApiRequest belongs
|
ApiWebservice |
getWebserviceByID(long uniqueID)
Gets an ApiWebservice instance by ID.
|
org.bouncycastle.asn1.x509.Certificate |
getWebserviceCertificate(ApiWebservice aWS)
Gets the client certificate of a webservice
|
XMLElement |
getWebserviceList()
Gets a list of the webservices and their requests
|
org.bouncycastle.crypto.params.AsymmetricKeyParameter |
getWebservicePrivateKey(ApiWebservice aWS,
java.lang.String password)
Gets the private key defined for a webservice
|
XMLElement |
getXMLElementByXpath(XMLElement rootElement,
java.lang.String xPath)
Gets an XMLElement by its XPath
|
ApiHtmlTab |
guiAddHtmlTab(java.lang.String htmlText,
boolean takeFocus)
Adds a html tab and displays a html text.
|
ApiTextTab |
guiAddTextTab(java.lang.String text,
boolean takeFocus)
Adds a text tab and displays a String.
|
int |
guiEditRequest(ApiRequest request)
Displays a GUI to allow the user to edit the request.
|
void |
guiFlashMessage(java.lang.String text,
int msec)
Dispiays a flash message when GUI is available (otherwise does nothing)
|
java.lang.String |
guiGetConsoleText()
Get the text of the console control when GUI is available
|
eve.ui.TabbedPanel |
guiGetTabbedPanel() |
java.util.Vector |
guiGetUserInput(XMLElement gui,
java.lang.String descr)
Calls guiGetUserInput (gui, descr, null);
|
java.util.Vector |
guiGetUserInput(XMLElement gui,
java.lang.String descr,
ApiRequest areq)
Shows a GUI and lets the user input data (only allowed in GUI mode).
|
int |
guiSetScriptStatus(java.lang.String line)
Sets the second line of the script status field
Only allowed in GUI mode.
|
int |
guiShowInGUI(ApiRequest request,
ApiResponse response,
java.lang.String selectTab)
Shows the request and the response in the GUI, if they are not null.
|
int |
guiShowJsonInGUI(ApiRequest request,
java.lang.String jsonString,
boolean selectTab)
Shows a JSON String in the GUI.
|
int |
guiShowXmlInGUI(ApiRequest request,
java.lang.String xmlString,
boolean selectTab)
Shows an XML String in the GUI.
|
boolean |
guiUpdateWebserviceFile(int target,
ApiRequest request)
Updates the request or webservice in the webservice definition file
(*.ws5) with the data of the ApiRequest.
|
ApiResponse |
invokeRequest(ApiRequest request,
java.util.Vector inputData)
Invokes a request and returns the response.
|
static boolean |
isGuiAvailable()
Checks if we are in GUI mode or not
|
ApiWebserviceFile |
loadWebserviceFile(java.lang.String filename,
java.lang.String encryptedKey)
Loads the webservice definition file.
|
java.util.Vector |
readInputFile()
Calls readInputFile(API.inputFile)
|
java.util.Vector |
readInputFile(java.lang.String filename)
Calls readInputFile(API.inputFile, "ISO-8859-1")
|
java.util.Vector |
readInputFile(java.lang.String filename,
java.lang.String encoding)
Reads a tab-separated text file and returns a Vector containing
a Vector of Strings for every line in file.
|
XMLElement |
removeWstAttributes(XMLElement xelem)
Makes a deep clone of the XMLElement and then removes all attributes
of WebserviceTool from the clone
|
java.lang.Object |
runScript(java.lang.String filename)
Run a sub-script from the current (parent) script after validating
the signature of the sub-script.
|
void |
setScriptResultCode(int code)
Sets the result code which will be returned to the operating system
when running from the commandline.
|
public static java.lang.String scriptFile
public static java.util.Vector vScriptFiles
public static java.lang.String username
public static java.lang.String password
public static java.lang.String inputFile
public static java.lang.String webserviceFile
public static java.lang.String lastError
public static ApiWebserviceFile wsFile
public static java.util.Hashtable globalVars
public static java.lang.String[] aMemory
protected static int iScriptResultCode
protected static long lScriptStart
protected static long lScriptStop
public void closeWebserviceFile()
public boolean copyFile(java.lang.String source, java.lang.String target)
source
- The path to the source filetarget
- The path to the target filepublic int countInputFields(XMLElement xelem)
xelem
- The XMLElementpublic boolean fillInputFields(ApiRequest request, java.util.Vector inputData)
request
- The ApiRequest objectinputData
- A Vector of Strings with input data.public java.lang.String getAppPath()
public java.util.Vector getAppVersion()
public ApiRequest getRequestByID(long uniqueID)
uniqueID
- The ID of the requestpublic ApiRequest getRequestByName(java.lang.String webserviceName, java.lang.String requestName)
webserviceName
- The name of the webservicerequestName
- The name of the requestpublic eve.io.File getRequestFile(ApiRequest request)
request
- The ApiRequestpublic long getScriptRunTime()
public ApiWebservice getWebserviceByID(long uniqueID)
uniqueID
- The ID of the webservicepublic org.bouncycastle.asn1.x509.Certificate getWebserviceCertificate(ApiWebservice aWS)
aWS
- The ApiWebservicepublic ApiWebservice getWebservice(ApiRequest areq)
areq
- The ApiRequestpublic XMLElement getWebserviceList()
public org.bouncycastle.crypto.params.AsymmetricKeyParameter getWebservicePrivateKey(ApiWebservice aWS, java.lang.String password)
aWS
- The ApiWebservicepassword
- The modification password set for the webservicepublic XMLElement getXMLElementByXpath(XMLElement rootElement, java.lang.String xPath)
rootElement
- The root element of the XML structurexPath
- The XPath to the elementpublic ApiHtmlTab guiAddHtmlTab(java.lang.String htmlText, boolean takeFocus)
htmlText
- The html text to displaytakeFocus
- Set to true if the new tab should take focuspublic ApiTextTab guiAddTextTab(java.lang.String text, boolean takeFocus)
text
- The text to displaytakeFocus
- Set to true if the new tab should take focuspublic void guiFlashMessage(java.lang.String text, int msec)
text
- The text to displaymsec
- The display duration in millisecondspublic java.lang.String guiGetConsoleText()
public eve.ui.TabbedPanel guiGetTabbedPanel()
public java.util.Vector guiGetUserInput(XMLElement gui, java.lang.String descr, ApiRequest areq)
Example: XMLElement xGui, xel; Vector v; String stGui; stGui = "<gui>"; // use any element name stGui+= "<e wst_title='Name' />"; // use any element name stGui+= "<e wst_title='Single Selection' wst_inputForm=\"{'formType':'singleItemChooser','values':'0,1,2','optLabels':'undefined,female,male'}\" />"; // optSeparator is also supported stGui+= "<e wst_title='Multi Selection' wst_inputForm=\"{'formType':'multiItemChooser','values':'Tick\tTrick\tTrack','optSeparator':'\t'}\" />"; // optLabels is also supported stGui+= "<e wst_title='Dynamic Values' />"; stGui+= "<e wst_title='Choose file for open' wst_inputForm=\"{'formType':'fileOpenChooser','optStartDir':'C:/Downloads'}\" />"; stGui+= "<e wst_title='Choose file for save' wst_inputForm=\"{'formType':'fileSaveChooser','optStartDir':'C:/Downloads'}\" />"; stGui+= "<e wst_title='Choose directory' wst_inputForm=\"{'formType':'dirChooser','optStartDir':'C:/Downloads'}\" />"; stGui+= "<e wst_title='Choose date' wst_inputForm=\"{'formType':'dateChooser','format':'dd.MM.yyyy'}\" />"; stGui+= "<e wst_title='Choose date and time' wst_inputForm=\"{'formType':'dateTimeChooser','format':'yyyy-MM-dd\\'T\\'HH:mm:ss'}\" />"; stGui+= "<e wst_title='Numeric input' wst_inputForm=\"{'formType':'numericInput','minValue':1900,'maxValue':2100}\" />"; stGui+= "</gui>"; xGui = new XMLElement(new Hashtable(), true, false); xGui.parseString(stGui); xel = NanoXmlUtils.getElementByXpath(xGui,"/gui/e[4]"); xel.setAttribute("wst_inputForm", "{'formType':'singleItemChooser','values':'fill in,the values,you need'}"); xel.setAttribute("wst_isReadonly", "true"); // only makes sense in combination with wst_formType v = API.guiGetUserInput(xGui,"Enter input data",null); if (v==null) { if (API.lastError!=null) System.out.println(API.lastError); else System.out.println("Cancelled by User"); return; } for (int i=0;i<v.size();i++) { System.out.println((String)v.get(i)); }
gui
- The GUI definitiondescr
- The optional description to be shown at the bottom of the GUI.areq
- The ApiRequest is required when wst_isEncrypted is used, otherwise it is optionalpublic java.util.Vector guiGetUserInput(XMLElement gui, java.lang.String descr)
gui
- The GUI definitiondescr
- The optional description to be shown at the bottom of the GUI.public int guiEditRequest(ApiRequest request)
request
- An ApiRequest object, must not be nullpublic int guiSetScriptStatus(java.lang.String line)
line
- The text to displaypublic int guiShowInGUI(ApiRequest request, ApiResponse response, java.lang.String selectTab)
request
- The ApiRequestresponse
- The ApiResponseselectTab
- "a"=new focus on request, "b"=new focus on response, ""=no new focuspublic int guiShowJsonInGUI(ApiRequest request, java.lang.String jsonString, boolean selectTab)
request
- The ApiRequest used to get the request properties defined in the GUIjsonString
- The String containing the JSON objectselectTab
- If true, the new tab gets the focuspublic int guiShowXmlInGUI(ApiRequest request, java.lang.String xmlString, boolean selectTab)
request
- The ApiRequest used to get the request properties defined in the GUIxmlString
- The String containing the XMLselectTab
- If true, the new tab gets the focuspublic boolean guiUpdateWebserviceFile(int target, ApiRequest request)
target
- What to update: 1=request, 2=webservicerequest
- The ApiRequestpublic ApiResponse invokeRequest(ApiRequest request, java.util.Vector inputData)
request
- The ApiRequest objectinputData
- A Vector of Strings with input data. Can be null
if the request needs no input data or data has already
been entered through the GUIpublic static boolean isGuiAvailable()
public ApiWebserviceFile loadWebserviceFile(java.lang.String filename, java.lang.String encryptedKey)
filename
- The path to the webservice fileencryptedKey
- The encrypted keypublic java.util.Vector readInputFile()
public java.util.Vector readInputFile(java.lang.String filename)
filename
- The file to readpublic java.util.Vector readInputFile(java.lang.String filename, java.lang.String encoding)
filename
- The file to readencoding
- The encoding to use. Supported encodings are ISO-8859-1 (ANSI) and UTF-8public XMLElement removeWstAttributes(XMLElement xelem)
xelem
- The root elementpublic java.lang.Object runScript(java.lang.String filename) throws java.lang.Exception
filename
- The full path and filename of the sub-scriptjava.lang.Exception
- Throws Exceptions that occur during script executionpublic void setScriptResultCode(int code)
code
- The exit code to set