Skip to content

Instantly share code, notes, and snippets.

@schleichardt
Created July 17, 2017 14:34
Show Gist options
  • Save schleichardt/f2c3fe8c2d820f88240db372e449944b to your computer and use it in GitHub Desktop.
Save schleichardt/f2c3fe8c2d820f88240db372e449944b to your computer and use it in GitHub Desktop.
wrap a SphereClient to send a correlation ID
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