Apply WebHarvest and WorkFusion context variables
In Bot configs you have access both to WebHarvest and WorkFusion context variables.
Manual Task context is described in the Template Variables section.
WebHarvest context
Every WebHarvest variable context initially contains the following help objects that can be used in any expression inside configurations:
Object sys
Object sys that contains general-purpose constants and methods.
| sys.lf | Line feed character (\n) |
| sys.cr | Carriage return character (\r) |
| sys.tab | Tab character (\t) |
| sys.space | Space character ( ) |
| sys.quot | Double quote character (") |
| sys.apos | Single quote character (') |
| sys.backspace | Backspace character (\b) |
| sys.date() | Returns current date in the yyyyMMdd format |
| sys.time() | Returns current time in the HHmmss format |
| sys.datetime(format) | Returns date/time in specified format (Java date and time formatting patterns must be used). |
| sys.escapeXml(text) | Escapes characters &'"<> in the specified text according to XML standard. |
| sys.fullUrl(pageUrl, link) | For the specified URL of the web page and specified link (which could be relative, absolute or full URL) returns full URL. |
| sys.defineVariable(varname, varvalue, [overwrite]) | Defines new variable with specified name and value in the current Web-Harvest context. Parameter overwrite tells whether to overwrite existing variable with the same name. Its default value is true. It has the same meaning as var-def processor, however it could be useful for value exchange between scripts and Web-Harvest context. |
| sys.isVariableDefined(varname) | Tells if variable with specified name is defined in the context. |
| sys.getVar(varname) | Returns variable from scraper context. |
| sys.xpath(xpathexpr, xml) | Evaluates XPath expression on specified XML. Returns instance oforg.webharvest.runtime.variables.Variable class. |
For more details check Java API of this class.
Object http
Object http which provides access to Http client and gives information about HTTP responses:
| http.client | Returns instance of org.apache.commons.httpclient.HttpClient class which is used as primary HTTP client during the configuration execution. For more details, see Jakarta HttpClient documentation. |
| http.contentLength | Lenght of the last HTTP response's content in bytes. |
| http.charset | Encoding of the last HTTP response, if it contain textual content. |
| http.mimeType | Mime type of the last HTTP response. |
| http.headers | Array of HTTP response header pairs. To access individual header by index, use
To access first header value by name, use
To get all headers with specified name use http.getHeaders("headername"):
|
| http.statusCode | Status code of the last HTTP response. |
| http.statusText | Status message of the last HTTP response. |
| http.totalLength | Total length in bytes of all responses returned to this HTTP client. |
| http.totalResponses | Total number of responses returned to this HTTP client. |
Object log
Object log provides ability to print debug information, the logger object is of type org.slf4j.Logger and supports all of the methods from there.
| log.info(message) | Prints the specified message |
| log.error(message, exception) | Prints the specified message along with the exception stacktrace |
| log.debug(messageTemplate, argument) | Formats and prints the specified message template with the passed argument. For example log.debug("Number of objects received: {}", receivedObjects.size()) |
| and many more... | Refer to [org.slf4j.Logger](https://www.slf4j.org/api/org/slf4j/Logger.html) |
WorkFusion context
You can use and access a set of defined variables (with their types) in Web-Harvest XML configuration.
- hit_submission_data_item (Object) - Contains current hit submission data item. CLASS com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemDto
- item (Object) - A web harvest task item. Contains necessary information about run, campaign, submission and other objects. CLASS com.freedomoss.crowdcontrol.webharvest.WebHarvestTaskItem
- prevData (Object) - A web harvest task item. Contains necessary information about run, campaign, submission, and other objects. CLASS com.freedomoss.crowdcontrol.webharvest.PreviousData
- assignment (Object) - Current assignment. CLASS com.freedomoss.crowdcontrol.webharvest.AwsHitAssignmentDto
- source (Object) - Current source. CLASS com.freedomoss.crowdcontrol.webharvest.SourceDto
- dataStoreProperties (Object) - CLASS com.freedomoss.crowdcontrol.webharvest.web.security.DatabaseProperties
- includedConfigs (Map) - Map of included configs. Used in
<include-config>plugin.Map<String, String>: key - config name, value - config body - applicationHost (String) - WorkFusion host name
- applicationContextPath (String) - WorkFusion context path
- applicationResourceUrl (String) - Root URL for resources. Default: https://s3.amazonaws.com
- userInternalCredentials (Object) - Username and hashed password (hashed value fetched from database) of the user that executes current run (Run.createdBy). Contains only username of the task author and empty string password. We don't recommend using this object.
- seleniumDriver (Object)
- seleniumServer (Object)
- seleniumLogger (Object)
- seleniumDriverRegistry (Object)
- selenium_node_id (Object)
- selenium_parent_browser_capabilities (String)
- capabilityNodeId (String)
- exportResult (Object)
- releaseDate (Object)
- s3EndpointUrl (String)
- s3AccessKey (String)
- s3SecretKey (String)
- s3KeyMap (Map)
- secureStorePassword (String)
- securityProviderMap (Map)
Usage examples
Each WorkFusion variable is accessible in Bot config using the getWrappedObject() method - see reference here: http://web-harvest.sourceforge.net/doc/org/webharvest/runtime/variables/Variable.html
The following javaDoc describes all Classes and DTOs (data transfer objects) accessible in Bot configs: https://s3.amazonaws.com/workfusion-docs/context/machine-javadoc/index.html
Example of accessing WorkFusion context variables from machine config
<script>
<![CDATA[
int processingAttempts = item.getWrappedObject().getSubmission().getAwsHit().getProcessingAttempts();
Integer maxAttempts = item.getWrappedObject().getRun().getMaxProcessingCount();
//...
]]>
</script>
<!-- Generate a link to current BP instance (run) -->
<export include-original-data="true">
<single-column name="link" value="${applicationHost}/workfusion/secure/business-process/edit/${item.getWrappedObject().getRun().getRootRunUuid()}" />
</export>