|
|
|
@ -165,8 +165,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
|
|
|
|
|
private static HashSet loadSet(String setname, String filename) {
|
|
|
|
|
HashSet set = new HashSet();
|
|
|
|
|
BufferedReader br = null;
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
|
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
|
line = line.trim();
|
|
|
|
@ -174,14 +175,18 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
}
|
|
|
|
|
br.close();
|
|
|
|
|
serverLog.logInfo("PROXY", "read " + setname + " set from file " + filename);
|
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
} finally {
|
|
|
|
|
if (br != null) try { br.close(); } catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
return set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static TreeMap loadMap(String mapname, String filename, String sep) {
|
|
|
|
|
TreeMap map = new TreeMap();
|
|
|
|
|
BufferedReader br = null;
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
|
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
|
|
|
|
|
String line;
|
|
|
|
|
int pos;
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
@ -189,9 +194,11 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
if ((line.length() > 0) && (!(line.startsWith("#"))) && ((pos = line.indexOf(sep)) > 0))
|
|
|
|
|
map.put(line.substring(0, pos).trim().toLowerCase(), line.substring(pos + sep.length()).trim());
|
|
|
|
|
}
|
|
|
|
|
br.close();
|
|
|
|
|
serverLog.logInfo("PROXY", "read " + mapname + " map from file " + filename);
|
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
} finally {
|
|
|
|
|
if (br != null) try { br.close(); } catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -200,7 +207,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
if (switchboard == null) return map; // not initialized yet
|
|
|
|
|
File listsPath = new File(switchboard.getRootPath(), switchboard.getConfig("listsPath", "DATA/LISTS"));
|
|
|
|
|
String filenamesarray[] = filenames.split(",");
|
|
|
|
|
String filename = "";
|
|
|
|
|
|
|
|
|
|
if(filenamesarray.length >0)
|
|
|
|
|
for(int i = 0; i < filenamesarray.length; i++)
|
|
|
|
|
map.putAll(loadMap(mapname, (new File(listsPath, filenamesarray[i])).toString(), sep));
|
|
|
|
@ -445,11 +452,15 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
|
|
|
|
|
// send also the complete body now from the cache
|
|
|
|
|
// simply read the file and transfer to out socket
|
|
|
|
|
InputStream is = new FileInputStream(cacheFile);
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
try {
|
|
|
|
|
is = new FileInputStream(cacheFile);
|
|
|
|
|
byte[] buffer = new byte[2048];
|
|
|
|
|
int l;
|
|
|
|
|
while ((l = is.read(buffer)) > 0) {hfos.write(buffer, 0, l);}
|
|
|
|
|
is.close();
|
|
|
|
|
} finally {
|
|
|
|
|
if (is != null) try { is.close(); } catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
if (hfos instanceof htmlFilterOutputStream) ((htmlFilterOutputStream) hfos).finalize();
|
|
|
|
|
}
|
|
|
|
|
// that's it!
|
|
|
|
@ -607,7 +618,6 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
remote.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// this may happen if the targeted host does not exist or anything with the
|
|
|
|
|
// remote server was wrong.
|
|
|
|
@ -632,6 +642,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void respondError(OutputStream respond, String origerror, int errorcase, String url) {
|
|
|
|
|
FileInputStream fis = null;
|
|
|
|
|
try {
|
|
|
|
|
// set rewrite values
|
|
|
|
|
serverObjects tp = new serverObjects();
|
|
|
|
@ -643,7 +654,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
File file = new File(htRootPath, "/proxymsg/error.html");
|
|
|
|
|
byte[] result;
|
|
|
|
|
ByteArrayOutputStream o = new ByteArrayOutputStream();
|
|
|
|
|
FileInputStream fis = new FileInputStream(file);
|
|
|
|
|
fis = new FileInputStream(file);
|
|
|
|
|
httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes());
|
|
|
|
|
o.close();
|
|
|
|
|
result = o.toByteArray();
|
|
|
|
@ -660,7 +671,8 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
|
|
|
|
|
serverFileUtils.write(result, respond);
|
|
|
|
|
respond.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
if (fis != null) try { fis.close(); } catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|