Package io.grpc.stub

Class MetadataUtils


  • public final class MetadataUtils
    extends java.lang.Object
    Utility functions for binding and receiving headers.
    • 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.
        Use stub.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 extraHeaders bound 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.
        Use stub.withInterceptors(newCaptureMetadataInterceptor()) instead.
        Captures the last received metadata for a stub. Useful for testing
        Parameters:
        stub - to capture for
        headersCapture - to record the last received headers
        trailersCapture - 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 headersCapture and trailersCapture.
      • 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 headers
        trailersCapture - to record the last received trailers
        Returns:
        an implementation of the channel with captures installed.