Show contents 

Web Service > Web Service Operations > Additional Operations > CustomRequestHandler

CustomRequestHandler

Syntax

<web service URL>/CustomRequestHandler?mon=<Unit moniker>&method=<Method/function name>

Description

The CustomRequestHandler operation is used to execute Fore function using POST request.

Comments

Operation parameters contain unit moniker and name of the executed Fore method/function. The moniker is specified in the following format: <moniker of opened connection>!<unit key>. The method/function should contain a string parameter, via which the sent POST request will be sent via Fore. The required condition of successful execution is sending the do_rest_through_post header with the 1 value. The further handling of POST request should be executed in the application Fore code. The function execution result will be returned as a response to POST request.

Example

Below is the example of code of the HTML page used for Fore function execution using the CustomRequestHandler operation. Unit key and function name are determined in the objKey and methodName variables, respectively. Simple code of the function that can be used to get the sent request:

Function TestReceive(Value: String): String;
Begin
    Return "Created request: " + Value;
End Function TestReceive;

When the code is executed, the HTML page text displays sent requests and their execution results: response obtained from BI server or error code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Use of the CustomRequestHandler operation</title>
</head>
<body>
    <script type="text/javascript">
        var svc = "http://localhost:9090/axis2/services/PP.SOM.Som";
        var objKey = 390432;
        var methodName = "TestReceive";
        // Execute CustomRequestHandler
        CustomRequestHandler();
        // Connect to repository and send request for the CustomRequestHandler operation execution
        function CustomRequestHandler() {
            OpenMetabase = { "OpenMetabase": { "tDef": { "id": "Warehouse" }, "tCreds": { "user": { "id": "User" }, "pass": "Password" } } }
            // Repository connection
            moniker = PostRequest(svc, OpenMetabase).OpenMetabaseResult.id;
            // Execute Fore function on server
            PostRequest(svc + "/CustomRequestHandler?mon=" + moniker +"!"+ objKey + "&method=" + methodName, "Test Request Body", true);
            // Close repository connection
            CloseMetabase = { "CloseMetabase": { "tMb": {"id": moniker} } }
            PostRequest(svc, CloseMetabase)
        }
        // Send requests
        function PostRequest(url, request, custom_handler = false) {
            document.writeln("<hr>Request:<p>" + JSON.stringify(request) + "<p>");
            <!--Send request-->
            var xhr = new XMLHttpRequest();
            if (custom_handler)
            {
                xhr.open("POST", url, false);
                xhr.setRequestHeader('do_rest_through_post', 1);
            }
            else
                xhr.open("POST", url, false);
            xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
            xhr.send(JSON.stringify(request));
            if (xhr.status == 200) {
                document.writeln("Response:<p>"  + xhr.responseText + "<p>");
                return eval("(" + xhr.responseText + ")");
            } else {
                document.writeln("Error executing request:<p>" + xhr.responseText + "<p>");
                return { "error" : true };
            }
        }
    </script>
</body>
</html>

See also:

Additional Operations