Package io.grpc.stub
Class MetadataUtils
- java.lang.Object
-
- io.grpc.stub.MetadataUtils
-
public final class MetadataUtils extends java.lang.ObjectUtility functions for binding and receiving headers.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T extends AbstractStub<T>>
TattachHeaders(T stub, Metadata extraHeaders)Deprecated.Usestub.withInterceptors(newAttachHeadersInterceptor(...))instead.static <T extends AbstractStub<T>>
TcaptureMetadata(T stub, java.util.concurrent.atomic.AtomicReference<Metadata> headersCapture, java.util.concurrent.atomic.AtomicReference<Metadata> trailersCapture)Deprecated.Usestub.withInterceptors(newCaptureMetadataInterceptor())instead.static ClientInterceptornewAttachHeadersInterceptor(Metadata extraHeaders)Returns a client interceptor that attaches a set of headers to requests.static ClientInterceptornewCaptureMetadataInterceptor(java.util.concurrent.atomic.AtomicReference<Metadata> headersCapture, java.util.concurrent.atomic.AtomicReference<Metadata> trailersCapture)Captures the last received metadata on a channel.
-
-
-
Method Detail
-
attachHeaders
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1789") @Deprecated @InlineMe(replacement="stub.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(extraHeaders))", imports="io.grpc.stub.MetadataUtils") public static <T extends AbstractStub<T>> T attachHeaders(T stub, Metadata extraHeaders)
Deprecated.Usestub.withInterceptors(newAttachHeadersInterceptor(...))instead.Attaches a set of request headers to a stub.- Parameters:
stub- to bind the headers to.extraHeaders- the headers to be passed by each call on the returned stub.- Returns:
- an implementation of the stub with
extraHeadersbound to each call.
-
newAttachHeadersInterceptor
public static ClientInterceptor newAttachHeadersInterceptor(Metadata extraHeaders)
Returns a client interceptor that attaches a set of headers to requests.- Parameters:
extraHeaders- the headers to be passed by each call that is processed by the returned interceptor
-
captureMetadata
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1789") @Deprecated @InlineMe(replacement="stub.withInterceptors(MetadataUtils.newCaptureMetadataInterceptor(headersCapture, trailersCapture))", imports="io.grpc.stub.MetadataUtils") public static <T extends AbstractStub<T>> T captureMetadata(T stub, java.util.concurrent.atomic.AtomicReference<Metadata> headersCapture, java.util.concurrent.atomic.AtomicReference<Metadata> trailersCapture)
Deprecated.Usestub.withInterceptors(newCaptureMetadataInterceptor())instead.Captures the last received metadata for a stub. Useful for testing- Parameters:
stub- to capture forheadersCapture- to record the last received headerstrailersCapture- to record the last received trailers- Returns:
- an implementation of the stub that allows to access the last received call's
headers and trailers via
headersCaptureandtrailersCapture.
-
newCaptureMetadataInterceptor
public static ClientInterceptor newCaptureMetadataInterceptor(java.util.concurrent.atomic.AtomicReference<Metadata> headersCapture, java.util.concurrent.atomic.AtomicReference<Metadata> trailersCapture)
Captures the last received metadata on a channel. Useful for testing.- Parameters:
headersCapture- to record the last received headerstrailersCapture- to record the last received trailers- Returns:
- an implementation of the channel with captures installed.
-
-