diff --git a/.gitignore b/.gitignore
index ee44a96..a133b2c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.idea
target
+out
diff --git a/pom.xml b/pom.xml
index a85d718..1d7bcbd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,9 +10,13 @@
Contains HAR models and writers
jar
- https://github.com/SmartBear/har-java
+ https://github.com/speakeasy-api/har-java
+
+ Alexa Drake
+ alexadrake
+
Shadid Chowdhury
shadidchowdhury
@@ -28,16 +32,15 @@
- https://github.com/SmartBear/har-java
- scm:git:ssh://git@github.com/SmartBear/har-java.git
- scm:git:ssh://git@github.com/SmartBear/har-java.git
-
- master
+ https://github.com/speakeasy-api/har-java
+ scm:git:https://github.com/speakeasy-api/har-java
+ scm:git:https://github.com/speakeasy-api/har-java.git
+ main
github
- https://github.com/SmartBear/har-java/issues
+ https://github.com/speakeasy-api/har-java/issues
diff --git a/src/main/java/com/smartbear/har/builder/HarEntryBuilder.java b/src/main/java/com/smartbear/har/builder/HarEntryBuilder.java
index 6500b60..abbf5c1 100644
--- a/src/main/java/com/smartbear/har/builder/HarEntryBuilder.java
+++ b/src/main/java/com/smartbear/har/builder/HarEntryBuilder.java
@@ -1,14 +1,15 @@
package com.smartbear.har.builder;
-import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+
import com.smartbear.har.model.HarCache;
import com.smartbear.har.model.HarEntry;
import com.smartbear.har.model.HarRequest;
import com.smartbear.har.model.HarResponse;
import com.smartbear.har.model.HarTimings;
-import java.util.Date;
-
public class HarEntryBuilder {
private String pageref;
private String startedDateTime;
@@ -21,6 +22,9 @@ public class HarEntryBuilder {
private String connection;
private String comment;
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'")
+ .withZone(ZoneId.of("UTC"));
+
public HarEntryBuilder withPageref(String pageref) {
this.pageref = pageref;
return this;
@@ -31,8 +35,8 @@ public HarEntryBuilder withStartedDateTime(String startedDateTime) {
return this;
}
- public HarEntryBuilder withStartedDateTime(Date startedDateTime) {
- this.startedDateTime = new ISO8601DateFormat().format(startedDateTime);
+ public HarEntryBuilder withStartedDateTime(Instant startedDateTime) {
+ this.startedDateTime = startedDateTime.toString();
return this;
}
@@ -77,6 +81,7 @@ public HarEntryBuilder withComment(String comment) {
}
public HarEntry build() {
- return new HarEntry(pageref, startedDateTime, time, request, response, cache, timings, serverIPAddress, connection, comment);
+ return new HarEntry(pageref, startedDateTime, time, request, response, cache, timings, serverIPAddress,
+ connection, comment);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/smartbear/har/creator/DefaultHarStreamWriter.java b/src/main/java/com/smartbear/har/creator/DefaultHarStreamWriter.java
index 88d919f..0ba9adb 100644
--- a/src/main/java/com/smartbear/har/creator/DefaultHarStreamWriter.java
+++ b/src/main/java/com/smartbear/har/creator/DefaultHarStreamWriter.java
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -19,8 +20,8 @@ public class DefaultHarStreamWriter implements HarStreamWriter {
private final JsonGenerator jsonGenerator;
- private DefaultHarStreamWriter(File harFile, String version, HarCreator creator, HarBrowser browser, List pages, String comment, boolean usePrettyPrint) throws IOException {
- jsonGenerator = new JsonFactory().createGenerator(harFile, JsonEncoding.UTF8);
+ private DefaultHarStreamWriter(OutputStream outputStream, String version, HarCreator creator, HarBrowser browser, List pages, String comment, boolean usePrettyPrint) throws IOException {
+ jsonGenerator = new JsonFactory().createGenerator(outputStream, JsonEncoding.UTF8);
final ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
jsonGenerator.setCodec(objectMapper);
if (usePrettyPrint) {
@@ -70,7 +71,7 @@ public void closeHar() throws IOException {
}
public static class Builder {
- private File harFile;
+ private OutputStream outputStream;
private String version = "1.2";
private HarCreator creator;
private HarBrowser browser;
@@ -111,8 +112,8 @@ public Builder withComment(String comment) {
return this;
}
- public Builder withOutputFile(File harFile) {
- this.harFile = harFile;
+ public Builder withOutputStream(OutputStream outputStream) {
+ this.outputStream = outputStream;
return this;
}
@@ -124,7 +125,7 @@ public Builder withUsePrettyPrint(boolean usePrettyPrint) {
public DefaultHarStreamWriter build() throws IOException {
- return new DefaultHarStreamWriter(harFile, version, creator, browser, pages, comment, usePrettyPrint);
+ return new DefaultHarStreamWriter(outputStream, version, creator, browser, pages, comment, usePrettyPrint);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/com/smartbear/har/model/HarCache.java b/src/main/java/com/smartbear/har/model/HarCache.java
index 453ceff..bc6084a 100644
--- a/src/main/java/com/smartbear/har/model/HarCache.java
+++ b/src/main/java/com/smartbear/har/model/HarCache.java
@@ -7,7 +7,8 @@
/**
* This objects contains info about a request coming from browser cache.
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"beforeRequest",
@@ -20,9 +21,13 @@ public class HarCache {
private HarCacheRequest afterRequest;
private String comment;
+ @JsonCreator
+ public HarCache() {
+ }
+
@JsonCreator
public HarCache(@JsonProperty("beforeRequest") HarCacheRequest beforeRequest,
- @JsonProperty("afterRequest") HarCacheRequest afterRequest, @JsonProperty("comment") String comment) {
+ @JsonProperty("afterRequest") HarCacheRequest afterRequest, @JsonProperty("comment") String comment) {
this.beforeRequest = beforeRequest;
this.afterRequest = afterRequest;
this.comment = comment;
@@ -42,8 +47,7 @@ public String getComment() {
@Override
public String toString() {
- return "HarCache [beforeRequest = " + beforeRequest + ", afterRequest = " + afterRequest + ", comment = " + comment + "]";
+ return "HarCache [beforeRequest = " + beforeRequest + ", afterRequest = " + afterRequest + ", comment = "
+ + comment + "]";
}
}
-
-
diff --git a/src/main/java/com/smartbear/har/model/HarContent.java b/src/main/java/com/smartbear/har/model/HarContent.java
index eaf038d..fae0c83 100644
--- a/src/main/java/com/smartbear/har/model/HarContent.java
+++ b/src/main/java/com/smartbear/har/model/HarContent.java
@@ -1,13 +1,17 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
- * This object describes details about response content (embedded in response object).
+ * This object describes details about response content (embedded in response
+ * object).
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"size",
@@ -26,8 +30,9 @@ public class HarContent {
@JsonCreator
public HarContent(@JsonProperty("size") Long size, @JsonProperty("compression") Long compression,
- @JsonProperty("mimeType") String mimeType, @JsonProperty("text") String text,
- @JsonProperty("comment") String comment) {
+ @JsonProperty("mimeType") String mimeType,
+ @JsonProperty("text") @JsonInclude(Include.NON_EMPTY) String text,
+ @JsonProperty("comment") String comment) {
this.size = size;
this.compression = compression;
this.mimeType = mimeType;
@@ -57,7 +62,7 @@ public Long getSize() {
@Override
public String toString() {
- return "HarContent [text = " + text + ", comment = " + comment + ", compression = " + compression + ", mimeType = " + mimeType + ", size = " + size + "]";
+ return "HarContent [text = " + text + ", comment = " + comment + ", compression = " + compression
+ + ", mimeType = " + mimeType + ", size = " + size + "]";
}
}
-
diff --git a/src/main/java/com/smartbear/har/model/HarCookie.java b/src/main/java/com/smartbear/har/model/HarCookie.java
index 3980fd3..071d0da 100644
--- a/src/main/java/com/smartbear/har/model/HarCookie.java
+++ b/src/main/java/com/smartbear/har/model/HarCookie.java
@@ -1,13 +1,16 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* Cookie used in request and response objects.
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"name",
@@ -19,6 +22,8 @@
"secure",
"comment"
})
+
+@JsonInclude(Include.NON_DEFAULT)
public class HarCookie {
private String name;
@@ -32,9 +37,9 @@ public class HarCookie {
@JsonCreator
public HarCookie(@JsonProperty("name") String name, @JsonProperty("value") String value,
- @JsonProperty("path") String path, @JsonProperty("domain") String domain,
- @JsonProperty("expires") String expires, @JsonProperty("httpOnly") boolean httpOnly,
- @JsonProperty("secure") boolean secure, @JsonProperty("comment") String comment) {
+ @JsonProperty("path") String path, @JsonProperty("domain") String domain,
+ @JsonProperty("expires") String expires, @JsonProperty("httpOnly") boolean httpOnly,
+ @JsonProperty("secure") boolean secure, @JsonProperty("comment") String comment) {
this.name = name;
this.value = value;
this.path = path;
@@ -79,7 +84,8 @@ public String getComment() {
@Override
public String toString() {
- return "HarCookie [expires = " + expires + ", name = " + name + ", secure = " + secure + ", domain = " + domain + ", path = " + path + ", value = " + value + ", httpOnly = " + httpOnly + ", comment = " + comment + "]";
+ return "HarCookie [expires = " + expires + ", name = " + name + ", secure = " + secure + ", domain = " + domain
+ + ", path = " + path + ", value = " + value + ", httpOnly = " + httpOnly + ", comment = " + comment
+ + "]";
}
}
-
diff --git a/src/main/java/com/smartbear/har/model/HarCreator.java b/src/main/java/com/smartbear/har/model/HarCreator.java
index 746b445..c46d360 100644
--- a/src/main/java/com/smartbear/har/model/HarCreator.java
+++ b/src/main/java/com/smartbear/har/model/HarCreator.java
@@ -1,14 +1,16 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-
/**
* Information about the creator of HAR
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"name",
@@ -22,8 +24,9 @@ public class HarCreator {
private String comment;
@JsonCreator
- public HarCreator(@JsonProperty("name") String name, @JsonProperty("comment") String comment,
- @JsonProperty("version") String version) {
+ public HarCreator(@JsonProperty("name") String name,
+ @JsonProperty("comment") @JsonInclude(Include.NON_EMPTY) String comment,
+ @JsonProperty("version") String version) {
this.name = name;
this.comment = comment;
this.version = version;
diff --git a/src/main/java/com/smartbear/har/model/HarEntry.java b/src/main/java/com/smartbear/har/model/HarEntry.java
index 35bd0de..8e0897d 100644
--- a/src/main/java/com/smartbear/har/model/HarEntry.java
+++ b/src/main/java/com/smartbear/har/model/HarEntry.java
@@ -1,13 +1,16 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* This object represents an array with all exported HTTP requests.
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"pageref",
@@ -36,10 +39,12 @@ public class HarEntry {
@JsonCreator
public HarEntry(@JsonProperty("pageref") String pageref, @JsonProperty("startedDateTime") String startedDateTime,
- @JsonProperty("time") long time, @JsonProperty("request") HarRequest request,
- @JsonProperty("response") HarResponse response, @JsonProperty("cache") HarCache cache,
- @JsonProperty("timings") HarTimings timings, @JsonProperty("serverIPAddress") String serverIPAddress,
- @JsonProperty("connection") String connection, @JsonProperty("comment") String comment) {
+ @JsonProperty("time") long time, @JsonProperty("request") HarRequest request,
+ @JsonProperty("response") HarResponse response,
+ @JsonProperty("cache") @JsonInclude(Include.ALWAYS) HarCache cache,
+ @JsonProperty("timings") @JsonInclude(Include.ALWAYS) HarTimings timings,
+ @JsonProperty("serverIPAddress") String serverIPAddress,
+ @JsonProperty("connection") String connection, @JsonProperty("comment") String comment) {
this.pageref = pageref;
this.startedDateTime = startedDateTime;
this.time = time;
@@ -94,6 +99,8 @@ public String getComment() {
@Override
public String toString() {
- return "HarEntry [response = " + response + ", connection = " + connection + ", time = " + time + ", pageref = " + pageref + ", cache = " + cache + ", timings = " + timings + ", request = " + request + ", comment = " + comment + ", serverIPAddress = " + serverIPAddress + ", startedDateTime = " + startedDateTime + "]";
+ return "HarEntry [response = " + response + ", connection = " + connection + ", time = " + time + ", pageref = "
+ + pageref + ", cache = " + cache + ", timings = " + timings + ", request = " + request + ", comment = "
+ + comment + ", serverIPAddress = " + serverIPAddress + ", startedDateTime = " + startedDateTime + "]";
}
}
diff --git a/src/main/java/com/smartbear/har/model/HarQueryString.java b/src/main/java/com/smartbear/har/model/HarQueryString.java
index 3cee516..3b7acad 100644
--- a/src/main/java/com/smartbear/har/model/HarQueryString.java
+++ b/src/main/java/com/smartbear/har/model/HarQueryString.java
@@ -1,13 +1,18 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
- * This object contains list of all parameters and values parsed from a query string, if any (embedded in request object).
- * @see specification
- */
+ * This object contains list of all parameters and values parsed from a query
+ * string, if any (embedded in request object).
+ *
+ * @see specification
+ */
@JsonPropertyOrder({
"name",
"value",
@@ -20,7 +25,7 @@ public class HarQueryString {
@JsonCreator
public HarQueryString(@JsonProperty("name") String name, @JsonProperty("value") String value,
- @JsonProperty("comment") String comment) {
+ @JsonProperty("comment") @JsonInclude(Include.NON_DEFAULT) String comment) {
this.name = name;
this.value = value;
this.comment = comment;
diff --git a/src/main/java/com/smartbear/har/model/HarResponse.java b/src/main/java/com/smartbear/har/model/HarResponse.java
index c6e8af9..16d7a3a 100644
--- a/src/main/java/com/smartbear/har/model/HarResponse.java
+++ b/src/main/java/com/smartbear/har/model/HarResponse.java
@@ -1,15 +1,18 @@
package com.smartbear.har.model;
+import java.util.List;
+
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import java.util.List;
-
/**
* This object contains detailed info about the response.
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"status",
@@ -38,17 +41,18 @@ public class HarResponse {
@JsonCreator
public HarResponse(@JsonProperty("status") int status, @JsonProperty("statusText") String statusText,
- @JsonProperty("httpVersion") String httpVersion, @JsonProperty("cookies") List cookies,
- @JsonProperty("headers") List headers, @JsonProperty("content") HarContent content,
- @JsonProperty("redirectURL") String redirectURL, @JsonProperty("headersSize") Long headersSize,
- @JsonProperty("bodySize") Long bodySize, @JsonProperty("comment") String comment) {
+ @JsonProperty("httpVersion") String httpVersion, @JsonProperty("cookies") List cookies,
+ @JsonProperty("headers") List headers, @JsonProperty("content") HarContent content,
+ @JsonProperty("redirectURL") @JsonInclude(Include.ALWAYS) String redirectURL,
+ @JsonProperty("headersSize") Long headersSize,
+ @JsonProperty("bodySize") Long bodySize, @JsonProperty("comment") String comment) {
this.status = status;
this.statusText = statusText;
this.httpVersion = httpVersion;
this.cookies = cookies;
this.headers = headers;
this.content = content;
- this.redirectURL = redirectURL;
+ this.redirectURL = redirectURL == null ? "" : redirectURL;
this.headersSize = headersSize;
this.bodySize = bodySize;
this.comment = comment;
@@ -96,8 +100,9 @@ public Long getHeadersSize() {
@Override
public String toString() {
- return "HarResponse [content = " + content + ", headers = " + headers + ", bodySize = " + bodySize + ", httpVersion = " + httpVersion + ", status = " + status + ", redirectURL = " + redirectURL + ", statusText = " + statusText + ", comment = " + comment + ", cookies = " + cookies + ", headersSize = " + headersSize + "]";
+ return "HarResponse [content = " + content + ", headers = " + headers + ", bodySize = " + bodySize
+ + ", httpVersion = " + httpVersion + ", status = " + status + ", redirectURL = " + redirectURL
+ + ", statusText = " + statusText + ", comment = " + comment + ", cookies = " + cookies
+ + ", headersSize = " + headersSize + "]";
}
}
-
-
diff --git a/src/main/java/com/smartbear/har/model/HarTimings.java b/src/main/java/com/smartbear/har/model/HarTimings.java
index e1411dd..ab0fea2 100644
--- a/src/main/java/com/smartbear/har/model/HarTimings.java
+++ b/src/main/java/com/smartbear/har/model/HarTimings.java
@@ -1,13 +1,17 @@
package com.smartbear.har.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
- * This object describes various phases within request-response round trip. All times are specified in milliseconds.
+ * This object describes various phases within request-response round trip. All
+ * times are specified in milliseconds.
*
- * @see specification
+ * @see specification
*/
@JsonPropertyOrder({
"blocked",
@@ -31,10 +35,13 @@ public class HarTimings {
private String comment;
@JsonCreator
- public HarTimings(@JsonProperty("blocked") Long blocked, @JsonProperty("dns") Long dns,
- @JsonProperty("connect") Long connect, @JsonProperty("send") Long send,
- @JsonProperty("wait") Long wait, @JsonProperty("receive") Long receive,
- @JsonProperty("ssl") Long ssl, @JsonProperty("comment") String comment) {
+ public HarTimings(@JsonProperty("blocked") @JsonInclude(Include.NON_DEFAULT) Long blocked,
+ @JsonProperty("dns") @JsonInclude(Include.NON_DEFAULT) Long dns,
+ @JsonProperty("connect") @JsonInclude(Include.NON_DEFAULT) Long connect,
+ @JsonProperty("send") Long send,
+ @JsonProperty("wait") Long wait, @JsonProperty("receive") Long receive,
+ @JsonProperty("ssl") @JsonInclude(Include.NON_DEFAULT) Long ssl,
+ @JsonProperty("comment") @JsonInclude(Include.NON_EMPTY) String comment) {
this.blocked = blocked;
this.dns = dns;
this.connect = connect;
@@ -79,7 +86,8 @@ public Long getReceive() {
@Override
public String toString() {
- return "HarTimings [send = " + send + ", connect = " + connect + ", dns = " + dns + ", ssl = " + ssl + ", blocked = " + blocked + ", wait = " + wait + ", comment = " + comment + ", receive = " + receive + "]";
+ return "HarTimings [send = " + send + ", connect = " + connect + ", dns = " + dns + ", ssl = " + ssl
+ + ", blocked = " + blocked + ", wait = " + wait + ", comment = " + comment + ", receive = " + receive
+ + "]";
}
}
-
diff --git a/src/test/com/smartbear/har/creator/DefaultHarStreamWriterTest.java b/src/test/com/smartbear/har/creator/DefaultHarStreamWriterTest.java
index 28cec2f..00fc013 100644
--- a/src/test/com/smartbear/har/creator/DefaultHarStreamWriterTest.java
+++ b/src/test/com/smartbear/har/creator/DefaultHarStreamWriterTest.java
@@ -9,6 +9,8 @@
import org.junit.Test;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -17,16 +19,19 @@ public class DefaultHarStreamWriterTest {
private File tempHarFile;
private HarStreamWriter harBuilder;
+ private OutputStream outputStream;
@Before
public void setUp() throws Exception {
tempHarFile = File.createTempFile("virt", ".har");
- harBuilder = new DefaultHarStreamWriter.Builder().withOutputFile(tempHarFile).withComment("Test Har").build();
+ outputStream = new FileOutputStream(tempHarFile);
+ harBuilder = new DefaultHarStreamWriter.Builder().withOutputStream(outputStream).withComment("Test Har").build();
}
@After
public void tearDown() throws Exception {
tempHarFile.deleteOnExit();
+ outputStream.close();
}
@Test