Java Code Examples for io.grpc.InternalMetadata#newMetadata()
The following examples show how to use
io.grpc.InternalMetadata#newMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CronetClientStream.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private void reportHeaders(List<Map.Entry<String, String>> headers, boolean endOfStream) { // TODO(ericgribkoff): create new utility methods to eliminate all these conversions List<String> headerList = new ArrayList<>(); for (Map.Entry<String, String> entry : headers) { headerList.add(entry.getKey()); headerList.add(entry.getValue()); } byte[][] headerValues = new byte[headerList.size()][]; for (int i = 0; i < headerList.size(); i += 2) { headerValues[i] = headerList.get(i).getBytes(Charset.forName("UTF-8")); headerValues[i + 1] = headerList.get(i + 1).getBytes(Charset.forName("UTF-8")); } Metadata metadata = InternalMetadata.newMetadata(TransportFrameUtil.toRawSerializedHeaders(headerValues)); synchronized (state.lock) { // There's no pending onReadCompleted callback so we can report trailers now. state.transportHeadersReceived(metadata, endOfStream); } }
Example 2
Source File: TransportFrameUtilTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void dupBinHeadersWithComma() { byte[][] http2Headers = new byte[][] { BINARY_BYTES.name().getBytes(US_ASCII), "BaS,e6,,4+,padding==".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "more".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "".getBytes(US_ASCII)}; byte[][] rawSerialized = TransportFrameUtil.toRawSerializedHeaders(http2Headers); Metadata recoveredHeaders = InternalMetadata.newMetadata(rawSerialized); byte[][] values = Iterables.toArray(recoveredHeaders.getAll(BINARY_BYTES), byte[].class); assertTrue(Arrays.deepEquals( new byte[][] { BaseEncoding.base64().decode("BaS"), BaseEncoding.base64().decode("e6"), BaseEncoding.base64().decode(""), BaseEncoding.base64().decode("4+"), BaseEncoding.base64().decode("padding"), BaseEncoding.base64().decode("more"), BaseEncoding.base64().decode("")}, values)); }
Example 3
Source File: CronetClientStream.java From grpc-java with Apache License 2.0 | 6 votes |
private void reportHeaders(List<Map.Entry<String, String>> headers, boolean endOfStream) { // TODO(ericgribkoff): create new utility methods to eliminate all these conversions List<String> headerList = new ArrayList<>(); for (Map.Entry<String, String> entry : headers) { headerList.add(entry.getKey()); headerList.add(entry.getValue()); } byte[][] headerValues = new byte[headerList.size()][]; for (int i = 0; i < headerList.size(); i += 2) { headerValues[i] = headerList.get(i).getBytes(Charset.forName("UTF-8")); headerValues[i + 1] = headerList.get(i + 1).getBytes(Charset.forName("UTF-8")); } Metadata metadata = InternalMetadata.newMetadata(TransportFrameUtil.toRawSerializedHeaders(headerValues)); synchronized (state.lock) { // There's no pending onReadCompleted callback so we can report trailers now. state.transportHeadersReceived(metadata, endOfStream); } }
Example 4
Source File: TransportFrameUtilTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void dupBinHeadersWithComma() { byte[][] http2Headers = new byte[][] { BINARY_BYTES.name().getBytes(US_ASCII), "BaS,e6,,4+,padding==".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "more".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "".getBytes(US_ASCII)}; byte[][] rawSerialized = TransportFrameUtil.toRawSerializedHeaders(http2Headers); Metadata recoveredHeaders = InternalMetadata.newMetadata(rawSerialized); byte[][] values = Iterables.toArray(recoveredHeaders.getAll(BINARY_BYTES), byte[].class); assertTrue(Arrays.deepEquals( new byte[][] { BaseEncoding.base64().decode("BaS"), BaseEncoding.base64().decode("e6"), BaseEncoding.base64().decode(""), BaseEncoding.base64().decode("4+"), BaseEncoding.base64().decode("padding"), BaseEncoding.base64().decode("more"), BaseEncoding.base64().decode("")}, values)); }
Example 5
Source File: Utils.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
public static Metadata convertHeaders(Http2Headers http2Headers) { if (http2Headers instanceof GrpcHttp2InboundHeaders) { GrpcHttp2InboundHeaders h = (GrpcHttp2InboundHeaders) http2Headers; return InternalMetadata.newMetadata(h.numHeaders(), h.namesAndValues()); } return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 6
Source File: Utils.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
public static Metadata convertTrailers(Http2Headers http2Headers) { if (http2Headers instanceof GrpcHttp2InboundHeaders) { GrpcHttp2InboundHeaders h = (GrpcHttp2InboundHeaders) http2Headers; return InternalMetadata.newMetadata(h.numHeaders(), h.namesAndValues()); } return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 7
Source File: TransportFrameUtilTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void testToAndFromHttp2Headers() { Metadata headers = new Metadata(); headers.put(PLAIN_STRING, COMPLIANT_ASCII_STRING); headers.put(BINARY_STRING, NONCOMPLIANT_ASCII_STRING); headers.put(BINARY_STRING_WITHOUT_SUFFIX, NONCOMPLIANT_ASCII_STRING); byte[][] http2Headers = TransportFrameUtil.toHttp2Headers(headers); byte[][] rawSerialized = TransportFrameUtil.toRawSerializedHeaders(http2Headers); Metadata recoveredHeaders = InternalMetadata.newMetadata(rawSerialized); assertEquals(COMPLIANT_ASCII_STRING, recoveredHeaders.get(PLAIN_STRING)); assertEquals(NONCOMPLIANT_ASCII_STRING, recoveredHeaders.get(BINARY_STRING)); assertNull(recoveredHeaders.get(BINARY_STRING_WITHOUT_SUFFIX)); }
Example 8
Source File: Utils.java From grpc-java with Apache License 2.0 | 5 votes |
public static Metadata convertHeaders(Http2Headers http2Headers) { if (http2Headers instanceof GrpcHttp2InboundHeaders) { GrpcHttp2InboundHeaders h = (GrpcHttp2InboundHeaders) http2Headers; return InternalMetadata.newMetadata(h.numHeaders(), h.namesAndValues()); } return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 9
Source File: Utils.java From grpc-java with Apache License 2.0 | 5 votes |
public static Metadata convertTrailers(Http2Headers http2Headers) { if (http2Headers instanceof GrpcHttp2InboundHeaders) { GrpcHttp2InboundHeaders h = (GrpcHttp2InboundHeaders) http2Headers; return InternalMetadata.newMetadata(h.numHeaders(), h.namesAndValues()); } return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 10
Source File: TransportFrameUtilTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void testToAndFromHttp2Headers() { Metadata headers = new Metadata(); headers.put(PLAIN_STRING, COMPLIANT_ASCII_STRING); headers.put(BINARY_STRING, NONCOMPLIANT_ASCII_STRING); headers.put(BINARY_STRING_WITHOUT_SUFFIX, NONCOMPLIANT_ASCII_STRING); byte[][] http2Headers = TransportFrameUtil.toHttp2Headers(headers); byte[][] rawSerialized = TransportFrameUtil.toRawSerializedHeaders(http2Headers); Metadata recoveredHeaders = InternalMetadata.newMetadata(rawSerialized); assertEquals(COMPLIANT_ASCII_STRING, recoveredHeaders.get(PLAIN_STRING)); assertEquals(NONCOMPLIANT_ASCII_STRING, recoveredHeaders.get(BINARY_STRING)); assertNull(recoveredHeaders.get(BINARY_STRING_WITHOUT_SUFFIX)); }
Example 11
Source File: Utils.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
public static Metadata convertHeaders(List<Header> http2Headers) { return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 12
Source File: Utils.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
public static Metadata convertTrailers(List<Header> http2Headers) { return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 13
Source File: Utils.java From grpc-java with Apache License 2.0 | 4 votes |
public static Metadata convertHeaders(List<Header> http2Headers) { return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }
Example 14
Source File: Utils.java From grpc-java with Apache License 2.0 | 4 votes |
public static Metadata convertTrailers(List<Header> http2Headers) { return InternalMetadata.newMetadata(convertHeadersToArray(http2Headers)); }