Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache-timings-to-spec #65

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
target
out
17 changes: 10 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
<description>Contains HAR models and writers</description>
<packaging>jar</packaging>

<url>https://github.com/SmartBear/har-java</url>
<url>https://github.com/speakeasy-api/har-java</url>

<developers>
<developer>
<name>Alexa Drake</name>
<id>alexadrake</id>
</developer>
<developer>
<name>Shadid Chowdhury</name>
<id>shadidchowdhury</id>
Expand All @@ -28,16 +32,15 @@
</developers>

<scm>
<url>https://github.com/SmartBear/har-java</url>
<connection>scm:git:ssh://[email protected]/SmartBear/har-java.git</connection>
<developerConnection>scm:git:ssh://[email protected]/SmartBear/har-java.git
</developerConnection>
<tag>master</tag>
<url>https://github.com/speakeasy-api/har-java</url>
<connection>scm:git:https://github.com/speakeasy-api/har-java</connection>
<developerConnection>scm:git:https://github.com/speakeasy-api/har-java.git</developerConnection>
<tag>main</tag>
</scm>

<issueManagement>
<system>github</system>
<url>https://github.com/SmartBear/har-java/issues</url>
<url>https://github.com/speakeasy-api/har-java/issues</url>
</issueManagement>

<licenses>
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/smartbear/har/builder/HarEntryBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class DefaultHarStreamWriter implements HarStreamWriter {

private final JsonGenerator jsonGenerator;

private DefaultHarStreamWriter(File harFile, String version, HarCreator creator, HarBrowser browser, List<HarPage> 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<HarPage> 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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}
}
14 changes: 9 additions & 5 deletions src/main/java/com/smartbear/har/model/HarCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/**
* This objects contains info about a request coming from browser cache.
*
* @see <a href="http://www.softwareishard.com/blog/har-12-spec/#cache">specification</a>
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#cache">specification</a>
*/
@JsonPropertyOrder({
"beforeRequest",
Expand All @@ -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;
Expand All @@ -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 + "]";
}
}


17 changes: 11 additions & 6 deletions src/main/java/com/smartbear/har/model/HarContent.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://www.softwareishard.com/blog/har-12-spec/#content">specification</a>
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#content">specification</a>
*/
@JsonPropertyOrder({
"size",
Expand All @@ -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;
Expand Down Expand Up @@ -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 + "]";
}
}

18 changes: 12 additions & 6 deletions src/main/java/com/smartbear/har/model/HarCookie.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://www.softwareishard.com/blog/har-12-spec/#cookies">specification</a>
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#cookies">specification</a>
*/
@JsonPropertyOrder({
"name",
Expand All @@ -19,6 +22,8 @@
"secure",
"comment"
})

@JsonInclude(Include.NON_DEFAULT)
public class HarCookie {

private String name;
Expand All @@ -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;
Expand Down Expand Up @@ -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
+ "]";
}
}

11 changes: 7 additions & 4 deletions src/main/java/com/smartbear/har/model/HarCreator.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://www.softwareishard.com/blog/har-12-spec/#creator">specification</a>
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#creator">specification</a>
*/
@JsonPropertyOrder({
"name",
Expand All @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/smartbear/har/model/HarEntry.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://www.softwareishard.com/blog/har-12-spec/#entries">specification</a>
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#entries">specification</a>
*/
@JsonPropertyOrder({
"pageref",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 + "]";
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/smartbear/har/model/HarQueryString.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://www.softwareishard.com/blog/har-12-spec/#queryString">specification</a>
*/
* This object contains list of all parameters and values parsed from a query
* string, if any (embedded in request object).
*
* @see <a href=
* "http://www.softwareishard.com/blog/har-12-spec/#queryString">specification</a>
*/
@JsonPropertyOrder({
"name",
"value",
Expand All @@ -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;
Expand Down
Loading