diff --git a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java index f1daabe363..cf440c9d73 100644 --- a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java +++ b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java @@ -134,7 +134,7 @@ public class ClientAuthInterceptorTests { Metadata.Headers headers = new Metadata.Headers(); interceptedCall.start(listener, headers); ArgumentCaptor statusCaptor = ArgumentCaptor.forClass(Status.class); - Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.Trailers.class)); + Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.class)); Assert.assertNull(headers.getAll(AUTHORIZATION)); Mockito.verify(call, never()).start(listener, headers); Assert.assertEquals(Status.Code.UNAUTHENTICATED, statusCaptor.getValue().getCode()); diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java index 222042920b..10b9bcae1b 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java @@ -254,7 +254,7 @@ public abstract class AbstractBenchmark { @Override public void onHalfClose() { - call.close(Status.OK, new Metadata.Trailers()); + call.close(Status.OK, new Metadata()); } @Override @@ -287,7 +287,7 @@ public abstract class AbstractBenchmark { @Override public void onHalfClose() { - call.close(Status.OK, new Metadata.Trailers()); + call.close(Status.OK, new Metadata()); } @Override @@ -323,7 +323,7 @@ public abstract class AbstractBenchmark { @Override public void onHalfClose() { - call.close(Status.OK, new Metadata.Trailers()); + call.close(Status.OK, new Metadata()); } @Override diff --git a/core/src/main/java/io/grpc/ChannelImpl.java b/core/src/main/java/io/grpc/ChannelImpl.java index 4691fc829f..1503fac890 100644 --- a/core/src/main/java/io/grpc/ChannelImpl.java +++ b/core/src/main/java/io/grpc/ChannelImpl.java @@ -475,7 +475,7 @@ public final class ChannelImpl extends Channel { @Override public ClientStream newStream( MethodDescriptor method, Headers headers, ClientStreamListener listener) { - listener.closed(shutdownStatus, new Metadata.Trailers()); + listener.closed(shutdownStatus, new Metadata()); return new ClientCallImpl.NoopClientStream(); } diff --git a/core/src/main/java/io/grpc/ClientCall.java b/core/src/main/java/io/grpc/ClientCall.java index 8ba20a1aa1..fdf32c1fc8 100644 --- a/core/src/main/java/io/grpc/ClientCall.java +++ b/core/src/main/java/io/grpc/ClientCall.java @@ -91,7 +91,7 @@ public abstract class ClientCall { * @param status the result of the remote call. * @param trailers metadata provided at call completion. */ - public abstract void onClose(Status status, Metadata.Trailers trailers); + public abstract void onClose(Status status, Metadata trailers); /** * This indicates that the ClientCall is now capable of sending additional messages (via diff --git a/core/src/main/java/io/grpc/ClientCallImpl.java b/core/src/main/java/io/grpc/ClientCallImpl.java index 32614326c7..19dcdcf4a9 100644 --- a/core/src/main/java/io/grpc/ClientCallImpl.java +++ b/core/src/main/java/io/grpc/ClientCallImpl.java @@ -201,7 +201,7 @@ final class ClientCallImpl extends ClientCall { private void closeCallPrematurely(ClientStreamListener listener, Status status) { Preconditions.checkState(stream == null, "Stream already created"); stream = new NoopClientStream(); - listener.closed(status, new Metadata.Trailers()); + listener.closed(status, new Metadata()); } private ScheduledFuture startDeadlineTimer(long timeoutMicros) { @@ -267,7 +267,7 @@ final class ClientCallImpl extends ClientCall { } @Override - public void closed(Status status, Metadata.Trailers trailers) { + public void closed(Status status, Metadata trailers) { if (status.getCode() == Status.Code.CANCELLED && deadlineNanoTime != null) { // When the server's deadline expires, it can only reset the stream with CANCEL and no // description. Since our timer may be delayed in firing, we double-check the deadline and @@ -276,11 +276,11 @@ final class ClientCallImpl extends ClientCall { if (deadlineNanoTime <= System.nanoTime()) { status = Status.DEADLINE_EXCEEDED; // Replace trailers to prevent mixing sources of status and trailers. - trailers = new Metadata.Trailers(); + trailers = new Metadata(); } } final Status savedStatus = status; - final Metadata.Trailers savedTrailers = trailers; + final Metadata savedTrailers = trailers; callExecutor.execute(new Runnable() { @Override public void run() { diff --git a/core/src/main/java/io/grpc/ClientInterceptors.java b/core/src/main/java/io/grpc/ClientInterceptors.java index 5cc7866c3a..ac7b847d40 100644 --- a/core/src/main/java/io/grpc/ClientInterceptors.java +++ b/core/src/main/java/io/grpc/ClientInterceptors.java @@ -164,7 +164,7 @@ public class ClientInterceptors { // to a NO-OP one to prevent the IllegalStateException. The user will finally get notified // about the error through the listener. delegate = (ClientCall) NOOP_CALL; - responseListener.onClose(Status.fromThrowable(e), new Metadata.Trailers()); + responseListener.onClose(Status.fromThrowable(e), new Metadata()); } } } diff --git a/core/src/main/java/io/grpc/ForwardingClientCallListener.java b/core/src/main/java/io/grpc/ForwardingClientCallListener.java index b92ab1e133..7a8f822403 100644 --- a/core/src/main/java/io/grpc/ForwardingClientCallListener.java +++ b/core/src/main/java/io/grpc/ForwardingClientCallListener.java @@ -52,7 +52,7 @@ public abstract class ForwardingClientCallListener extends ClientCall.Lis } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { delegate().onClose(status, trailers); } diff --git a/core/src/main/java/io/grpc/ForwardingServerCall.java b/core/src/main/java/io/grpc/ForwardingServerCall.java index f0a27bee03..9e67d09627 100644 --- a/core/src/main/java/io/grpc/ForwardingServerCall.java +++ b/core/src/main/java/io/grpc/ForwardingServerCall.java @@ -61,7 +61,7 @@ public abstract class ForwardingServerCall extends ServerCall { } @Override - public void close(Status status, Metadata.Trailers trailers) { + public void close(Status status, Metadata trailers) { delegate().close(status, trailers); } diff --git a/core/src/main/java/io/grpc/Metadata.java b/core/src/main/java/io/grpc/Metadata.java index 0de4eb2ff6..cf3041bfe6 100644 --- a/core/src/main/java/io/grpc/Metadata.java +++ b/core/src/main/java/io/grpc/Metadata.java @@ -56,7 +56,7 @@ import javax.annotation.concurrent.NotThreadSafe; *

*/ @NotThreadSafe -public abstract class Metadata { +public class Metadata { /** * All binary headers should have this suffix in their names. Vice versa. @@ -108,7 +108,7 @@ public abstract class Metadata { * Constructor called by the transport layer when it receives binary metadata. */ // TODO(louiscryan): Convert to use ByteString so we can cache transformations - private Metadata(byte[]... binaryValues) { + public Metadata(byte[]... binaryValues) { for (int i = 0; i < binaryValues.length; i++) { String name = new String(binaryValues[i], US_ASCII); storeAdd(name, new MetadataEntry(name.endsWith(BINARY_HEADER_SUFFIX), binaryValues[++i])); @@ -118,7 +118,7 @@ public abstract class Metadata { /** * Constructor called by the application layer when it wants to send metadata. */ - private Metadata() {} + public Metadata() {} private void storeAdd(String name, MetadataEntry value) { List values = store.get(name); @@ -286,6 +286,11 @@ public abstract class Metadata { } } + @Override + public String toString() { + return "Metadata(" + toStringInternal() + ")"; + } + private String toStringInternal() { return store.toString(); } @@ -375,31 +380,19 @@ public abstract class Metadata { /** * Concrete instance for metadata attached to the end of the call. Only provided by * servers. + * + * @deprecated use Metadata instead. */ + @Deprecated public static class Trailers extends Metadata { - /** - * Called by the transport layer to create trailers from their binary serialized values. - * - *

This method does not copy the provided byte arrays. The byte arrays must not be mutated. - */ - public Trailers(byte[]... headers) { - super(headers); - } - /** * Called by the application layer to construct trailers prior to passing them to the * transport for serialization. */ public Trailers() { } - - @Override - public String toString() { - return "Trailers(" + super.toStringInternal() + ")"; - } } - /** * Marshaller for metadata values that are serialized into raw binary. */ diff --git a/core/src/main/java/io/grpc/ServerCall.java b/core/src/main/java/io/grpc/ServerCall.java index 379155ffa1..d712862bb6 100644 --- a/core/src/main/java/io/grpc/ServerCall.java +++ b/core/src/main/java/io/grpc/ServerCall.java @@ -149,12 +149,12 @@ public abstract class ServerCall { * status} is not equal to {@link Status#OK}, then the call is said to have failed. * *

If {@code status} is not {@link Status#CANCELLED} and no errors or cancellations are known - * to have occured, then a {@link Listener#onComplete} notification should be expected. + * to have occurred, then a {@link Listener#onComplete} notification should be expected. * Otherwise {@link Listener#onCancel} has been or will be called. * * @throws IllegalStateException if call is already {@code close}d */ - public abstract void close(Status status, Metadata.Trailers trailers); + public abstract void close(Status status, Metadata trailers); /** * Returns {@code true} when the call is cancelled and the server is encouraged to abort diff --git a/core/src/main/java/io/grpc/ServerImpl.java b/core/src/main/java/io/grpc/ServerImpl.java index 6d94801990..a1f71d7f0d 100644 --- a/core/src/main/java/io/grpc/ServerImpl.java +++ b/core/src/main/java/io/grpc/ServerImpl.java @@ -308,14 +308,14 @@ public final class ServerImpl extends Server { if (method == null) { stream.close( Status.UNIMPLEMENTED.withDescription("Method not found: " + methodName), - new Metadata.Trailers()); + new Metadata()); timeout.cancel(true); return; } listener = startCall(stream, methodName, method.getMethodDefinition(), timeout, headers); } catch (Throwable t) { - stream.close(Status.fromThrowable(t), new Metadata.Trailers()); + stream.close(Status.fromThrowable(t), new Metadata()); timeout.cancel(true); throw Throwables.propagate(t); } finally { @@ -410,9 +410,9 @@ public final class ServerImpl extends Server { } /** - * Like {@link ServerCall#close(Status, Metadata.Trailers)}, but thread-safe for internal use. + * Like {@link ServerCall#close(Status, Metadata)}, but thread-safe for internal use. */ - private void internalClose(Status status, Metadata.Trailers trailers) { + private void internalClose(Status status, Metadata trailers) { // TODO(ejona86): this is not thread-safe :) stream.close(status, trailers); } @@ -425,7 +425,7 @@ public final class ServerImpl extends Server { try { getListener().messageRead(message); } catch (Throwable t) { - internalClose(Status.fromThrowable(t), new Metadata.Trailers()); + internalClose(Status.fromThrowable(t), new Metadata()); throw Throwables.propagate(t); } } @@ -440,7 +440,7 @@ public final class ServerImpl extends Server { try { getListener().halfClosed(); } catch (Throwable t) { - internalClose(Status.fromThrowable(t), new Metadata.Trailers()); + internalClose(Status.fromThrowable(t), new Metadata()); throw Throwables.propagate(t); } } @@ -504,7 +504,7 @@ public final class ServerImpl extends Server { stream.writeMessage(resp); stream.flush(); } catch (Throwable t) { - close(Status.fromThrowable(t), new Metadata.Trailers()); + close(Status.fromThrowable(t), new Metadata()); throw Throwables.propagate(t); } } @@ -515,7 +515,7 @@ public final class ServerImpl extends Server { } @Override - public void close(Status status, Metadata.Trailers trailers) { + public void close(Status status, Metadata trailers) { Preconditions.checkState(!closeCalled, "call already closed"); closeCalled = true; stream.close(status, trailers); diff --git a/core/src/main/java/io/grpc/inprocess/InProcessTransport.java b/core/src/main/java/io/grpc/inprocess/InProcessTransport.java index d7bc19c386..7630690107 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessTransport.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessTransport.java @@ -107,7 +107,7 @@ class InProcessTransport implements ServerTransport, ClientTransport { public synchronized ClientStream newStream(MethodDescriptor method, Metadata.Headers headers, ClientStreamListener clientStreamListener) { if (shutdownStatus != null) { - clientStreamListener.closed(shutdownStatus, new Metadata.Trailers()); + clientStreamListener.closed(shutdownStatus, new Metadata()); return new NoopClientStream(); } InProcessStream stream = new InProcessStream(); @@ -195,7 +195,7 @@ class InProcessTransport implements ServerTransport, ClientTransport { @GuardedBy("this") private Status clientNotifyStatus; @GuardedBy("this") - private Metadata.Trailers clientNotifyTrailers; + private Metadata clientNotifyTrailers; // Only is intended to prevent double-close when client cancels. @GuardedBy("this") private boolean closed; @@ -266,7 +266,7 @@ class InProcessTransport implements ServerTransport, ClientTransport { } @Override - public void close(Status status, Metadata.Trailers trailers) { + public void close(Status status, Metadata trailers) { synchronized (this) { if (closed) { return; @@ -306,7 +306,7 @@ class InProcessTransport implements ServerTransport, ClientTransport { log.log(Level.WARNING, "Exception closing stream", t); } } - clientStreamListener.closed(status, new Metadata.Trailers()); + clientStreamListener.closed(status, new Metadata()); return true; } } diff --git a/core/src/main/java/io/grpc/internal/AbstractClientStream.java b/core/src/main/java/io/grpc/internal/AbstractClientStream.java index 972b2aa09f..4475b37156 100644 --- a/core/src/main/java/io/grpc/internal/AbstractClientStream.java +++ b/core/src/main/java/io/grpc/internal/AbstractClientStream.java @@ -59,7 +59,7 @@ public abstract class AbstractClientStream extends AbstractStream // Stored status & trailers to report when deframer completes or // transportReportStatus is directly called. private Status status; - private Metadata.Trailers trailers; + private Metadata trailers; private Runnable closeListenerTask; @@ -100,7 +100,7 @@ public abstract class AbstractClientStream extends AbstractStream } // For transport errors we immediately report status to the application layer // and do not wait for additional payloads. - transportReportStatus(errorStatus, false, new Metadata.Trailers()); + transportReportStatus(errorStatus, false, new Metadata()); } /** @@ -165,7 +165,7 @@ public abstract class AbstractClientStream extends AbstractStream * @param trailers the received trailers * @param status the status extracted from the trailers */ - protected void inboundTrailersReceived(Metadata.Trailers trailers, Status status) { + protected void inboundTrailersReceived(Metadata trailers, Status status) { Preconditions.checkNotNull(trailers, "trailers"); if (inboundPhase() == Phase.STATUS) { log.log(Level.INFO, "Received trailers on closed stream {0}\n {1}\n {2}", @@ -212,7 +212,7 @@ public abstract class AbstractClientStream extends AbstractStream * @param trailers new instance of {@code Trailers}, either empty or those returned by the server */ public void transportReportStatus(final Status newStatus, boolean stopDelivery, - final Metadata.Trailers trailers) { + final Metadata trailers) { Preconditions.checkNotNull(newStatus, "newStatus"); boolean closingLater = closeListenerTask != null && !stopDelivery; @@ -240,7 +240,7 @@ public abstract class AbstractClientStream extends AbstractStream /** * Creates a new {@link Runnable} to close the listener with the given status/trailers. */ - private Runnable newCloseListenerTask(final Status status, final Metadata.Trailers trailers) { + private Runnable newCloseListenerTask(final Status status, final Metadata trailers) { return new Runnable() { @Override public void run() { @@ -252,7 +252,7 @@ public abstract class AbstractClientStream extends AbstractStream /** * Closes the listener if not previously closed. */ - private void closeListener(Status newStatus, Metadata.Trailers trailers) { + private void closeListener(Status newStatus, Metadata trailers) { if (!listenerClosed) { listenerClosed = true; closeDeframer(); diff --git a/core/src/main/java/io/grpc/internal/AbstractServerStream.java b/core/src/main/java/io/grpc/internal/AbstractServerStream.java index 51a8680007..222b322df5 100644 --- a/core/src/main/java/io/grpc/internal/AbstractServerStream.java +++ b/core/src/main/java/io/grpc/internal/AbstractServerStream.java @@ -61,7 +61,7 @@ public abstract class AbstractServerStream extends AbstractStream */ private boolean gracefulClose; /** Saved trailers from close() that need to be sent once the framer has sent all messages. */ - private Metadata.Trailers stashedTrailers; + private Metadata stashedTrailers; protected AbstractServerStream(WritableBufferAllocator bufferAllocator) { super(bufferAllocator); @@ -109,7 +109,7 @@ public abstract class AbstractServerStream extends AbstractStream } @Override - public final void close(Status status, Metadata.Trailers trailers) { + public final void close(Status status, Metadata trailers) { Preconditions.checkNotNull(status, "status"); Preconditions.checkNotNull(trailers, "trailers"); if (outboundPhase(Phase.STATUS) != Phase.STATUS) { @@ -187,7 +187,7 @@ public abstract class AbstractServerStream extends AbstractStream * @param trailers metadata to be sent to end point * @param headersSent {@code true} if response headers have already been sent. */ - protected abstract void sendTrailers(Metadata.Trailers trailers, boolean headersSent); + protected abstract void sendTrailers(Metadata trailers, boolean headersSent); /** * Indicates the stream is considered completely closed and there is no further opportunity for @@ -216,7 +216,7 @@ public abstract class AbstractServerStream extends AbstractStream * Aborts the stream with an error status, cleans up resources and notifies the listener if * necessary. * - *

Unlike {@link #close(Status, Metadata.Trailers)}, this method is only called from the + *

Unlike {@link #close(Status, Metadata)}, this method is only called from the * transport. The transport should use this method instead of {@code close(Status)} for internal * errors to prevent exposing unexpected states and exceptions to the application. * @@ -232,7 +232,7 @@ public abstract class AbstractServerStream extends AbstractStream if (notifyClient) { // TODO(louiscryan): Remove if (stashedTrailers == null) { - stashedTrailers = new Metadata.Trailers(); + stashedTrailers = new Metadata(); } writeStatusToTrailers(status); closeFramer(); diff --git a/core/src/main/java/io/grpc/internal/ClientStreamListener.java b/core/src/main/java/io/grpc/internal/ClientStreamListener.java index 1e229a61d3..017b8af97f 100644 --- a/core/src/main/java/io/grpc/internal/ClientStreamListener.java +++ b/core/src/main/java/io/grpc/internal/ClientStreamListener.java @@ -40,7 +40,7 @@ public interface ClientStreamListener extends StreamListener { * Called upon receiving all header information from the remote end-point. Note that transports * are not required to call this method if no header information is received, this would occur * when a stream immediately terminates with an error and only - * {@link #closed(io.grpc.Status, Metadata.Trailers)} is called. + * {@link #closed(io.grpc.Status, Metadata)} is called. * *

This method should return quickly, as the same thread may be used to process other streams. * @@ -60,5 +60,5 @@ public interface ClientStreamListener extends StreamListener { * @param status details about the remote closure * @param trailers trailing metadata */ - void closed(Status status, Metadata.Trailers trailers); + void closed(Status status, Metadata trailers); } diff --git a/core/src/main/java/io/grpc/internal/Http2ClientStream.java b/core/src/main/java/io/grpc/internal/Http2ClientStream.java index 2114339b5c..563f18921e 100644 --- a/core/src/main/java/io/grpc/internal/Http2ClientStream.java +++ b/core/src/main/java/io/grpc/internal/Http2ClientStream.java @@ -145,7 +145,7 @@ public abstract class Http2ClientStream extends AbstractClientStream { * * @param trailers the received terminal trailer metadata */ - protected void transportTrailersReceived(Metadata.Trailers trailers) { + protected void transportTrailersReceived(Metadata trailers) { Preconditions.checkNotNull(trailers); if (transportError != null) { // Already received a transport error so just augment it. @@ -176,7 +176,7 @@ public abstract class Http2ClientStream extends AbstractClientStream { /** * Extract the response status from trailers. */ - private Status statusFromTrailers(Metadata.Trailers trailers) { + private Status statusFromTrailers(Metadata trailers) { Status status = trailers.get(Status.CODE_KEY); if (status == null) { status = statusFromHttpStatus(trailers); diff --git a/core/src/main/java/io/grpc/internal/ServerStream.java b/core/src/main/java/io/grpc/internal/ServerStream.java index 717ce2f38a..249f362a33 100644 --- a/core/src/main/java/io/grpc/internal/ServerStream.java +++ b/core/src/main/java/io/grpc/internal/ServerStream.java @@ -58,7 +58,7 @@ public interface ServerStream extends Stream { * @param status details of the closure * @param trailers an additional block of metadata to pass to the client on stream closure. */ - void close(Status status, Metadata.Trailers trailers); + void close(Status status, Metadata trailers); /** diff --git a/core/src/test/java/io/grpc/ChannelImplTest.java b/core/src/test/java/io/grpc/ChannelImplTest.java index dd4d390976..02fc62381e 100644 --- a/core/src/test/java/io/grpc/ChannelImplTest.java +++ b/core/src/test/java/io/grpc/ChannelImplTest.java @@ -137,7 +137,7 @@ public class ChannelImplTest { channel.newCall(method, CallOptions.DEFAULT.withDeadlineNanoTime(System.nanoTime())); call.start(mockCallListener, new Metadata.Headers()); verify(mockCallListener, timeout(1000)).onClose( - same(Status.DEADLINE_EXCEEDED), any(Metadata.Trailers.class)); + same(Status.DEADLINE_EXCEEDED), any(Metadata.class)); } @Test @@ -179,7 +179,7 @@ public class ChannelImplTest { verify(mockTransport) .newStream(same(method), same(headers2), streamListenerCaptor.capture()); ClientStreamListener streamListener2 = streamListenerCaptor.getValue(); - Metadata.Trailers trailers = new Metadata.Trailers(); + Metadata trailers = new Metadata(); streamListener2.closed(Status.CANCELLED, trailers); verify(mockCallListener2, timeout(1000)).onClose(Status.CANCELLED, trailers); @@ -194,7 +194,7 @@ public class ChannelImplTest { call3.start(mockCallListener3, new Metadata.Headers()); ArgumentCaptor statusCaptor = ArgumentCaptor.forClass(Status.class); verify(mockCallListener3, timeout(1000)) - .onClose(statusCaptor.capture(), any(Metadata.Trailers.class)); + .onClose(statusCaptor.capture(), any(Metadata.class)); assertSame(Status.Code.UNAVAILABLE, statusCaptor.getValue().getCode()); // Finish shutdown @@ -227,7 +227,7 @@ public class ChannelImplTest { verify(mockTransport).start(any(ClientTransport.Listener.class)); ArgumentCaptor statusCaptor = ArgumentCaptor.forClass(Status.class); verify(mockCallListener, timeout(1000)) - .onClose(statusCaptor.capture(), any(Metadata.Trailers.class)); + .onClose(statusCaptor.capture(), any(Metadata.class)); assertSame(goldenStatus, statusCaptor.getValue()); // Have transport shutdown immediately during start @@ -251,7 +251,7 @@ public class ChannelImplTest { verify(mockTransportFactory, times(2)).newClientTransport(); verify(mockTransport2).start(any(ClientTransport.Listener.class)); verify(mockTransport2).newStream(same(method), same(headers2), streamListenerCaptor.capture()); - Metadata.Trailers trailers2 = new Metadata.Trailers(); + Metadata trailers2 = new Metadata(); streamListenerCaptor.getValue().closed(Status.CANCELLED, trailers2); verify(mockCallListener2, timeout(1000)).onClose(Status.CANCELLED, trailers2); @@ -267,7 +267,7 @@ public class ChannelImplTest { verify(mockTransportFactory, times(3)).newClientTransport(); verify(mockTransport3).start(transportListenerCaptor.capture()); verify(mockTransport3).newStream(same(method), same(headers3), streamListenerCaptor.capture()); - Metadata.Trailers trailers3 = new Metadata.Trailers(); + Metadata trailers3 = new Metadata(); streamListenerCaptor.getValue().closed(Status.CANCELLED, trailers3); verify(mockCallListener3, timeout(1000)).onClose(Status.CANCELLED, trailers3); diff --git a/core/src/test/java/io/grpc/ClientInterceptorsTest.java b/core/src/test/java/io/grpc/ClientInterceptorsTest.java index f7a01312c6..1eab4ae7d2 100644 --- a/core/src/test/java/io/grpc/ClientInterceptorsTest.java +++ b/core/src/test/java/io/grpc/ClientInterceptorsTest.java @@ -347,7 +347,7 @@ public class ClientInterceptorsTest { interceptedCall.request(1); verifyNoMoreInteractions(call); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); - verify(listener).onClose(captor.capture(), any(Metadata.Trailers.class)); + verify(listener).onClose(captor.capture(), any(Metadata.class)); assertSame(error, captor.getValue().getCause()); } diff --git a/core/src/test/java/io/grpc/MetadataTest.java b/core/src/test/java/io/grpc/MetadataTest.java index b54b6b6fba..1cac7af917 100644 --- a/core/src/test/java/io/grpc/MetadataTest.java +++ b/core/src/test/java/io/grpc/MetadataTest.java @@ -203,13 +203,13 @@ public class MetadataTest { assertEquals("Headers(path=/path,authority=myauthority," + "metadata={test-bin=[Fish(binary)], test=[ascii]})", h.toString()); - Metadata.Trailers t = new Metadata.Trailers(); + Metadata t = new Metadata(); t.put(Metadata.Key.of("test", Metadata.ASCII_STRING_MARSHALLER), "ascii"); - assertEquals("Trailers({test=[ascii]})", t.toString()); + assertEquals("Metadata({test=[ascii]})", t.toString()); - t = new Metadata.Trailers("test".getBytes(US_ASCII), "ascii".getBytes(US_ASCII), + t = new Metadata("test".getBytes(US_ASCII), "ascii".getBytes(US_ASCII), "test-bin".getBytes(US_ASCII), "binary".getBytes(US_ASCII)); - assertEquals("Trailers({test=[ascii], test-bin=[[98, 105, 110, 97, 114, 121]]})", t.toString()); + assertEquals("Metadata({test=[ascii], test-bin=[[98, 105, 110, 97, 114, 121]]})", t.toString()); } @Test diff --git a/core/src/test/java/io/grpc/ServerImplTest.java b/core/src/test/java/io/grpc/ServerImplTest.java index b7a9e4d708..2618cbf804 100644 --- a/core/src/test/java/io/grpc/ServerImplTest.java +++ b/core/src/test/java/io/grpc/ServerImplTest.java @@ -227,7 +227,7 @@ public class ServerImplTest { verify(stream, times(2)).flush(); assertEquals(50, INTEGER_MARSHALLER.parse(inputCaptor.getValue()).intValue()); - Metadata.Trailers trailers = new Metadata.Trailers(); + Metadata trailers = new Metadata(); trailers.put(metadataKey, 3); Status status = Status.OK.withDescription("A okay"); call.close(status, trailers); @@ -268,7 +268,7 @@ public class ServerImplTest { barrier.await(); executeBarrier(executor).await(); - verify(stream).close(same(status), notNull(Metadata.Trailers.class)); + verify(stream).close(same(status), notNull(Metadata.class)); verifyNoMoreInteractions(stream); } diff --git a/examples/src/main/java/io/grpc/examples/header/HeaderServerInterceptor.java b/examples/src/main/java/io/grpc/examples/header/HeaderServerInterceptor.java index 57c10ac3cf..558360b043 100644 --- a/examples/src/main/java/io/grpc/examples/header/HeaderServerInterceptor.java +++ b/examples/src/main/java/io/grpc/examples/header/HeaderServerInterceptor.java @@ -78,7 +78,7 @@ public class HeaderServerInterceptor implements ServerInterceptor { } @Override - public void close(Status status, Metadata.Trailers trailers) { + public void close(Status status, Metadata trailers) { super.close(status, trailers); } }, requestHeaders); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java index c1d61cf040..dfa875111e 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java @@ -456,7 +456,7 @@ public abstract class AbstractTransportTest { } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { queue.add(status); } }, new Metadata.Headers()); @@ -527,7 +527,7 @@ public abstract class AbstractTransportTest { fixedHeaders.put(METADATA_KEY, contextValue); stub = MetadataUtils.attachHeaders(stub, fixedHeaders); // .. and expect it to be echoed back in trailers - AtomicReference trailersCapture = new AtomicReference(); + AtomicReference trailersCapture = new AtomicReference(); AtomicReference headersCapture = new AtomicReference(); stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture); @@ -550,7 +550,7 @@ public abstract class AbstractTransportTest { fixedHeaders.put(METADATA_KEY, contextValue); stub = MetadataUtils.attachHeaders(stub, fixedHeaders); // .. and expect it to be echoed back in trailers - AtomicReference trailersCapture = new AtomicReference(); + AtomicReference trailersCapture = new AtomicReference(); AtomicReference headersCapture = new AtomicReference(); stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture); diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java index 37d92ccdfc..9d6ed05835 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java @@ -216,7 +216,7 @@ class NettyClientHandler extends Http2ConnectionHandler { private void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { NettyClientStream stream = clientStream(requireHttp2Stream(streamId)); Status status = HttpUtil.Http2Error.statusForCode((int) errorCode); - stream.transportReportStatus(status, false, new Metadata.Trailers()); + stream.transportReportStatus(status, false, new Metadata()); } @Override @@ -238,7 +238,7 @@ class NettyClientHandler extends Http2ConnectionHandler { connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { - clientStream(stream).transportReportStatus(goAwayStatus, false, new Metadata.Trailers()); + clientStream(stream).transportReportStatus(goAwayStatus, false, new Metadata()); return true; } }); @@ -274,7 +274,7 @@ class NettyClientHandler extends Http2ConnectionHandler { Http2Stream stream = connection().stream(http2Ex.streamId()); if (stream != null) { clientStream(stream).transportReportStatus(Status.fromThrowable(cause), false, - new Metadata.Trailers()); + new Metadata()); } // Delegate to the base class to send a RST_STREAM. @@ -315,10 +315,10 @@ class NettyClientHandler extends Http2ConnectionHandler { if (future.cause() instanceof GoAwayClosedStreamException) { GoAwayClosedStreamException e = (GoAwayClosedStreamException) future.cause(); goAwayStatus(statusFromGoAway(e.errorCode(), e.debugData())); - stream.transportReportStatus(goAwayStatus, false, new Metadata.Trailers()); + stream.transportReportStatus(goAwayStatus, false, new Metadata()); } else { stream.transportReportStatus(Status.fromThrowable(future.cause()), true, - new Metadata.Trailers()); + new Metadata()); } } } @@ -331,7 +331,7 @@ class NettyClientHandler extends Http2ConnectionHandler { private void cancelStream(ChannelHandlerContext ctx, CancelClientStreamCommand cmd, ChannelPromise promise) { NettyClientStream stream = cmd.stream(); - stream.transportReportStatus(cmd.reason(), true, new Metadata.Trailers()); + stream.transportReportStatus(cmd.reason(), true, new Metadata()); encoder().writeRstStream(ctx, stream.id(), Http2Error.CANCEL.code(), promise); } @@ -402,7 +402,7 @@ class NettyClientHandler extends Http2ConnectionHandler { public boolean visit(Http2Stream stream) throws Http2Exception { if (stream.id() > lastKnownStream) { clientStream(stream) - .transportReportStatus(goAwayStatus, false, new Metadata.Trailers()); + .transportReportStatus(goAwayStatus, false, new Metadata()); stream.close(); } return true; diff --git a/netty/src/main/java/io/grpc/netty/NettyClientTransport.java b/netty/src/main/java/io/grpc/netty/NettyClientTransport.java index edde9f6a68..a256c77825 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientTransport.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientTransport.java @@ -139,7 +139,7 @@ class NettyClientTransport implements ClientTransport { if (!future.isSuccess()) { // Stream creation failed. Close the stream if not already closed. stream.transportReportStatus(Status.fromThrowable(future.cause()), true, - new Metadata.Trailers()); + new Metadata()); } } }; diff --git a/netty/src/main/java/io/grpc/netty/NettyServerStream.java b/netty/src/main/java/io/grpc/netty/NettyServerStream.java index 2646ba68d1..548d5a9b01 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerStream.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerStream.java @@ -112,7 +112,7 @@ class NettyServerStream extends AbstractServerStream { } @Override - protected void sendTrailers(Metadata.Trailers trailers, boolean headersSent) { + protected void sendTrailers(Metadata trailers, boolean headersSent) { Http2Headers http2Trailers = Utils.convertTrailers(trailers, headersSent); writeQueue.enqueue(new SendResponseHeadersCommand(id(), http2Trailers, true), true); } diff --git a/netty/src/main/java/io/grpc/netty/Utils.java b/netty/src/main/java/io/grpc/netty/Utils.java index 9092e65514..14bdc37b7e 100644 --- a/netty/src/main/java/io/grpc/netty/Utils.java +++ b/netty/src/main/java/io/grpc/netty/Utils.java @@ -142,11 +142,11 @@ class Utils { return http2Headers; } - public static Metadata.Trailers convertTrailers(Http2Headers http2Headers) { - return new Metadata.Trailers(convertHeadersToArray(http2Headers)); + public static Metadata convertTrailers(Http2Headers http2Headers) { + return new Metadata(convertHeadersToArray(http2Headers)); } - public static Http2Headers convertTrailers(Metadata.Trailers trailers, boolean headersSent) { + public static Http2Headers convertTrailers(Metadata trailers, boolean headersSent) { Http2Headers http2Trailers = convertMetadata(trailers); if (!headersSent) { http2Trailers.set(Utils.CONTENT_TYPE_HEADER, Utils.CONTENT_TYPE_GRPC); diff --git a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java index 2f176a3deb..2817d24287 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java @@ -183,7 +183,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { assertTrue(createPromise.isSuccess()); verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true), - any(Metadata.Trailers.class)); + any(Metadata.class)); } @Test @@ -341,7 +341,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { assertTrue(promise.isDone()); assertFalse(promise.isSuccess()); verify(stream).transportReportStatus(any(Status.class), eq(false), - notNull(Metadata.Trailers.class)); + notNull(Metadata.class)); } @Test @@ -353,7 +353,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { goAwayFrame(0, 8 /* Cancel */, Unpooled.copiedBuffer("this is a test", UTF_8))); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); verify(stream).transportReportStatus(captor.capture(), eq(false), - notNull(Metadata.Trailers.class)); + notNull(Metadata.class)); assertEquals(Status.CANCELLED.getCode(), captor.getValue().getCode()); assertEquals("HTTP/2 error code: CANCEL\nthis is a test", captor.getValue().getDescription()); @@ -371,7 +371,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { goAwayFrame(0, 8 /* Cancel */, Unpooled.copiedBuffer("this is a test", UTF_8))); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); verify(stream).transportReportStatus(captor.capture(), eq(false), - notNull(Metadata.Trailers.class)); + notNull(Metadata.class)); assertEquals(Status.CANCELLED.getCode(), captor.getValue().getCode()); assertEquals("HTTP/2 error code: CANCEL\nthis is a test", captor.getValue().getDescription()); @@ -385,7 +385,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { when(stream.id()).thenReturn(3); writeQueue.enqueue(new CancelClientStreamCommand(stream, Status.CANCELLED), true); verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true), - any(Metadata.Trailers.class)); + any(Metadata.class)); } @Test @@ -406,7 +406,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); InOrder inOrder = inOrder(stream); inOrder.verify(stream, calls(1)).transportReportStatus(captor.capture(), eq(false), - notNull(Metadata.Trailers.class)); + notNull(Metadata.class)); assertEquals(Status.UNAVAILABLE.getCode(), captor.getValue().getCode()); } diff --git a/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java b/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java index e6d9caf719..b2ae1cc62e 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java @@ -160,35 +160,35 @@ public class NettyClientStreamTest extends NettyStreamTestBase { @Test public void setStatusWithOkShouldCloseStream() { stream().id(STREAM_ID); - stream().transportReportStatus(Status.OK, true, new Metadata.Trailers()); - verify(listener).closed(same(Status.OK), any(Metadata.Trailers.class)); + stream().transportReportStatus(Status.OK, true, new Metadata()); + verify(listener).closed(same(Status.OK), any(Metadata.class)); assertTrue(stream.isClosed()); } @Test public void setStatusWithErrorShouldCloseStream() { Status errorStatus = Status.INTERNAL; - stream().transportReportStatus(errorStatus, true, new Metadata.Trailers()); - verify(listener).closed(eq(errorStatus), any(Metadata.Trailers.class)); + stream().transportReportStatus(errorStatus, true, new Metadata()); + verify(listener).closed(eq(errorStatus), any(Metadata.class)); assertTrue(stream.isClosed()); } @Test public void setStatusWithOkShouldNotOverrideError() { Status errorStatus = Status.INTERNAL; - stream().transportReportStatus(errorStatus, true, new Metadata.Trailers()); - stream().transportReportStatus(Status.OK, true, new Metadata.Trailers()); - verify(listener).closed(any(Status.class), any(Metadata.Trailers.class)); + stream().transportReportStatus(errorStatus, true, new Metadata()); + stream().transportReportStatus(Status.OK, true, new Metadata()); + verify(listener).closed(any(Status.class), any(Metadata.class)); assertTrue(stream.isClosed()); } @Test public void setStatusWithErrorShouldNotOverridePreviousError() { Status errorStatus = Status.INTERNAL; - stream().transportReportStatus(errorStatus, true, new Metadata.Trailers()); + stream().transportReportStatus(errorStatus, true, new Metadata()); stream().transportReportStatus(Status.fromThrowable(new RuntimeException("fake")), true, - new Metadata.Trailers()); - verify(listener).closed(any(Status.class), any(Metadata.Trailers.class)); + new Metadata()); + verify(listener).closed(any(Status.class), any(Metadata.class)); assertTrue(stream.isClosed()); } @@ -226,7 +226,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { stream().transportHeadersReceived(grpcResponseTrailers(Status.INTERNAL), true); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); - verify(listener).closed(captor.capture(), any(Metadata.Trailers.class)); + verify(listener).closed(captor.capture(), any(Metadata.class)); assertEquals(Status.INTERNAL.getCode(), captor.getValue().getCode()); assertTrue(stream.isClosed()); } @@ -239,7 +239,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { // Remove once b/16290036 is fixed. headers.status(new AsciiString("500")); stream().transportHeadersReceived(headers, false); - verify(listener, never()).closed(any(Status.class), any(Metadata.Trailers.class)); + verify(listener, never()).closed(any(Status.class), any(Metadata.class)); // We are now waiting for 100 bytes of error context on the stream, cancel has not yet been // sent @@ -251,7 +251,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { // Now verify that cancel is sent and an error is reported to the listener verify(writeQueue).enqueue(any(CancelClientStreamCommand.class), eq(true)); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); - verify(listener).closed(captor.capture(), any(Metadata.Trailers.class)); + verify(listener).closed(captor.capture(), any(Metadata.class)); assertEquals(Status.UNKNOWN.getCode(), captor.getValue().getCode()); assertTrue(stream.isClosed()); @@ -261,7 +261,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { public void nonGrpcResponseShouldSetStatus() throws Exception { stream().transportDataReceived(Unpooled.copiedBuffer(MESSAGE, UTF_8), true); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); - verify(listener).closed(captor.capture(), any(Metadata.Trailers.class)); + verify(listener).closed(captor.capture(), any(Metadata.class)); assertEquals(Status.Code.INTERNAL, captor.getValue().getCode()); } @@ -288,7 +288,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { verify(listener).messageRead(any(InputStream.class)); // Now set the error status. - Metadata.Trailers trailers = Utils.convertTrailers(grpcResponseTrailers(Status.CANCELLED)); + Metadata trailers = Utils.convertTrailers(grpcResponseTrailers(Status.CANCELLED)); stream().transportReportStatus(Status.CANCELLED, true, trailers); // Now allow the delivery of the second. @@ -314,7 +314,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { verify(listener).messageRead(any(InputStream.class)); ArgumentCaptor captor = ArgumentCaptor.forClass(Status.class); - verify(listener).closed(captor.capture(), any(Metadata.Trailers.class)); + verify(listener).closed(captor.capture(), any(Metadata.class)); assertEquals(Status.Code.INTERNAL, captor.getValue().getCode()); } @@ -372,7 +372,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase { } private Http2Headers grpcResponseTrailers(Status status) { - Metadata.Trailers trailers = new Metadata.Trailers(); + Metadata trailers = new Metadata(); trailers.put(Status.CODE_KEY, status); return Utils.convertTrailers(trailers, true); } diff --git a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java index 61835e5aee..f815970da4 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java @@ -282,7 +282,7 @@ public class NettyClientTransportTest { } @Override - public void closed(Status status, Metadata.Trailers trailers) { + public void closed(Status status, Metadata trailers) { if (status.isOk()) { closedFuture.set(null); } else { @@ -328,7 +328,7 @@ public class NettyClientTransportTest { @Override public void halfClosed() { // Just close when the client closes. - stream.close(Status.OK, new Metadata.Trailers()); + stream.close(Status.OK, new Metadata()); } @Override diff --git a/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java b/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java index 89cc124ac7..c9a7a1ece7 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java @@ -76,7 +76,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase { @Mock private NettyServerHandler handler; - private Metadata.Trailers trailers = new Metadata.Trailers(); + private Metadata trailers = new Metadata(); @Before @Override @@ -126,7 +126,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase { @Test public void closeBeforeClientHalfCloseShouldSucceed() throws Exception { - stream().close(Status.OK, new Metadata.Trailers()); + stream().close(Status.OK, new Metadata()); verify(writeQueue).enqueue( new SendResponseHeadersCommand(STREAM_ID, new DefaultHttp2Headers() .status(new AsciiString("200")) @@ -224,7 +224,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase { @Test public void emptyFramerShouldSendNoPayload() throws Exception { - stream().close(Status.OK, new Metadata.Trailers()); + stream().close(Status.OK, new Metadata()); verify(writeQueue).enqueue( new SendResponseHeadersCommand(STREAM_ID, new DefaultHttp2Headers() .status(new AsciiString("200")) @@ -265,7 +265,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase { @Override protected void closeStream() { - stream().close(Status.ABORTED, new Metadata.Trailers()); + stream().close(Status.ABORTED, new Metadata()); } @Override diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java index 21abb7b32f..df2bed9cac 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java @@ -245,7 +245,7 @@ class OkHttpClientStream extends Http2ClientStream { data.buffer.clear(); } pendingData = null; - transportReportStatus(reason, true, new Metadata.Trailers()); + transportReportStatus(reason, true, new Metadata()); } else { transport.finishStream(id(), reason, ErrorCode.CANCEL); } diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java index 4c64d88db3..216c89ff18 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java @@ -254,7 +254,7 @@ class OkHttpClientTransport implements ClientTransport { synchronized (lock) { if (goAway) { - clientStream.transportReportStatus(goAwayStatus, true, new Metadata.Trailers()); + clientStream.transportReportStatus(goAwayStatus, true, new Metadata()); } else if (streams.size() >= maxConcurrentStreams) { pendingStreams.add(clientStream); } else { @@ -459,12 +459,12 @@ class OkHttpClientTransport implements ClientTransport { Map.Entry entry = it.next(); if (entry.getKey() > lastKnownStreamId) { it.remove(); - entry.getValue().transportReportStatus(status, false, new Metadata.Trailers()); + entry.getValue().transportReportStatus(status, false, new Metadata()); } } for (OkHttpClientStream stream : pendingStreams) { - stream.transportReportStatus(status, true, new Metadata.Trailers()); + stream.transportReportStatus(status, true, new Metadata()); } pendingStreams.clear(); } @@ -501,7 +501,7 @@ class OkHttpClientTransport implements ClientTransport { if (status != null) { boolean isCancelled = (status.getCode() == Code.CANCELLED || status.getCode() == Code.DEADLINE_EXCEEDED); - stream.transportReportStatus(status, isCancelled, new Metadata.Trailers()); + stream.transportReportStatus(status, isCancelled, new Metadata()); } if (!startPendingStreams()) { stopIfNecessary(); diff --git a/okhttp/src/main/java/io/grpc/okhttp/Utils.java b/okhttp/src/main/java/io/grpc/okhttp/Utils.java index 5daf74f1f3..1fd162fcde 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/Utils.java +++ b/okhttp/src/main/java/io/grpc/okhttp/Utils.java @@ -49,8 +49,8 @@ class Utils { return new Metadata.Headers(convertHeadersToArray(http2Headers)); } - public static Metadata.Trailers convertTrailers(List

http2Headers) { - return new Metadata.Trailers(convertHeadersToArray(http2Headers)); + public static Metadata convertTrailers(List
http2Headers) { + return new Metadata(convertHeadersToArray(http2Headers)); } private static byte[][] convertHeadersToArray(List
http2Headers) { diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java index 53889800cc..3e2d6bf295 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java @@ -1254,7 +1254,7 @@ public class OkHttpClientTransportTest { private static class MockStreamListener implements ClientStreamListener { Status status; Metadata.Headers headers; - Metadata.Trailers trailers; + Metadata trailers; CountDownLatch closed = new CountDownLatch(1); ArrayList messages = new ArrayList(); boolean onReadyCalled; @@ -1276,7 +1276,7 @@ public class OkHttpClientTransportTest { } @Override - public void closed(Status status, Metadata.Trailers trailers) { + public void closed(Status status, Metadata trailers) { this.status = status; this.trailers = trailers; closed.countDown(); diff --git a/stub/src/main/java/io/grpc/stub/ClientCalls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java index 865d71c893..e54be3f6ae 100644 --- a/stub/src/main/java/io/grpc/stub/ClientCalls.java +++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java @@ -257,7 +257,7 @@ public class ClientCalls { } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { if (status.isOk()) { observer.onCompleted(); } else { @@ -291,7 +291,7 @@ public class ClientCalls { } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { if (status.isOk()) { if (value == null) { // No value received so mark the future as an error @@ -403,7 +403,7 @@ public class ClientCalls { } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { Preconditions.checkState(!done, "ClientCall already closed"); if (status.isOk()) { buffer.add(BlockingResponseStream.this); diff --git a/stub/src/main/java/io/grpc/stub/MetadataUtils.java b/stub/src/main/java/io/grpc/stub/MetadataUtils.java index 5c0a07fae4..8194064569 100644 --- a/stub/src/main/java/io/grpc/stub/MetadataUtils.java +++ b/stub/src/main/java/io/grpc/stub/MetadataUtils.java @@ -98,7 +98,7 @@ public class MetadataUtils { public static T captureMetadata( T stub, AtomicReference headersCapture, - AtomicReference trailersCapture) { + AtomicReference trailersCapture) { return (T) stub.withInterceptors( newCaptureMetadataInterceptor(headersCapture, trailersCapture)); } @@ -112,7 +112,7 @@ public class MetadataUtils { */ public static ClientInterceptor newCaptureMetadataInterceptor( final AtomicReference headersCapture, - final AtomicReference trailersCapture) { + final AtomicReference trailersCapture) { return new ClientInterceptor() { @Override public ClientCall interceptCall( @@ -132,7 +132,7 @@ public class MetadataUtils { } @Override - public void onClose(Status status, Metadata.Trailers trailers) { + public void onClose(Status status, Metadata trailers) { trailersCapture.set(trailers); super.onClose(status, trailers); } diff --git a/stub/src/main/java/io/grpc/stub/ServerCalls.java b/stub/src/main/java/io/grpc/stub/ServerCalls.java index 7538c03684..fbab6c5d65 100644 --- a/stub/src/main/java/io/grpc/stub/ServerCalls.java +++ b/stub/src/main/java/io/grpc/stub/ServerCalls.java @@ -142,7 +142,7 @@ public class ServerCalls { call.close( Status.INVALID_ARGUMENT.withDescription( "More than one request messages for unary call or server streaming call"), - new Metadata.Trailers()); + new Metadata()); } } @@ -152,7 +152,7 @@ public class ServerCalls { method.invoke(request, responseObserver); } else { call.close(Status.INVALID_ARGUMENT.withDescription("Half-closed without a request"), - new Metadata.Trailers()); + new Metadata()); } } @@ -239,7 +239,7 @@ public class ServerCalls { @Override public void onError(Throwable t) { - call.close(Status.fromThrowable(t), new Metadata.Trailers()); + call.close(Status.fromThrowable(t), new Metadata()); } @Override @@ -247,7 +247,7 @@ public class ServerCalls { if (cancelled) { throw Status.CANCELLED.asRuntimeException(); } else { - call.close(Status.OK, new Metadata.Trailers()); + call.close(Status.OK, new Metadata()); } } } diff --git a/stub/src/test/java/io/grpc/stub/ClientCallsTest.java b/stub/src/test/java/io/grpc/stub/ClientCallsTest.java index f60ffb0901..74ed6feda2 100644 --- a/stub/src/test/java/io/grpc/stub/ClientCallsTest.java +++ b/stub/src/test/java/io/grpc/stub/ClientCallsTest.java @@ -74,7 +74,7 @@ public class ClientCallsTest { verify(call).sendMessage(req); verify(call).halfClose(); listener.onMessage("bar"); - listener.onClose(Status.OK, new Metadata.Trailers()); + listener.onClose(Status.OK, new Metadata()); assertEquals("bar", future.get()); } @@ -84,7 +84,7 @@ public class ClientCallsTest { ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); verify(call).start(listenerCaptor.capture(), any(Metadata.Headers.class)); ClientCall.Listener listener = listenerCaptor.getValue(); - listener.onClose(Status.INVALID_ARGUMENT, new Metadata.Trailers()); + listener.onClose(Status.INVALID_ARGUMENT, new Metadata()); try { future.get(); fail("Should fail"); @@ -103,7 +103,7 @@ public class ClientCallsTest { future.cancel(true); verify(call).cancel(); listener.onMessage("bar"); - listener.onClose(Status.OK, new Metadata.Trailers()); + listener.onClose(Status.OK, new Metadata()); try { future.get(); fail("Should fail"); diff --git a/testing/src/main/java/io/grpc/testing/TestUtils.java b/testing/src/main/java/io/grpc/testing/TestUtils.java index 82f493a475..8a3e138a3f 100644 --- a/testing/src/main/java/io/grpc/testing/TestUtils.java +++ b/testing/src/main/java/io/grpc/testing/TestUtils.java @@ -106,7 +106,7 @@ public class TestUtils { } @Override - public void close(Status status, Metadata.Trailers trailers) { + public void close(Status status, Metadata trailers) { trailers.merge(requestHeaders, keySet); super.close(status, trailers); }