Skip to content
Open
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 .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
- allure-hamcrest
- allure-httpclient
- allure-httpclient5
- allure-java-httpclient
- allure-java-commons
- allure-java-commons-test
- allure-jax-rs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Run your tests, then generate or serve the report from the produced Allure resul
| Module | Use When | Captured Data |
| --- | --- | --- |
| [`allure-rest-assured`](allure-rest-assured/README.md) | REST Assured filters | HTTP requests and responses |
| [`allure-java-httpclient`](allure-java-httpclient/README.md) | Java built-in `HttpClient` wrapper | HTTP requests and responses |
| [`allure-httpclient5`](allure-httpclient5/README.md) | Apache HttpClient 5 interceptors | HTTP requests and responses |
| [`allure-httpclient`](allure-httpclient/README.md) | Apache HttpClient 4 interceptors | HTTP requests and responses |
| [`allure-okhttp3`](allure-okhttp3/README.md) | OkHttp interceptors | HTTP requests and responses |
Expand Down
72 changes: 72 additions & 0 deletions allure-java-httpclient/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# allure-java-httpclient

Java built-in HTTP Client integration for Allure Java.

Use this module to capture requests and responses sent through `java.net.http.HttpClient` as structured HTTP exchange attachments in Allure Report.

## Supported Versions

- Allure Java 3.x requires Java 17 or newer.
- The wrapped HTTP client API is available since Java 11.
- Synchronous requests, asynchronous requests, and accepted HTTP/2 push promises are supported.

## Installation

Gradle:

```kotlin
dependencies {
testImplementation(platform("io.qameta.allure:allure-bom:<allure-version>"))
testImplementation("io.qameta.allure:allure-java-httpclient")
}
```

Maven, with `allure-bom` imported in dependency management:

```xml
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-java-httpclient</artifactId>
<scope>test</scope>
</dependency>
```

## Setup

Wrap the client used by your tests with `io.qameta.allure.javahttpclient.AllureHttpClient`.

```java
HttpClient httpClient = AllureHttpClient.wrap(
HttpClient.newBuilder().build()
);

HttpRequest request = HttpRequest.newBuilder(URI.create("https://example.test/api/items"))
.GET()
.build();

HttpResponse<String> response = httpClient.send(
request,
HttpResponse.BodyHandlers.ofString()
);
```

The wrapper passes calls through unchanged when no Allure test or fixture is running.

Customize redaction and body limits before sharing the client:

```java
HttpClient httpClient = AllureHttpClient.wrap(HttpClient.newHttpClient())
.configureHttpExchange(exchange -> exchange
.redactHeader("X-Api-Key")
.redactQueryParameter("token")
.setMaxBodySize(64 * 1024));
```

## Report Output

- One `HTTP exchange` attachment for each completed request or accepted push promise.
- Request method, URL, HTTP version, headers, and captured body.
- Response status, HTTP version, headers, and captured body.
- Transport errors when a request completes exceptionally.

Streaming response handlers remain streaming. The attachment contains the response bytes delivered by the time the response future completes; consume or close streaming bodies as required by `HttpClient`.
28 changes: 28 additions & 0 deletions allure-java-httpclient/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
description = "Allure Java HTTP Client Integration"

dependencies {
api(project(":allure-java-commons"))
testImplementation("org.wiremock:wiremock")
testImplementation("org.assertj:assertj-core")
testImplementation(project(":allure-assertj"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.slf4j:slf4j-simple")
testImplementation(project(":allure-java-commons-test"))
testImplementation(project(":allure-junit-platform"))
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.jar {
manifest {
attributes(
mapOf(
"Automatic-Module-Name" to "io.qameta.allure.javahttpclient"
)
)
}
}

tasks.test {
useJUnitPlatform()
}
Loading
Loading