HTTP trigger

Operation name

HTTP trigger

Functional Overview

HTTP trigger is a trigger function to run script by sending request from HTTP clients for specified URL.
GET and POST is available as request.

Fire image



Properties

HTTP trigger settings
Item name Content Remarks
Trigger name Enter the name of the trigger.  
Execution path Enter execution path of trigger.
  • The default value is "path".
  • Example: If in the execution path "run" is specified, the URL of trigger execution will be as follows.

    http://<Hostname or IP address of DataSpiderServer>:<Port number of DataSpiderServer>/dataspider/trigger/run

  • If [Enable HTTPS] at [Control Panel] - [DataSpiderServer Settings] - [Security] tab is checked, URL of trigger execution is as follows.

    https://<Hostname or IP address of DataSpiderServer>:<SSL port number of DataSpiderServer>/dataspider/trigger/run

Action when executed successfully Select the action script which is running in HTTP trigger successfully end.
  • [Return page generated by script]: (default)
    Returns the data in trigger variable "trigger.outputHtml".
  • [Forwarded to another page]:
    Forward to another web page such as JSP.
  • Request can only be forwarded to either a JSP or an HTML.
  • Set JSP file under $DATASPIDER_HOME/server/system/kernel/modules/webcontainer/META-INF/catalina/webapps/dataspider.
Action when exit abnormally Select the operation in case that script performed by HTTP trigger script exits abnormally.
  • [Return error page of web server]: (default)
    Returns an error page that is set in the web server.
  • [Forwarded to another page]:
    You can forward to another JSP Web page.
  • Request can only be forwarded to either a JSP or an HTML.
  • Set JSP file under $DATASPIDER_HOME/server/system/kernel/modules/webcontainer/META-INF/catalina/webapps/dataspider.
Request settings Settings pertaining to HTTP request received  
Request settings/Encoding Select the encoding.
  • Defaults to 'UTF-8'
  • If you receive XML data or JSON data, the encoding specified is ignored.
    • If the any specification of encoding in the XML document is present, it will be used. Otherwise the encoding used defaults to UTF-8.
    • Treat JSON data as UTF-8.
Response settings Settings pertaining to HTTP response returned.
  • If the script executed on the HTTP trigger event fails,[Response settings] is disregarded and error will be returned accordingly to the settings in the [Action when exit abnormally]
Response settings/Encoding Specify the encoding used for the http response returned.
  • Defaults to 'UTF-8'
  • Encoding setting is disregarded when request is forwarded.
    Encoding needs to be specified in the JSP the request is forwarded.
Response settings/Content-Type Select the media type of the Content-Type
  • [Not specified]:
    The media type is determined by the content returned.
    text/html is used if the data is not XML.
    text/xml is used for XML data.
  • [text/html]:(default)
    text/html is used.
  • [text/xml]:
    text/xml is used.
  • [text/plain]:
    text/plain is used.
  • [text/csv]:
    text/csv is used.
  • [application/json]:
    application/json is used.
  • For more about the [text/csv] used, see CSV Output.
  • For more about the [application/json] used, see JSON Output.
Response settings/Output as file Select whether the response should be output as a file.
Response settings/Specify file name by trigger variables Select whether to specify file name to be output by trigger variables "trigger.file_name".
  • Enabled if [Response settings/Output as file]is checked.
Response settings/File name Enter the name of the file to be output.
  • Enabled if [Response settings/Output as file]is checked and [Response settings/Specify file name by trigger variables] is unchecked.
  • Multi-byte character is not supported.
Execution content settings
Item name Content Remarks
Trigger owner Select the owner of the trigger to be created.
  • Can only be selected by users with administrator privileges.
    (Ordinary users can select themselves only.)
Execution user name Select the user to run script specified by [Script].  
Password Type the password associated with the user specified by [Execution user name].  
Service Select the script to run by trigger.
  • Project that was registered as a service displays.
Script Select the script to run by trigger.
  • Script in the service specified by [Service] displays.
Script arguments script input variables that is set in script specified by [Script] displays
  • The script output variable does not display.
  • For details on how to set script input variables into script and to use, refer to "Input/output Variables".
Script arguments / Variable name Script variable name is displayed.
  • Can not be edited.
Script arguments / Type Script variable number type is displayed.
  • Can not be edited.
Script arguments / Value Enter a script variable value.
Script outputs Script output variables that is set in script specified in [Script] appears.
  • The script input variables does not display.
  • For details on how to set script output variables into script and to use, refer to "Input/output Variables".
Script outputs / Variable name Script variable name is displayed.
  • Can not be edited.
Script outputs / Type Script variable number type is displayed.
  • Can not be edited.
Script outputs / Value Enter a script variable value.
Execution option settings
For more information about Setting execution option, refer to "Execution option settings".

Trigger Variables

In HTTP trigger, you can retrieve information from the script to run.
In addition, this variable can also forward to JSP."HttpServletRequest.getAttribute (" variable name ")" can be obtained by JSP.

Trigger variable name Value Content Remarks
Input data trigger.inputData Formats to treat the request itself differ depending on the value of Content-Type header of request.
  • [text/xml] or [application/xml]:
    Treats request as XML format and stores in script input variable.
  • [application/json]:
    Treats request as JSON format and stores in script input variable.
  • Example: ${trigger.inputData}
  • The value can be stored only to an XML type input variable.
  • For how to treat JSON format data, refer to "Converting JSON Format Data".
Exit code trigger.exitStatus Exit status of Running script.
  • Example: ${trigger.exitStatus}
Message when exit abnormally trigger.failureMessage The error message string if the script fails to run.
  • Example: ${trigger.failureMessage}
Service name trigger.serviceName The service name of the script execution.
  • Example: ${trigger.serviceName}
  • For compatibility, trigger.projectName will also work.
Script name trigger.scriptName The script name of the script execution.
  • Example: ${trigger.scriptName}
Output data trigger.outputData If [Return page generated by script] is selected in [Action when executed successfully] the value dereferenced by this variable will be returned to the HTTP client.
  • Example:${trigger.outputData}
  • For compatibility, trigger.outputHtml will also work.
Client address trigger.client_address The IP address of the client which sent the request or the proxy server which connected.
  • Example:${trigger.client_address}
HTTP header trigger.header:<HTTP request header name> Stores the request header value specified in <HTTP request header name> to script input variable.
  • Example:${trigger.header:Content-Type}
  • Does not distinguish between upper and lower case of header name specifying to <HTTP request header name>.
  • If specified header does not exist in <HTTP request header name>, default value of script variable will be used.
  • If header specified in <HTTP request header name> exists multiply, the header value detected first will be stored.
trigger.header:<HTTP response header name> Adds the value of name specified in <HTTP response header name> and the value in variables to response header.
  • Example:${trigger.header:X-PRODUCT-NAME}
  • The following headers will be ignored despite specifying.
    • Content-Type
    • Content-Disposition
    • Content-Length
    • Transfer-Encoding
    • Date
    • Server
Status code trigger.status_code Set the value within this variable into response status code.
  • Example:${trigger.status_code}
  • For details on specifiable status codes, refer to "Response status code".
Output file name trigger.file_name Set the value within this variable into response file name.
  • Example:${trigger.file_name}
  • Multi-byte character is not supported.

How to set request parameters

For script Input variables of running script, you can set the request parameter value.

In the following script, the script input variable of type string "input" is defined.



You can set the value scripts input variable "input" dynamically.
For example: http://<Hostname or IP address of DataSpiderServer>:<Port number of DataSpiderServer>/dataspider/trigger/<path to run>?<script input variable name>=<value>

How to set multiple part form data

HTML formed value can be stored to the script input variable of execution script.

Example:In case the HTML form of multiple part form data is as follows.
<form method="post" action="<HTTP trigger URL>" enctype="multipart/form-data">
<p>First name<br>
<input type="text" name="firstname"></p>
<p>Last name<br>
<input type="text" name="lastname"></p>
<p>Profile picture<br>
<input type="file" name="attachment"></p>
<p><input type="submit" value="Send"></p>
</form>

Contents of the sent HTTP request body is as follows.
Content-Type: multipart/form-data; boundary=<boundary>

--<boundary>
Content-Disposition: form-data; name="firstname"

Ichiro

--<boundary>
Content-Disposition: form-data; name="lastname"

Suzuki

--<boundary>
Content-Disposition: form-data; name="attachment"; filename="profile.jpg"
Content-Type: image/jpeg

</data/profile.jpg data>

--<boundary>--

By performing script variable of same name as name attribute of HTML form input tag, script input variable will store values when script execution from HTTP trigger.
Also, if type attribute of HTML form input tag gets the contents of file uploaded from "file" parameter, variable type of script input variable specifies "Binary type".
If you are getting file name, define the script input variable of character string type as the name "<Parameter name>_filename".
Variable name Variable type
firstname Character string type
lastname Character string type
attachment Binary type
attachment_filename Character string type

CSV Output

When [text/csv] is specified in [Response settings/Content-Type], the value dereferenced by the trigger.outputData variable is used as follows:

JSON Output

If you specify [application/json] to [Response setting/Content-Type], data will be output as follows sue to the given data to trigger variable "trigger.outputData" variable.

File Output

If [Response settings/Output as file] is checked, the header values of the http response will be output as follows.
With this response general HTTP client downloads a file named the name specified in [Response settings/File name]. If [Specify file name by trigger variables] is checked, the file name will be what is passed to trigger variable "trigger.file_name".

Filed name Field value Example
Content-Type <media type>; name=<file name>;charset=<encoding>
Content-Type: text/csv; name=test.csv;charset=Shift_JIS
Content-Disposition attachment; fileName=<file name> Content-Disposition: attachment; filename=test.csv

Converting JSON Format Data

If Content-Type header of request is "application/json", data of request itself with JSON format will be converted into XML format following the below rules, and then stored to trigger variable "trigger.inputData" variable.
Also, when outputting data by specifing [application/json] to [Response settings/Content-Type], it will be converted into JSON format data, if XML format data given to trigger variable "trigger.outputData" variable follws the bellow rules.

<-- If root is JSON object of object type -->
<?xml version="1.0"?>
<root type="object">
  <JSON member name type="Attribute value that shows JSON type">value</JSON member name>
    :
</root>

<-- If root is JSON object of array type -->
<?xml version="1.0"?>
<root type="array">
  <element type="Attribute value that shows JSON type">value</element>
    :
</root>

<-- If JSON member name is false as XML element name -->
<?xml version="1.0"?>
<root type="object">
  <member type="Attribute value that shows JSON type" name="JSON member name">value</member>
    :
</root>
Element Name Attribute Name Description Remarks
root - Root element that wraps JSON object.  
type Sets attribute value that shows JSON type.
Attribute Value Description
object Shows JSON object type.

Example:JSON object that consists of object type
{"name":"Suzuki"}
Outputs the above JSON object example by converting into the following XML data.
<root type="object">
  <name type="string">Suzuki</name>
</root>
array Shows JSON array type.

Example:JSON object that consist of array type
["apple","grape","orange"]
Outputs the above JSON object example by converting into the following XML data.
<root type="array">
  <element type="string">apple</element>
  <element type="string">grape</element>
  <element type="string">orange</element>
</root>
 
JSON member name - Element showing JSON member.  
type Sets attribute value showing JSON type.
Attribute Value Description
string Shows JSON character string type.

Example:JSON member that has character string type value.
{"name":"Suzuki"}
Outputs the above JSON member example by converting into the following XML data.
<name type="string">Suzuki</name>
number Shows tha JSON numeric value type.

Example:JSON member that has numeric value type value.
{"age":37}
Outputs the above JSON member example by converting into the following XML data.
<age type="number">37</age>
boolean Shows boolean type of JSON.

Example:JSON member that has boolean type value.
{"success":true}
Outputs the above JSON member example by converting into the following XML data.
<success type="boolean">true</success>
object Shows object type of JSON.

Example:JSON member that has object type value.
{"name":{"first":"Ichiro","last":Suzuki"}}
Outputs the above JSON member example by converting into the following XML data.
<name type="object">
  <first type="string">Ichiro</first>
  <last type="string">Suzuki</last>
</name>
array Shows array type of JSON.

JSON array type element is showed as "element" element.
If JSON array type element is object type, XML data that has schema showing JSON object is output to child element of "element" element, and if other types, the value is output to element contents of "element" element.

Schema is as follows.
<JSON member name type="array">
  <element type="Attribute value showing JSON type">value</element>
    :
</JSON member name>

Example:JSON member that has array type value.
{"fruits":["apple","grape","orange"]}
Outputs the above JSON member example by converting into the following XML data.
<fruits type="array">
  <element type="string">apple</element>
  <element type="string">grape</element>
  <element type="string">orange</element>
</fruits>
null Shows null type of JSON.

Example:JSON member that has null type value.
{"name":null}
Outputs the above JSON member example by converting into the following XML data.
<name type="null"/>
 
element - Elment name that shows array type element.  
type Outputs the character string that shows JSON type.
Same attribute value as JSON member name type attribute will be set.
 
member - Element name that is used when the JSON member name is inappropreate as XML element name.  
type Character string that shows JSON type will be output.
Same attribute value as JSON member name type attribute will be set.
 
name Outputs JSON member name.

Example:JSON member that has inappropreate name as XML element name
{"1name":"Suzuki"}
Outputs the above JSON member example by converting into the following XML data.
<member type="string" name="1name">Suzuki</member>
 

Response status code

By using trigger variable "trigger.status_code", arbitrary status code can be set upon response. Specifiable status codes are as follows.
Status code Text phrase
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

Log Output

When received a request to the trigger execution URL, DataSpiderServer will output the IP address of the client you used for sending the request, or the IP address of the last proxy server to the server log if the trigger is enabled.
DataSpiderServer will only output those to log when the log level is set as "FINFO".

Specification limit

Main exceptions

Nothing.

Notes