%-- CSARedirect.jsp --%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.util.Date" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.net.URLEncoder" %>
<%
String cookieName = "ORA_SMP_CSA";
String cookieValue = "";
Cookie[] cookies = request.getCookies();
Cookie aCookie = null;
int nCookies = ((cookies == null) ? 0 : cookies.length);
int ii;
int csaCookieCnt = 0;
// String serverName = request.getServerName();
// int snLen = 0;
int idx = 0;
// Setup formatted timestamp string for use as part of cookieValue ...
// Date currDate = new Date();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd H:mm:ss (z)");
// String ts = sdf.format(currDate);
// StringBuffer cvBuff = new StringBuffer(100); // for new cookie value
long currTS = System.currentTimeMillis();
// String msec = new String().valueOf(currTS);
long prevTS = 0; // for an existing cookie, if any
long cookieAge = -1; // diff between prevTS and currTS (in msec)
long execInterval = -1;
String execIntString = "";
// Define defaults for several cookie attributes, etc, and then
// determine if any non-default values are provided ...
// int cookieMaxAge = 600*1; // default is 60 seconds
// String cookiePath = request.getParameter("path");
// String cookieDomain = request.getParameter("domain");
// String currPath = ""; // for an existing cookie, if any
boolean reDirect = false; //this flag indicates whether or not we should
//redirect
//if there is a redirection config file present, we should read it
String configPath = "./CSARedirect.config";
String csaURL = "";
String resultURL = "";
int UIMode = 0;
int idxEq = 0;
int idxLb = 0;
System.out.println("AKS: hello from CSARedirect!");
String reqPath = "";
String realPath = application.getRealPath("");
String servletPath = request.getServletPath();
int idxLastDot = 0;
if ((realPath != null) && !realPath.equals("")
&& (servletPath != null) && !servletPath.equals(""))
{
reqPath = realPath + servletPath;
}
if ((reqPath != null) && !reqPath.equals("") // verify reqPath defined
&& ((idxLastDot = reqPath.lastIndexOf("/")) > 0))
{
try {
configPath = reqPath.substring(0, idxLastDot + 1) + "CSARedirect.config";
System.out.println("configPath is " + configPath);
System.out.println("reqpath is " + reqPath);
File configFile = new File(configPath);
if(configFile.exists()) {
System.out.println("config file exists");
BufferedReader in =
new BufferedReader(new FileReader(configPath));
String line;
while((line = in.readLine()) != null) {
if(!line.trim().startsWith("#")) {
idxEq = line.indexOf("=");
idxLb = line.indexOf("#");
String keyString = "";
String valString = "";
// Allow for trailing comments (ie starting with #) ...
if (idxLb > idxEq)
{
keyString = line.substring(0, idxEq).trim();
valString = line.substring(idxEq+1, idxLb).trim();
}
else // no trailing comment
{
keyString = line.substring(0, idxEq).trim();
valString = line.substring(idxEq+1).trim();
}
if((keyString != null) && !(keyString.equals(""))) {
session.setAttribute(keyString, valString);
}
}
}
in.close();
}
}
catch (Exception e) {}
}
//now see if we can get values for csaURL, resultURL, and execInterval
csaURL = (String)session.getAttribute("csaURL");
resultURL = (String)session.getAttribute("resultURL");
execIntString = (String)session.getAttribute("execInterval");
String UIModeString = (String)session.getAttribute("UIMode");
try {
UIMode = Integer.parseInt(UIModeString);
}
catch (Exception e) {}
try {
execInterval = Long.parseLong(execIntString);
}
catch (Exception e) {}
int numCSACookies = 0;
for (ii = 0; ii < nCookies; ii++) {
aCookie = cookies[ii];
if(aCookie.getName().equals(cookieName)) {
numCSACookies++;
cookieValue = aCookie.getValue();
idx = cookieValue.indexOf("|");
if (idx > 0) {
try
{
prevTS = Long.parseLong(cookieValue.substring(0, idx));
if(execInterval != -1) {
execInterval =
Long.parseLong(cookieValue.substring(idx + 1));
}
cookieAge = currTS - prevTS;
}
catch (Exception e) {
//if there was an exception parsing the timestamp,
//we should re-direct so that the CSA page can set a new cookie
reDirect = true;
}
}
}
}
System.out.println("cookieage is " + cookieAge);
System.out.println("execInterval is " + execInterval);
if(((csaURL != null) && !(csaURL.equals("")))
&& ((cookieAge > (execInterval * 1000)) || (numCSACookies == 0)))
{
reDirect = true;
}
if((resultURL != null) && !(resultURL.equals(""))) {
csaURL = csaURL + "?appURL=" + URLEncoder.encode(resultURL);
System.out.println("csaURL is " + csaURL);
}
if(true) {
if(UIMode == 0) {
response.sendRedirect(csaURL);
}
else {
if(UIMode == 1) {
%> <%
}
}
}
%>