Version

    Data Service HTTP Library Functions

    addResponseHeader

    void addResponseHeader( string name, string value  );

    The addResponseHeader function adds an HTTP response header field. If the fuction is called multiple times, multiple headers will be added.

    The name parameter is a header field name. See list of header field names.

    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.

    Compatibility

    The addResponseHeader(string,string) function is available since CloverETL 4.7.0-M1.

    Example 383. Usage of addResponseHeader

    The addResponseHeader("Content-Language", "fr") adds an HTTP header field Content-Language with value fr

    Content-Language: fr

    The addResponseHeader("foo", "") adds header field with empty value

    foo:

    The addResponseHeder("foo", null) does not add an HTTP header field because of null.

    containsResponseHeader

    boolean containsResponseHeader( string headerField );

    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.

    Compatibility

    The containsResponseHeader(string) function is available since CloverETL 4.7.0-M1.

    Example 384. 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.

    setResponseHeader("Content-Language", "fr");
    boolean a = containsResponseHeader("Content-Language"); // true

     

    The containsResponseHeader("Server") returns false. The header was not added by user.

    See also: addResponseHeader

    getRequestBody

    string getRequestBody(  );

    The getRequestBody() function returns the request body.

    Compatibility

    The getRequestBody() function is available since CloverETL 4.7.0-M1.

    Example 385. Usage of getRequestBody

    If you query the data service with

    wget \
        --user=userName \
        --password=password \
        --method=POST \
        --body-data="Once upon a time" \
        "http://${HOST_PORT}/clover/data-service/getRequestBody"

    the getRequestBody() returns Once upon a time.

    See also: getRequestEncoding

    getRequestClientIPAddress

    string getRequestClientIPAddress(  );

    The getRequestClientIPAddress() function returns the IP address of client performing the request.

    Compatibility

    The getRequestClientIPAddress() function is available since CloverETL 4.7.0-M1.

    Example 386. Usage of getRequestClientIPAddress
    If you run the CloverDX 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

    getRequestContentType

    string getRequestContentType(  );

    The getRequestContentType() function returns the content type.

    Compatibility

    The getRequestContentType() function is available since CloverETL 4.7.0-M1.

    Example 387. Usage of getRequestContentType

    If you query the data service API with

     wget \
        --user=... \
        --password=... \
        --method=POST \
        --body-data="Once upon a time" \
        "http://${HOST_PORT}/clover/data-service/getRequestContentType"

    the getRequestContentType() returns application/x-www-form-urlencoded.

    getRequestEncoding

    string getRequestEncoding(  );

    The getRequestEncoding() function encoding specified in Content-Type header.

    If the header does not exist, the function returns null.

    Compatibility

    The getRequestEncoding() function is available since CloverETL 4.7.0-M1.

    Example 388. Usage of getRequestEncoding

    If you query the data with

    wget \
        --user=... \
        --password=... \
        --header="Content-Type: text/html; charset=UTF-8" \
        "http://${HOST_PORT}/clover/data-service/getRequestEncoding"

    the getRequestEncoding() function returns UTF-8.

    See also: setRequestEncoding

    getRequestHeader

    string getRequestHeader( string headerField );

    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.

    Compatibility

    The function getRequestHeader(string) is available since CloverETL 4.7.0-M1.

    Example 389. Usage of getRequestHeader

    If you query the service with

    wget \
        --user=... \
        --password=... \
        --header="Accept-Language: de" \
        "http://${HOST_PORT}/clover/data-service/getRequestHeader"

    the getRequestHeader("Accept-Language") returns de.

    getRequestHeaderNames

    string[] getRequestHeaderNames(  );

    The getRequestHeaderNames() function returns names of request header fields.

    Compatibility

    The function getRequestHeaderNames() was introduced in CloverETL 4.7.0-M1.

    Example 390. Usage of getRequestHeaderNames

    If the data service receives

    GET /clover/data-service/getRequestHeaderNames HTTP/1.1
    User-Agent: Wget/1.19.1 (cygwin)
    Accept: */*
    Accept-Encoding: identity
    Host: 172.22.2.71:33754
    Connection: Keep-Alive
    Accept-Language: es
    Authorization: Basic Y2xvdmVyOmNsb3Zlcg==
    Cookie: JSESSIONID=AE6A63EA112A0BADD046CDE0D068DCC1

    The getRequestHeaderNames() function returns user-agent,accept,accept-encoding,host,connection,accept-language,authorization,cookie (as a list of strings).

    getRequestHeaders

    map[string,string] getRequestHeaders(  );
    string[] getRequestHeaders( string param );

    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.

    Compatibility

    The function getRequestHeaders() is available since CloverETL 4.7.0-M1.

    Example 391. Usage of getRequestHeaders

    If you query the data service with>

    curl.exe \
        --user clover:clover \
        --header "Accept-Language: de, en, es, fr" \
        --header "Accept: text/plain" \
        --header "Accept: text/html" \
        --header "Accept: application/xml" \
        --header "Accept: application/json" \
        http://${HOST_PORT}/clover/data-service/getRequestHeaders

    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.

    getRequestMethod

    string getRequestMethod(  );

    The getRequestMethod() function returns the HTTP method: GET, POST, PUT, PATCH or DELETE.

    Compatibility

    The function getRequestMethod() was introduced in CloverETL 4.7.0-M1.

    Example 392. Usage of getRequestMethod

    If you query the data service with:

    wget \
        --user=clover \
        --password=clover \
        --method=GET \
        "http://${HOST_PORT}/clover/data-service/getRequestMethod"

    the getRequestMethod() returns GET.

    getRequestParameter

    string getRequestParameter( string param );

    The getRequestParameter() function returns value of GET or POST parameter.

    The param parameter is the parameter name.

    Compatibility

    The function getRequestParameters() was introduced in CloverETL 4.7.0-M1.

    Example 393. Usage of getRequestParameter

    If you query the data service with:

    wget \
        --user=clover \
        --password=clover \
        "http://${HOST_PORT}/clover/data-service/getRequestParameter?id=1234&"

    the getRequestParameter("id") returns 1234 (as string).

    If you query data service on .../getRequestParameter/id/{id} URL with

    wget \
        --user=clover \
        --password=clover \
        "http://${HOST_PORT}/clover/data-service/getRequestParameter/id/123"

    the getRequestParameter("id") returns 123 (as string). Note parameters in the URL in data service configuration.

    If you query data service with

    wget \
        --user=clover \
        --password=clover \
        --post-data "id=234&" \
        "http://${HOST_PORT}/clover/data-service/getRequestParameter"

    the getRequestParameter("id") returns 234 (as string).

    getRequestParameterNames

    string[] getRequestParameterNames(  );

    The getRequestParameterNames() function returns names of GET or POST parameters., e.g. http://example.com/?id=123&

    Compatibility

    The function getRequestParameternames() was introduced in CloverETL 4.7.0-M1.

    Example 394. Usage of getRequestParameterNames

    If you query the data service with:

    wget \
        --user=clover \
        --password=clover \
        "http://${HOST_PORT}/clover/data-service/getRequestParameterNames?id=123&name=doe&"

    the getRequestParameterNames() returns list containing id and name.

    If you query data service on /getRequestParameterNames2/id/{id}/name/{name} with:

    wget \
        --user=clover \
        --password=clover \
        "http://${HOST_PORT}/clover/data-service/getRequestParameterNames2/id/123/name/doe"

    the getRequestParameterNames() function returns list containing id and name.

    If you query data service with:

    wget \
        --user=clover \
        --password=clover \
        --post-data "name=doe&" \
        "http://${HOST_PORT}/clover/data-service/getRequestParameterNames3?id=234&"

    the getRequestParameterNames() returns list containing id and name.

    getRequestParameters

    string[] getRequestParameters( string name );
    map[string,string] getRequestParameters(  );

    The getRequestParameters() function return map of GET or POST request parameters and request parameter values. The parameters are from URL: www.example.com/getRequestParameters?id=123&name=doe&name=john&

    The name parameter is name of the parameter.

    Compatibility

    The function getRequestParameters() was introduced in CloverETL 4.7.0-M1.

    Example 395. Usage of getRequestParameters

    If you query data service with:

    wget \
        --user=clover \
        --password=clover \
        "http://${HOST_PORT}/clover/data-service/getReqPar?id=123&name=doe&name=john&"

    The getRequestParameters() returns map. The key is parameter name, the value is the parameter value.

    The getRequestParameters("name") returns list containing doe and john.

    getRequestPartFilename

    string getRequestPartFilename( string paramName );

    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.

    Compatibility

    The function getRequestPartFileName(string) is available since CloverETL 4.7.0-M1.

    Example 396. Usage of getRequestPartFilename

    If you query the web service with:

    curl -F name=@/tmp/filename \
        http://example.com:8080/clover/data-service/getRequestPartFilename \
        --user clover:clover

    the getRequestPartFilename("name") returns somefile.

    getResponseContentType

    string getResponseContentType(  );

    The getResponseContentType() function retuns response content type - the value of Content-Type response header field.

    Compatibility

    The function getResponseContentType() is available since CloverETL 4.7.0-M1.

    Example 397. Usage of getResponseContentType
    The getResponseContentType() returns for example application/json.

    getResponseEncoding

    string getResponseEncoding(  );

    The getResponseEncoding() function returns the response encoding.

    Compatibility

    The function getResponseEncoding() is available since CloverETL 4.7.0-M1.

    Example 398. Usage of getResponseEncoding
    E.g. the getResponseEncoding() returns iso-8859-1.

    setRequestEncoding

    void setRequestEncoding( string encoding );

    The setRequestEncoding() function sets the encoding to be used in POST request parsing. Call this function in init().

    The encoding parameter is encoding.

    Compatibility

    The function setRequestEncoding(string) is available since CloverETL 4.7.0-M1.

    Example 399. 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

    setResponseBody

    void setResponseBody( string body );

    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.

    Compatibility

    The function setResponseBody(string) is available since CloverETL 4.7.0-M1.

    Example 400. Usage of getResponseBody
    The setResponseBody("The response") sets the response body.

    setResponseContentType

    void setResponseContentType( string contentType );

    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.

    Compatibility

    The function setResponseContentType(string) is available since CloverETL 4.7.0-M1.

    Example 401. Usage of setResponseContentType
    setResponseContentType("text/plain");

    setResponseEncoding

    void setResponseEncoding( string encoding );

    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.

    Compatibility

    The function setResponseEncoding(string) is available since CloverETL 4.7.0-M1.

    Example 402. Usage of setResponseEncoding
    The setResponseEncoding("UTF-8"); sets response body encoding to UTF-8.

    setResponseHeader

    void setResponseHeader( string field, string value );

    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.

    Compatibility

    The function setResponseHeader(string,string) is available since CloverETL 4.7.0-M1.

    Example 403. Usage of setResponseHeader
    setResponseHeader("Server", "BOA")

    See also: addResponseHeader

    setResponseStatus

    void setResponseStatus( integer statusCode );
    void setResponseStatus( integer statusCode, string message );

    The setResponseStatus() function sets the response status code.

    The statusCode parameter is the returned status code.

    The message parameter is a message.

    Compatibility

    The setResponseStatus(string,string) is availables since CloverETL 4.7.0-M1.

    Example 404. Usage of setResponseStatus

    The setResponseStatus(403) sets the response status to 403.

     

    The setResponseStatus(414, "URI Too Long") returns a status code 414.

    HTTP/1.1 414 URI Too Long