Is anyone familiar using HarLib in Java? I'm trying to get the "response" data from a .HAR file and output it to screen.
There is a getResponse()
method in the HarEntry
class, however I'm not sure how to implement it based on the example on the main page:
Sample from web site:
import edu.umass.cs.benchlab.har.*;
File f = new File(fileName);
HarFileReader r = new HarFileReader();
HarFileWriter w = new HarFileWriter();
try
{
System.out.println("Reading " + fileName);
HarLog log = r.readHarFile(f);
// Access all elements as objects
HarBrowser browser = log.getBrowser();
HarEntries entries = log.getEntries();
List<HarPage> pages = log.getPages().getPages();
for (HarPage page : pages)
{
System.out.println("page start time: "
+ ISO8601DateFormatter.format(page.getStartedDateTime()));
System.out.println("page id: " + page.getId());
System.out.println("page title: "+page.getTitle());
}
// Once you are done manipulating the objects, write back to a file
System.out.println("Writing " + fileName + ".test");
File f2 = new File(fileName + ".test");
w.writeHarFile(log, f2);
}
catch (JsonParseException e)
{
e.printStackTrace();
fail("Parsing error during test");
}
catch (IOException e)
{
e.printStackTrace();
fail("IO exception during test");
}
I think I figured something out, although I don't know how "clean" this code is. I modified the sample code and commented out the write to file part:
}