-
Notifications
You must be signed in to change notification settings - Fork 0
/
regular-redirect.jsp
80 lines (71 loc) · 2.61 KB
/
regular-redirect.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<%@ page
import="java.util.*,
java.net.*,
java.io.*,
java.awt.Frame,
java.io.BufferedReader,
java.io.File,
java.io.FileOutputStream,
java.io.IOException,
java.io.InputStream,
java.io.InputStreamReader,
java.io.PrintWriter,
java.io.UnsupportedEncodingException,
java.nio.charset.StandardCharsets,
java.util.ArrayList,
org.apache.http.Header,
org.apache.http.HttpResponse,
org.apache.http.NameValuePair,
org.apache.http.client.*,
org.apache.http.client.entity.UrlEncodedFormEntity,
org.apache.http.client.methods.*,
org.apache.http.impl.client.CloseableHttpClient,
org.apache.http.impl.client.HttpClients,
org.apache.http.message.BasicNameValuePair,
org.apache.commons.io.IOUtils"%>
<%
/**
* Defines hostname, cookies[], client, which are pulled from logincheck.jsp to maintain the session
* Defines reportName by pulling it from the form block in regular-report.jsp
*/
String hostname = (String) session.getAttribute("hostname");
Header[] cookies = (Header[]) session.getAttribute("cookies");
CloseableHttpClient client = (CloseableHttpClient) session.getAttribute("client");
String reportName = request.getParameter("x");
/**
* Defines reportURL to access the reports, using the hostname and reportName
*/
String reportURL = "http://" + hostname + ".ibi.com:8080/ibi_apps/rs?IBIRS_path=WFC/Repository/Public/"
+ reportName + "&IBIRS_action=run&IBIRS_service=ibfs";
/**
* getReport is defined to send the get request using reportURL
*/
HttpGet getReport = new HttpGet(reportURL);
/**
* For loop attaches the cookies to the get request
*/
for (int h = 0; h < cookies.length; h++) {
getReport.addHeader(cookies[h].getName(), cookies[h].getValue());
}
/**
* Defines HttpResponse and replaceString outside the try block
*/
HttpResponse httpResponse = null;
String replacedString = "";
/**
* httpResponse is set to execute getReport
* Gets status code for possible error message
*/
try {
httpResponse = client.execute(getReport);
int statusCode = httpResponse.getStatusLine().getStatusCode();
String result = IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8);
replacedString = result.replace("/ibi_apps/", "http://" + hostname + ".ibi.com:8080/ibi_apps/");
} catch (Exception ex) {
System.out.println("HttpResponse Error: " + ex.getMessage());
}
/**
* Sends the report back to the iFrame
*/
%>
<%=replacedString%>