Created
July 17, 2017 14:34
-
-
Save schleichardt/f2c3fe8c2d820f88240db372e449944b to your computer and use it in GitHub Desktop.
wrap a SphereClient to send a correlation ID
This file contains hidden or 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
import io.sphere.sdk.client.*; | |
import java.util.UUID; | |
import java.util.concurrent.CompletionStage; | |
public class CorrelationIdSphereClient extends SphereClientDecorator { | |
public CorrelationIdSphereClient(SphereClient delegate) { | |
super(delegate); | |
} | |
@Override | |
public <T> CompletionStage<T> execute(SphereRequest<T> sphereRequest) { | |
return super.execute(new CorrelationIdSphereRequest<>(sphereRequest)); | |
} | |
private static final class CorrelationIdSphereRequest<T> extends SphereRequestDecorator<T> { | |
private CorrelationIdSphereRequest(SphereRequest<T> delegate) { | |
super(delegate); | |
} | |
@Override | |
public HttpRequestIntent httpRequestIntent() { | |
return super.httpRequestIntent().plusHeader("X-Correlation-ID", UUID.randomUUID().toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment