Functions from Data Service HTTP Library are available in context of Data API jobs.
The addResponseHeader
function adds an HTTP response header field. If the function is called multiple times, multiple headers will be added.
The name
parameter is a header field name. See .
If name
is null
or empty string, the response header field is not added.
The value
parameter is a value of the header field. If value
is empty string, empty string is used. If value
is null the header field is not added.
Example 343. Usage of addResponseHeader
The addResponseHeader("Content-Language", "fr")
adds an HTTP header field Content-Language
with value fr
.
The addResponseHeader("foo", "")
adds header field with empty value
The addResponseHeder("foo", null)
does not add an HTTP header field because of null
.
See also:
The containsResponseHeader()
function checks for presence of a user-added header field. It does not check existence of header fields not added by user, e.g. Server: Apache-Coyote/1.1
. The check is case insensitive.
The headerField
parameter is a name of HTTP header field.
Example 344. Usage of containsResponseHeader
There is no Content-Language
header. The containsResponseHeader("Content-Language")
returns false
.
If the header was added by setResponseHeader()
function. The function containsResponseHeader()
returns true
.
The containsResponseHeader("Server")
returns false
. The header was not added by user.
See also: addResponseHeader
The getRequestBody()
function returns the request body.
Example 345. Usage of getRequestBody If you query the data service with
the getRequestBody()
returns Once upon a time.
See also: getRequestEncoding
The getRequestClientIPAddress()
function returns the IP address of client performing the request.
Example 346. Usage of getRequestClientIPAddress
If you run the Data Shaper Server locally, the getRequestClientIPAddress()
returns IP address corresponding to localhost: "127.0.0.1"
or "0:0:0:0:0:0:0:1"
.
See also: getRequestBody
The getRequestContentType()
function returns the content type.
Example 347. Usage of getRequestContentType If you query the data service API with
the getRequestContentType()
returns application/x-www-form-urlencoded
.
See also: getResponseContentType
The getRequestEncoding()
function encoding specified in Content-Type header.
If the header does not exist, the function returns null
.
Example 348. Usage of getRequestEncoding If you query the data with
the getRequestEncoding()
function returns UTF-8
.
See also: setRequestEncoding
The getRequestHeader()
function returns value of the header field.
The headerField
parameter is HTTP header field name.
If the header field does not exist, the function returns null
.
Example 349. Usage of getRequestHeader If you query the service with
the getRequestHeader("Accept-Language")
returns de
.
See also: getRequestHeaderNames
The getRequestHeaderNames()
function returns names of request header fields.
Example 350. Usage of getRequestHeaderNames If the data service receives
The getRequestHeaderNames()
function returns user-agent,accept,accept-encoding,host,connection,accept-language,authorization,cookie
(as a list of strings).
See also: getRequestHeader, getRequestHeaders
The getRequestHeaders()
function returns a map with request headers. The header name is a key, header field value is value.
The param
parameter is header field name.
Example 351. Usage of getRequestHeaders If you query the data service with:
the getRequestHeaders()
function returns map with key-value pairs:
User-Agent=curl/7.54.1;Accept=application/json;Accept-Language=de, en, es, fr;…​.
As the function does not return a multimap, the Accept header field contains only one of the received header fields values. To get all received header field values, use the getRequestHeaders(string)
function.
The getRequestHeaders("Accept")
function returns list of strings: text/plain;text/html;application/xml;application/json.
See also: getRequestHeader, getRequestHeaderNames
The getRequestMethod()
function returns the HTTP method: GET, POST, PUT, PATCH or DELETE.
Example 352. Usage of getRequestMethod If you query the data service with:
the getRequestMethod()
returns GET
.
The getRequestParameter()
function returns value of GET or POST parameter.
The param
parameter is the parameter name.
Example 353. Usage of getRequestParameter If you query the data service with:
the getRequestParameter("id")
returns 1234
(as string).
If you query data service on .../getRequestParameter/id/{id}
URL with
the getRequestParameter("id")
returns 123
(as string). Note parameters in the URL in data service configuration.
If you query data service with
the getRequestParameter("id")
returns 234
(as string).
See also: getRequestParameters, getRequestParameterNames
Example 354. Usage of getRequestParameterNames If you query the data service with:
the getRequestParameterNames()
returns list containing id
and name
.
If you query data service on ./getRequestParameterNames2/id/{id}/name/{name}
with:
the getRequestParameterNames()
function returns list containing id
and name
.
If you query data service with:
the getRequestParameterNames()
returns list containing id
and name
.
See also: getRequestParameter, getRequestParameters
Example 355. Usage of getRequestParameters If you query data service with:
The getRequestParameters()
returns map. The key is parameter name, the value is the parameter value.
The getRequestParameters("name")
returns list containing doe
and john
.
See also: getRequestParameter, getRequestParameterNames
The getRequestPartFilename()
function returns name of file received in multipart entity. Usually, it is a file name from HTML form.
The paramName
parameter is name of HTML input field containing the file.
Example 356. Usage of getRequestPartFilename If you query the web service with:
the getRequestPartFilename("name")
returns somefile
.
The getResponseContentType()
function returns response content type - the value of Content-Type
response header field.
Example 357. Usage of getResponseContentType
The getResponseContentType()
returns for example application/json
.
See also: getRequestContentType, setResponseContentType
The getResponseEncoding()
function returns the response encoding.
Example 358. Usage of getResponseEncoding
E.g. the getResponseEncoding()
returns iso-8859-1
.
See also: getRequestEncoding, setResponseEncoding
The setRequestEncoding()
function sets the encoding to be used in POST request parsing. Call this function in init()
.
The encoding
parameter is encoding.
Example 359. Usage of setRequestEncoding
The setRequestEncoding("utf-8")
sets request encoding to UTF-8.
The setRequestEncoding("iso-8859-2")
sets request encoding to latin2.
The setRequestEncoding("cp1250")
sets request encoding to code page 1250.
See also: getRequestEncoding
The setResponseBody()
function sets HTTP response body. Consider setting the response body encoding explicitly.
The body
parameter is the content of the body.
If you try to create response body with setResponsebody()
function and with writing to response:body
, the later one will be used. You should use only one way to create the response body.
Example 360. Usage of getResponseBody
The setResponseBody("The response")
sets the response body.
See also: setResponseEncoding
The setResponseContentType()
function sets the response content type - the value of Content-Type
response header field.
The contentType
parameter is the value of Content-Type
response header field.
Example 361. Usage of setResponseContentType
setResponseContentType("text/plain");
See also: setResponseBody, getResponseContentType
The setResponseEncoding()
function sets HTTP response encoding. This encoding is used if you set the response body with the setResponseBody()
function.
The encoding parameter is the response body encoding.
Example 362. Usage of setResponseEncoding
The setResponseEncoding("UTF-8")
; sets response body encoding to UTF-8.
See also: getResponseEncoding, setResponseBody
The setResponseHeader()
function sets the response header. If the header does not exist, it will be created.
The field
parameter is HTTP header field name.
The value
parameter is HTTP header field value.
Example 363. Usage of setResponseHeader
setResponseHeader("Server", "BOA")
See also: addResponseHeader
The setResponseStatus()
function sets the response status code.
The statusCode
parameter is the returned status code.
The message
parameter is a message.
Example 364. Usage of setResponseStatus
The setResponseStatus(403)
sets the response status to 403.
The setResponseStatus(414, "URI Too Long")
returns a status code 414.
The getRequestParameterNames()
function returns names of GET or POST parameters., e.g.
The getRequestParameters()
function return map of GET or POST request parameters and request parameter values. The parameters are from URL:
The name
parameter is name of the parameter.
See also: ,