Running a WebFOCUS Report

Topics:

This section provides code examples that demonstrate how to run the Sales_for_a_Specific_Country WebFOCUS report, which resides in the RESTful_Web_Services/Car_Reports folder. A successful sign-on request is a prerequisite for running this example, including retrieving the HTTP Header cookies from its response.

Visual Basic .NET Example

Imports System.Net
Imports System.IO
Imports System.Text
Dim request2 As HttpWebRequest
Dim response2 As HttpWebResponse
Dim webStream2 As Stream
Dim webResponse2 As String = ""
request2 = 
WebRequest.Create("http://localhost:8080/ibi_apps/rs/ibfs/WFC/Repository/
RESTful_Web_Services/Car_Reports/Sales_for_a_Specific_Country.fex")
request2.Method = "POST"
'cookies is defined as CookieContainer in the Signing-On to WebFOCUS example
request2.CookieContainer = cookies
postData = "IBIRS_action=run&COUNTRY=ENGLAND"
Dim byteArray2 As Byte() = Encoding.UTF8.GetBytes(postData)
request2.ContentType = "application/x-www-form-urlencoded"
request2.ContentLength = byteArray2.Length
Dim dataStream2 As Stream = request2.GetRequestStream()
dataStream2.Write(byteArray2, 0, byteArray2.Length)
dataStream2.Close()
response2 = request2.GetResponse()
webStream2 = response2.GetResponseStream()
Dim webStreamReader2 As New StreamReader(webStream2)
While webStreamReader2.Peek >= 0
    webResponse2 = webStreamReader2.ReadToEnd()
End While
WebBrowser1.DocumentText = webResponse2

Java Example

import java.awt.Frame;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import org.apache.commons.httpclient.*; 
import org.apache.commons.httpclient.methods.*;
String request2 = "http://localhost:8080/ibi_apps/rs/ibfs/WFC/Repository/RESTful_Web_
Services/Car_Reports/Sales_for_a_Specific_Country.fex";
			
PostMethod method_report = new PostMethod(request2);
			
method_report.addParameter("IBIRS_action","run");
method_report.addParameter("COUNTRY","ENGLAND");
// cookies is defined as Header[] in the Signing-On to WebFOCUS example			
for(int h=0; h<cookies.length; h++){
        System.out.println(cookies[h]);
        method_report.addRequestHeader(cookies[h].getName(), cookies[h].getValue());
}
								    
// client is defined as HttpClient in the Signing-On to WebFOCUS example
int statusCode2 = client.executeMethod(method_report);
InputStream rstream2 = null;
					    
rstream2 = method_report.getResponseBodyAsStream();
					    
File tempfile = new File("c:\\temp\\Report.htm");
FileOutputStream fos = new FileOutputStream(tempfile);
PrintWriter out=new PrintWriter(fos);
BufferedReader br2 = new BufferedReader(new InputStreamReader(rstream2));
String line2;
String newOutput = null;
			
while ((line2 = br2.readLine()) != null) {
	newOutput = line2;
	out.println(newOutput);
	System.out.println(line2);
}
br2.close();
out.close();

HTML and jQuery Example

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.js"> </script>
    <script type='text/javascript' src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/
jquery.xdomainrequest.min.js"></script>
    
    <script type="text/javascript">
        var csrf_name;
        var csrf_value;
        var frameToBeWorkedOn = "#AjaxPlaceHolder";
        var contentType = "application/x-www-form-urlencoded; charset=utf-8";
        $(document).ready(function (IBIRS_action, IBIRS_userName, IBIRS_password) {
            
            if (window.XDomainRequest)
                contentType = "text/plain";
            var webMethod = "http://machine:port/ibi_apps/rs";
            var IBIRS_action = "signOn";
            var IBIRS_userName = "admin";
            var IBIRS_password = "admin";
            var parameters = 'IBIRS_action=' + IBIRS_action + '&IBIRS_userName=' + IBIRS_userName + '&IBIRS_password=' + IBIRS_password;
            $.ajax({
                type: "POST",
                url: webMethod,
                data: parameters,
                dataType: "xml",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                contentType: contentType,
                success: xmlParser,
                error:function(jqXHR,textStatus,errorThrown)
                  {
                    alert("You can not send Cross Domain AJAX requests: " + errorThrown);
                  }
            })
        });
        function xmlParser(xml) {
            $(xml).find("entry").each(function () {
                if ($(this).attr("key") == "IBI_CSRF_Token_Name") {
                    csrf_name = $(this).attr("value");
                }
                if ($(this).attr("key") == "IBI_CSRF_Token_Value") {
                    csrf_value = $(this).attr("value");
                }
            });
            runReport();
        }
        function runReport() {
            if (window.XDomainRequest)
                contentType = "text/plain";
            var webMethod = "http://machine:port/ibi_apps/rs/ibfs/WFC/Repository/Tests/Revenue_by_Product_Category.fex";
            var IBIRS_action = "run";
            var BUSINESS_REGION = "'North America'";
            var BUSINESS_SUB_REGION = "'MidWest'";
            var parameters = 'IBIRS_action=' + IBIRS_action + '&BUSINESS_REGION=' + BUSINESS_REGION + '&BUSINESS_SUB_REGION=' + BUSINESS_SUB_REGION + '&' + csrf_name + '=' + csrf_value;
            $.ajax({
                type: "POST",
                url: webMethod,
                data: parameters,
                dataType: "html",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                contentType: contentType,
/*              success: alert("success"),    */
                complete: function(xhr,status) {
/*                  alert(xhr.responseText);  */
/*                  $("AjaxPlaceHolder".html(xhr.responseText));   */
                    document.AjaxPlaceHolder.document.body.innerHTML = xhr.responseText;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("You can not send Cross Domain AJAX requests: " + errorThrown);
                }
            })
        }
    </script>
</head>
<body>
    <iframe id="AjaxPlaceHolder" name="AjaxPlaceHolder" height="600" width="900" align="middle" style="position:absolute; top: 5px; left: 5px"></iframe>
</body>
</html>

WebFOCUS

Feedback