17 |
import java.util.Map; |
import java.util.Map; |
18 |
import java.util.logging.Level; |
import java.util.logging.Level; |
19 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
|
import java.util.zip.GZIPInputStream; |
|
20 |
import java.util.zip.ZipEntry; |
import java.util.zip.ZipEntry; |
21 |
import java.util.zip.ZipOutputStream; |
import java.util.zip.ZipOutputStream; |
22 |
|
|
60 |
|
|
61 |
protected File[] getFiles(int count) { |
protected File[] getFiles(int count) { |
62 |
File accessLogDir = new File("/home/app/domain1/logs/access/"); |
File accessLogDir = new File("/home/app/domain1/logs/access/"); |
63 |
|
//File accessLogDir = new File("/home/torben/inst/glassfishv3/glassfish/domains/domain1/logs/access/"); |
64 |
|
|
65 |
File logFiles[] = accessLogDir.listFiles( new FilenameFilter() { |
File logFiles[] = accessLogDir.listFiles( new FilenameFilter() { |
66 |
@Override |
@Override |
67 |
public boolean accept(File dir, String name) { |
public boolean accept(File dir, String name) { |
68 |
|
//log.info("name:" + name); |
69 |
return name.startsWith("server_access_log"); |
return name.startsWith("server_access_log"); |
70 |
} |
} |
71 |
}); |
}); |
72 |
|
|
73 |
|
Arrays.sort(logFiles); |
74 |
|
|
75 |
if (logFiles == null) { |
if (logFiles == null) { |
76 |
File[] empty = {}; |
File[] empty = {}; |
77 |
|
log.info("file array was empty"); |
78 |
return empty; |
return empty; |
79 |
} |
} |
80 |
|
|
81 |
int from = logFiles.length - count; |
int from = logFiles.length - (count); |
82 |
int to = logFiles.length-1; |
int to = logFiles.length; |
83 |
|
|
84 |
return Arrays.copyOfRange(logFiles, from, to); |
return Arrays.copyOfRange(logFiles, from, to); |
85 |
} |
} |
86 |
|
|
87 |
protected PositionContainer getRequestsFromFileWorker(boolean multiple) throws IOException{ |
protected PositionContainer getRequestsFromFileWorker(int count) throws IOException{ |
88 |
PositionContainer positions = new PositionContainer(); |
PositionContainer positions = new PositionContainer(); |
89 |
|
|
90 |
try { |
try { |
|
|
|
|
int count; |
|
|
|
|
|
if (multiple == false) { |
|
|
count = 1; |
|
|
} else { |
|
|
count = 4; |
|
|
} |
|
91 |
|
|
92 |
File files[] = getFiles(count); |
File files[] = getFiles(count); |
93 |
|
|
336 |
return sb.toString(); |
return sb.toString(); |
337 |
} |
} |
338 |
|
|
339 |
protected String getRequestsFromFile(boolean multiple) throws IOException { |
protected String getRequestsFromFile(int count) throws IOException { |
340 |
String kmlData = null; |
String kmlData = null; |
341 |
String key; |
String key; |
342 |
|
|
343 |
if (multiple == false) { |
key = "kmldata-" + count; |
|
key = "kmldata"; |
|
|
} else { |
|
|
key = "kmldata-multi"; |
|
|
} |
|
344 |
|
|
345 |
kmlData = cache.get(key); |
kmlData = cache.get(key); |
346 |
|
|
347 |
if (kmlData == null) { |
if (kmlData == null) { |
348 |
kmlData = formatXml( getRequestsFromFileWorker(multiple) ); |
kmlData = formatXml( getRequestsFromFileWorker(count) ); |
349 |
cache.put(key, kmlData); |
cache.put(key, kmlData); |
350 |
kmlData += "<!-- from source -->"; |
kmlData += "<!-- from source -->"; |
351 |
} else { |
} else { |
371 |
@Override |
@Override |
372 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
373 |
|
|
|
boolean multiple = enabled( req.getParameter("multi") ); |
|
374 |
|
|
375 |
String kmlData = getRequestsFromFile(multiple); |
int count = Integer.parseInt( req.getParameter("count") ); |
376 |
|
|
377 |
|
if (count > 30) //limit to 30 days |
378 |
|
count = 30; |
379 |
|
|
380 |
|
String kmlData = getRequestsFromFile(count); |
381 |
|
|
382 |
if ( enabled(req.getParameter("zip")) ) { |
if ( enabled(req.getParameter("zip")) ) { |
383 |
|
|