Closed gitgrimbo closed 8 years ago
They should be able to be deserialized; for example, the HAR viewer parses BMP HARs successfully. BMP's Har classes aren't really designed to deserialize, as there is no reason I'm aware of for the proxy to do so.
Are there any existing Java libraries for HAR parsing that you could leverage?
Hi, I'm not questioning the validity of the HAR JSON that is produced by the BMP Har
classes, I was more wondering if the same JSON could be deserialised back into the BMP Har
classes.
If the answer is that BMP is essentially 'serialise-only' for HAR files then I'm happy with that as an answer and will look towards other HAR parsers/HAR model classes to meet that requirement.
Take a look at https://github.com/sdstoehr/har-reader
@gitgrimbo - Yes, BMP's Har class tree is designed for serialization only. I'd recommend using a HAR library designed for deserialization, such as the one @jpereira06 suggested.
@gitgrimbo I ran into the same thing with the expiry date in the JSESSIONID cookie. I did a string replace for that one value to some meaningful year and the rest worked fine. I am using the Browsermob API to stand up the proxy then grabbing the HAR. Tough part was that I had to stand up a different library for the Har class that was able to be serialized/deserialized.
<dependency>
<groupId>de.sstoehr</groupId>
<artifactId>har-reader</artifactId>
<version>2.0.0</version>
</dependency>
// basic example
private Har retrieveHar() {
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://localhost:8080/proxy/8081/har");
HarReader harReader = new HarReader();
try {
org.apache.http.HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);
// the stupid cookie with a crazy expire year on it
String cleanResponse = responseString.replace("292269008","2012");
bmpHar = harReader.readFromString(cleanResponse);
}
catch (Exception e) {
e.printStackTrace();
}
return bmpHar;
}
Similar to #143, I would like to know if it's possible to deserialise a HAR file into the
Har
object?I have had to do the following to get the
Har
object created due to the following issues:HarNameValuePair
.HarNameVersion
.HarCookie.expires
.HarEntry.time
property when no such property exists (I guess the property is inferred from the presence of agetTime()
method).(note that my
HarCookieDateDeserializer
does nothing at the moment)And without the
HarCookieDateDeserializer
I get this error: