Buongiorno, spero che questa sia la sezione giusta. Non so nemmeno se sia il titolo più appropriato per il mio problema, ma ora provo a spiegarvelo.
Con questa classe voglio effettuare la conversione tra file di log HTTP e IIS:
codice:
public class HTTPtoIIS extends Conversion{
private String IISversion = "7.5"; //Valori provvisori.
private String protocolVersion = "1.0";
FileLoader fl = new HTTPLogHandler();
public String convert() {
//fl.setFilePath(Constants.LOG_HTTP_PATH);
fl.parse();
String converted = null;
StringBuffer sb = new StringBuffer();
sb.append(generateHeader());
for (Iterator<HTTPFormat> i = fl.getParsed().iterator(); i.hasNext();) {
HTTPFormat h = (HTTPFormat) i.next();
String line = dateGenerator(h) + " " + IIS_UNKNOWN + " " + h.getMethod() + " "
+ h.getRequest() + " " + IIS_UNKNOWN/*uri query*/ + " " + IIS_UNKNOWN
/*porta*/ + " " + h.getUserID() + " " + h.getIPclient() + " " + h.getUserAgent()
+ " " + h.getStatus() + " 0 0 " + IIS_UNKNOWN;
sb.append("\n");
sb.append(line);
}
converted = sb.toString();
return converted;
}
public String generateHeader() {
fl.parse();
String header = "#Software: Microsoft Internet Information Services " + IISversion + "\n"
+ "#Version: " + protocolVersion + "\n"
+ "#Date: " +dateGenerator(fl.getParsed().get(0)) + "\n"
+ "#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken";
return header;
}
public String dateGenerator(HTTPFormat h) {
String day = dateZero(h.getDate().get(Calendar.DAY_OF_MONTH));
String month = dateZero(h.getDate().get(Calendar.MONTH));
String year = dateZero(h.getDate().get(Calendar.YEAR));
String hour = dateZero(h.getDate().get(Calendar.HOUR_OF_DAY));
String minutes = dateZero(h.getDate().get(Calendar.MINUTE));
String seconds = dateZero(h.getDate().get(Calendar.SECOND));
String result = year + "-" + month + "-" + day + " " + hour + ":"
+ minutes + ":" + seconds;
return result;
}
}
Il problema si verifica quando, invece di mettere nel codice il valore di filePath (cioè
) lo passo da una classe esterna, di questo tipo:
codice:
public class HTTPtoIIStest { public static void main(String[] args) {
HTTPtoIIS h = new HTTPtoIIS();
h.setFilePath(Constants.LOG_HTTP_PATH);
System.out.println(h.convert());
}
}
mi da un errore:
codice:
Exception in thread "main" java.lang.NullPointerException at java.io.File.<init>(File.java:277)
at tesi.FileLoader.loadFile(FileLoader.java:19)
at tesi.HTTPLogHandler.parse(HTTPLogHandler.java:20)
at tesi.HTTPtoIIS.convert(HTTPtoIIS.java:19)
at test.HTTPtoIIStest.main(HTTPtoIIStest.java:19)
Java Result: 1
Vi chiedo aiuto dopo due giorni di emicrania senza riuscire a ricavare nulla... Grazie mille!