|
Topics: |
This section provides code examples that demonstrate how to run an On-Demand Paging report called ODP_Report.fex, which resides in the RESTful_Web_Services/Car_Reports folder.
The examples include:
The WebForm2 page can also be used as is to handle Drill-down and Active Cache paging requests.
The signOn page contains the RESTful Web Service request to run the initial WebFOCUS report. The IBIRS_clientPath parameter is set so that all additional RESTful Web Services requests needed, whether paging, image retrieval, or paging will be routed through the client application. For example:
IBIRS_clientPath=http://localhost:51970/WebForm2.aspx
signOn.aspx
Imports System.Net
Imports System.IO
Public Class signOn
Inherits System.Web.UI.Page
Dim cookies As New CookieContainer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim webStream As Stream
Dim webResponse As String = ""
Dim request As HttpWebRequest
Dim response1 As HttpWebResponse
Dim postData As String
request = WebRequest.Create("http://localhost.:8080/ibi_apps/rs/ibfs")
request.Method = "POST"
postData = "IBIRS_action=signOn&IBIRS_userName=admin&IBIRS_password=admin"
request.CookieContainer = cookies Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
response1 = request.GetResponse()
webStream = response1.GetResponseStream()
Dim request2 As HttpWebRequest
Dim response2 As HttpWebResponse
Dim webStream2 As Stream
Dim webResponse2 As String = ""
Dim uri As New System.Uri("http://localhost.:8080/ibi_apps/rs")
request2 = WebRequest.Create(uri)
request2.Method = "POST"
request2.CookieContainer = cookies
postData = "IBIRS_action=run" + _
"&IBIRS_clientPath=/WebForm2.aspx" + _
"&IBIRS_path=/WFC/Repository/RESTful_Web_Services/Car_Reports/ODP_Report.fex" + _
"&IBIRS_service=ibfs" + _
"&IBIRS_htmlPath=http://localhost:8080/ibi_apps/ibi_html"
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()
Dim i As Integer
Dim cookieArray As New CookieCollection
cookieArray = cookies.GetCookies(uri)
For i = 0 To cookies.Count - 1
Dim aCookie As New HttpCookie(cookieArray(i).Name)
aCookie.Value = cookieArray(i).Value
Response.Cookies.Add(aCookie)
Next i
webStream2 = response2.GetResponseStream()
Dim webStreamReader2 As New StreamReader(webStream2)
While webStreamReader2.Peek >= 0
webResponse2 = webStreamReader2.ReadToEnd()
End While
Response.Output.Write(webResponse2)
End Sub
End ClassWebForm2.aspx
Imports System.Net
Imports System.IO
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tDrillURL As String = Request.ServerVariables("QUERY_STRING")
Dim i As Integer
Dim qParm As String
Dim qValue As String
Dim IBIRS_path As String = ""
Dim Clicked_On As String = ""
Dim cookies As New CookieContainer
Dim request3 As HttpWebRequest
Dim response3 As HttpWebResponse
Dim webStream3 As Stream
Dim webResponse3 As String = ""
Dim getData As String
Dim uris As String = "http://localhost.:8080/ibi_apps/rs"
Dim uri As New System.Uri(uris)
getData = "http://localhost.:8080/ibi_apps/rs?" + _
tDrillURL + _
"&IBIRS_clientPath=/WebForm2.aspx" + _
"&IBIRS_htmlPath=http://localhost:8080/ibi_apps/ibi_html"
request3 = WebRequest.Create(getData)
request3.Method = "GET"
Dim j As Integer
For j = 0 To Request.Cookies.Count - 1
Dim rCookie As New System.Net.Cookie
rCookie.Name = Request.Cookies(j).Name
rCookie.Value = Request.Cookies(j).Value
cookies.Add(uri, rCookie)
Dim aCookie As New HttpCookie(Request.Cookies(j).Name)
aCookie.Value = Request.Cookies(j).Value
Response.Cookies.Add(aCookie)
Next j
request3.CookieContainer = cookies
response3 = request3.GetResponse()
webStream3 = response3.GetResponseStream()
Dim binaryReader3 As New BinaryReader(webStream3)
Dim readData() As Byte = Nothing
Dim byteArray() As Byte = Nothing
Dim byteStart As Integer = 0
Dim byteLength As Integer While (True)
readData = binaryReader3.ReadBytes(4096)
If (readData.Length = 0) Then
Exit While
End If
byteLength = readData.Length
ReDim Preserve byteArray(byteLength + byteStart - 1)
Array.Copy(readData, 0, byteArray, byteStart, byteLength)
byteStart = byteStart + byteLength
End While
Response.OutputStream.Write(byteArray, 0, byteArray.Length)
End Sub
End ClasssignOn.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="true"
import="
java.io.BufferedReader,
java.io.IOException,
java.io.InputStream,
java.io.InputStreamReader,
java.io.File,
java.io.FileOutputStream,
java.io.PrintWriter,
java.net.URI,
java.net.URISyntaxException,
org.apache.commons.httpclient.*,
org.apache.commons.httpclient.methods.*,
sax.xml.parser.SaxHandler,
javax.xml.parsers.ParserConfigurationException,
javax.xml.parsers.SAXParser,
javax.xml.parsers.SAXParserFactory,
org.xml.sax.SAXException
"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String request1 = "http://localhost:8080/ibi_apps/rs/ibfs";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(request1);
method.addParameter("IBIRS_action", "signOn");
method.addParameter("IBIRS_userName", "admin");
method.addParameter("IBIRS_password", "admin");
client.executeMethod(method);
Header[] cookies = null;
InputStream response1 = null;
response1 = method.getResponseBodyAsStream();
cookies = method.getResponseHeaders("Set-Cookie");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
SaxHandler handler = new SaxHandler();
parser.parse(response1, handler);
String csrfName = handler.getResults()[0].toString();
String csrfValue = handler.getResults()[1].toString();
// System.out.println("csrfName = " + csrfName);
// System.out.println("csrfValue = " + csrfValue);
String request2 = "http://localhost:8080/ibi_apps/rs";
PostMethod method_report = new PostMethod(request2);
method_report.addParameter("IBIRS_action","run");
method_report.addParameter("IBIRS_clientPath","/drillDownJSP/WebForm2.jsp");
method_report.addParameter("IBIRS_path","/EDA/EDASERVE/ibisamp/carinst.fex");
method_report.addParameter("IBIRS_service","ibfs");
method_report.addParameter("IBIRS_htmlPath","http://localhost:8080/ibi_apps/ibi_html");
method_report.addParameter(csrfName,csrfValue);
// 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());
String str = cookies[h].getName() + cookies[h].getValue();
//write cookie to a disk file and then read it back in the next JSP
String nameOfTextFile = "c:/temp/jsessionid.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
//clean up
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
}
method_report.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// client is defined as HttpClient in the Signing-On to WebFOCUS example
client.executeMethod(method_report);
InputStream response2 = null;
response2 = method_report.getResponseBodyAsStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(response2));
String line2;
String newOutput = null;
while ((line2 = br2.readLine()) != null) {
newOutput = line2;
out.println(newOutput);
// System.out.println(line2);
}
%>WebForm2.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="
java.io.BufferedReader,
java.io.IOException,
java.io.InputStream,
java.io.InputStreamReader,
java.io.File,
java.io.FileOutputStream,
java.io.PrintWriter,
java.io.FileReader,
java.net.URI,
java.net.URISyntaxException,
org.apache.commons.httpclient.*,
org.apache.commons.httpclient.methods.*,
sax.xml.parser.SaxHandler,
javax.xml.parsers.ParserConfigurationException,
javax.xml.parsers.SAXParser,
javax.xml.parsers.SAXParserFactory,
org.xml.sax.SAXException
"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String tDrillURL ="";
int i;
String qParm;
String qValue;
String IBIRS_path = "";
String Clicked_On = "";
Header[] cookies = null;
HttpClient client = new HttpClient();
tDrillURL = request.getQueryString();
// read saved cookie from text file
String txtFilePath = "c:/temp/jsessionid.txt";
BufferedReader reader = new BufferedReader(new FileReader(txtFilePath));
StringBuilder sb = new StringBuilder();
String line;
while((line = reader.readLine())!= null){
sb.append(line);
}
// System.out.println(sb.toString());
reader.close();
String request3 = "http://localhost:8080/ibi_apps/rs";
GetMethod method_report2 = new GetMethod(request3);
method_report2.setQueryString(tDrillURL);
method_report2.getParams().setParameter("IBIRS_clientPath", "/drillDownJSP/WebForm2.jsp");
method_report2.getParams().setParameter("IBIRS_htmlPath","http://localhost:8080/ibi_apps/ibi_html");
String cookie=sb.toString();
// System.out.println("webform2 cookie before replace " + cookie);
cookie = cookie.replace("Set-Cookie","");
// System.out.println("webform2 cookie after replace " + cookie);
method_report2.setRequestHeader("Cookie", cookie);
// }
method_report2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
int statusCode = client.executeMethod(method_report2);
System.out.println(statusCode);
InputStream response3 = null;
response3 = method_report2.getResponseBodyAsStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(response3));
String line3;
String newOutput = null;
while ((line3 = br2.readLine()) != null) {
newOutput = line3;
out.println(newOutput);
}
%>drillOne.html
<!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";
var IBIRS_action = "run";
var IBIRS_clientPath = "/src/drillTwo.html";
var IBIRS_path = "/EDA/EDASERVE/ibisamp/carinst.fex";
var IBIRS_service = "ibfs";
var IBIRS_htmlPath = "http://machine:port/ibi_apps/ibi_html";
var parameters = 'IBIRS_action=' + IBIRS_action + '&IBIRS_clientPath=' + IBIRS_clientPath + '&IBIRS_path=' + IBIRS_path
+ '&IBIRS_service=' + IBIRS_service + '&IBIRS_htmlPath=' + IBIRS_htmlPath + '&' + 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>drillTwo.html
<!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 frameToBeWorkedOn = "#AjaxPlaceHolder";
var contentType = "application/x-www-form-urlencoded; charset=utf-8";
var tDrillURLx = window.location.search;
var tDrillURL = tDrillURLx.slice(1);
$(document).ready(function () {
if (window.XDomainRequest)
contentType = "text/plain";
var webMethod = "http://machine:port/ibi_apps/rs";
var IBIRS_action = "get";
var IBIRS_clientPath = "/src/drillTwo.html";
var IBIRS_htmlPath = "http://machine:port/ibi_apps/ibi_html";
var parameters = tDrillURL + '&IBIRS_clientPath=' + IBIRS_clientPath + '&IBIRS_htmlPath=' + IBIRS_htmlPath;
$.ajax({
type: "GET",
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 |