-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: sokomishalov <sokolovm@dev.vtb>
- Loading branch information
1 parent
51fefc4
commit 7fd7635
Showing
24 changed files
with
1,464 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.zalando</groupId> | ||
<artifactId>logbook-parent</artifactId> | ||
<version>2.11.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>logbook-httpclient5</artifactId> | ||
<description>HTTP Client interceptor for request and response logging</description> | ||
<scm> | ||
<url>https://github.com/zalando/logbook</url> | ||
<connection>scm:git:git@github.com:zalando/logbook.git</connection> | ||
<developerConnection>scm:git:git@github.com:zalando/logbook.git</developerConnection> | ||
</scm> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.zalando</groupId> | ||
<artifactId>logbook-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents.client5</groupId> | ||
<artifactId>httpclient5</artifactId> | ||
<version>5.1</version> | ||
</dependency> | ||
<!-- testing --> | ||
<dependency> | ||
<groupId>org.zalando</groupId> | ||
<artifactId>logbook-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.zalando</groupId> | ||
<artifactId>logbook-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-nop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.rest-driver</groupId> | ||
<artifactId>rest-client-driver</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
9 changes: 9 additions & 0 deletions
9
logbook-httpclient5/src/main/java/org/zalando/logbook/httpclient5/Attributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.zalando.logbook.httpclient5; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.zalando.logbook.Logbook; | ||
|
||
@UtilityClass | ||
final class Attributes { | ||
static final String STAGE = Logbook.class.getName() + ".STAGE"; | ||
} |
37 changes: 37 additions & 0 deletions
37
...t5/src/main/java/org/zalando/logbook/httpclient5/BufferingFixedSizeDataStreamChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.zalando.logbook.httpclient5; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.hc.core5.http.Header; | ||
import org.apache.hc.core5.http.nio.DataStreamChannel; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
|
||
import static lombok.AccessLevel.PACKAGE; | ||
|
||
@RequiredArgsConstructor(access = PACKAGE) | ||
final class BufferingFixedSizeDataStreamChannel implements DataStreamChannel { | ||
private final byte[] buffer; | ||
|
||
public byte[] getBuffer() { | ||
return buffer; | ||
} | ||
|
||
@Override | ||
public void requestOutput() { | ||
} | ||
|
||
@Override | ||
public int write(ByteBuffer src) { | ||
ByteBufferUtils.fixedSizeCopy(src, buffer); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void endStream() { | ||
} | ||
|
||
@Override | ||
public void endStream(List<? extends Header> trailers) { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
logbook-httpclient5/src/main/java/org/zalando/logbook/httpclient5/ByteBufferUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.zalando.logbook.httpclient5; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
@UtilityClass | ||
class ByteBufferUtils { | ||
|
||
static void fixedSizeCopy(ByteBuffer src, byte[] dest) { | ||
if (src.hasArray()) { | ||
byte[] array = src.array(); | ||
System.arraycopy(array, 0, dest, 0, dest.length); | ||
} else { | ||
src.get(dest, 0, dest.length); | ||
src.flip(); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...t5/src/main/java/org/zalando/logbook/httpclient5/ForwardingHttpAsyncResponseConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.zalando.logbook.httpclient5; | ||
|
||
import lombok.experimental.Delegate; | ||
import org.apache.hc.core5.http.nio.AsyncResponseConsumer; | ||
|
||
abstract class ForwardingHttpAsyncResponseConsumer<T> implements AsyncResponseConsumer<T> { | ||
|
||
@Delegate | ||
protected abstract AsyncResponseConsumer<T> delegate(); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
logbook-httpclient5/src/main/java/org/zalando/logbook/httpclient5/HttpEntities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.zalando.logbook.httpclient5; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Delegate; | ||
import lombok.experimental.UtilityClass; | ||
import org.apache.hc.core5.http.ContentType; | ||
import org.apache.hc.core5.http.HttpEntity; | ||
import org.apache.hc.core5.http.io.entity.ByteArrayEntity; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.hc.core5.http.io.entity.EntityUtils.toByteArray; | ||
|
||
@UtilityClass | ||
final class HttpEntities { | ||
|
||
interface Copy extends HttpEntity { | ||
byte[] getBody(); | ||
} | ||
|
||
Copy copy(final HttpEntity entity) throws IOException { | ||
final byte[] body = toByteArray(entity); | ||
ContentType contentType = ContentType.parse(entity.getContentType()); | ||
boolean chunked = entity.isChunked(); | ||
String contentEncoding = entity.getContentEncoding(); | ||
|
||
final ByteArrayEntity copy = new ByteArrayEntity(body, contentType, contentEncoding, chunked); | ||
|
||
return new DefaultCopy(copy, body); | ||
} | ||
|
||
@RequiredArgsConstructor | ||
private static final class DefaultCopy implements Copy { | ||
|
||
@Delegate | ||
private final HttpEntity entity; | ||
|
||
@Getter | ||
private final byte[] body; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.