HarLib is an open source Java library for the HTTP Archive Specification (HAR) v1.2. HarLib v1.1.2 is now available (see download link at the bottom of this page). Main features
UsageThe API is very intuitive and maps all JSON objects to Java objects. HarLib relies on Jackson for the parsing. You can use the HarLib version that is already integrated with Jackson or add the Jackson jar to your classpath.Here is an example on how to read/write HAR files with HarLib. import edu.umass.cs.benchlab.har.* 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"); } Here is another example using a Derby database for storing HAR data. // Read a HAR file HarFileReader r = new HarFileReader(); HarLog log = r.readHarFile(f); HarDatabaseConfig config = new HarDatabaseConfig( "org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:harlibtest;create=true", "SA", "", "writetest", null, null, null, null, null); log.writeJDBC(config); // Read a potentially corrupted HAR file HarFileReader r = new HarFileReader(); try { // All violations of the specification generate warnings HarLog l = r.readHarFile(f, warnings); for (HarWarning w : warnings) System.out.println("File:" + fileName + " - Warning:" + w); } catch (JsonParseException e) { e.printStackTrace(); fail("Parsing error during test"); } catch (IOException e) { e.printStackTrace(); fail("IO exception during test"); } DownloadYou will find the following files (where xxx is the version number):
|
Projects >