Bypassing Cloudflare's Time-out Of 100 Seconds
Solution 1:
In case anyone else has the same problem, I am posting how I finally got this working. I gave up trying to use AJAX to run the report, but instead ran the report via a Thread, but used AJAX to "poll" to check if the report had been created. What I did was basically as follows.
Note that I stripped a lot out of my code, e.g. security routines and error checking routines, just to give the basic framework.
I created a java class called ThreadMyReport
publicclassThreadMyReportimplementsRunnable {
String fileID = "";
Date dateOfReport = null;
publicThreadMyReport(Date dateOfReport) {
this.fileID= "MyReport_" + UUID.randomUUID();
this.dateOfReport = dateOfReport;
}
publicvoidrun() {
int a = ReportMyReport.loadAndSaveMyReport(dateOfReport, fileID);
}
publicStringgetFileID() {
return fileID;
}
}
All my original code to generate the report is found in ReportMyReport.loadAndSaveMyReport. When the report is finished, then it saves a file with fileName fileID on the server.
I then started a thread going to run the report
ThreadMyReporta=newThreadMyReport(theDate);
Thread theThread=newThread(a);
theThread.start();
fileID=a.getFileID();
I then added a javascript routine to check via AJAX every second whether the file had been created, and if it had been created then to display the report.
<SCRIPTlanguage="javascript">var myVar;
myVar=setInterval(function (){
$.post("post/post_checkReportReady_xml.jsp", {
generatedReport: '<%=fileID%>'
}, function(data) {
if (data.indexOf("produced")>-1) {
clearInterval(myVar);
//display report
}
if (data.indexOf("failed")>-1) {
clearInterval(myVar);
}
});
}, 1000);
</SCRIPT>
The AJAX code looks like this:
<%
String result="";
String generatedReport=(request.getParameter("generatedReport"));
if(!"".equals(generatedReport)) {
String fileName2="My directory/"+generatedReport+".xlsm";
java.io.File f = new java.io.File(fileName2);
if(f.exists()) {
result="produced";
}
}
}
%>
<%=result%>
Solution 2:
Since cloudflare does not cache html or xhr, you can greycloud a subdomain but on the server use that as an alias. For example...
In CloudFlare dns:
- www 123.123.123.123 = orange (protected)
- ajax 123.123.123.123 = grey (dns only)
In your website control panel add ajax.mydomain.com as an alias.
Finally, in your code use the fqdn that hits your server bypassing cloudflare.
functionajaxReport() {
var seconds = prompt("Please enter how many seconds you want the report to run", "5");
$('#imgWaiting').show();
$.post("//ajax.mydomain.com/post/post_ajaxReport.jsp",
{
theParam:seconds
},function(data) {
$('#imgWaiting').hide();
window.location=data;
});
}
This does expose your IP address. But there should be little to no performance penalty, depending on the content returned.
Post a Comment for "Bypassing Cloudflare's Time-out Of 100 Seconds"