當前位置: 首頁>>代碼示例>>Java>>正文


Java Metadata.put方法代碼示例

本文整理匯總了Java中io.grpc.Metadata.put方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.put方法的具體用法?Java Metadata.put怎麽用?Java Metadata.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.grpc.Metadata的用法示例。


在下文中一共展示了Metadata.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: metadataInterceptor

import io.grpc.Metadata; //導入方法依賴的package包/類
private ClientInterceptor metadataInterceptor() {
  ClientInterceptor interceptor = new ClientInterceptor() {
    @Override
    public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
        final io.grpc.MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, final Channel next) {
      return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
        @Override
        protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
            throws StatusException {
          for (ConfigProto.CallMetadataEntry entry : callConfiguration.getMetadataList()) {
            Metadata.Key<String> key = Metadata.Key.of(entry.getName(), Metadata.ASCII_STRING_MARSHALLER);
            headers.put(key, entry.getValue());
          }
          delegate().start(responseListener, headers);
        }
      };
    }
  };

  return interceptor;
}
 
開發者ID:grpc-ecosystem,項目名稱:polyglot,代碼行數:22,代碼來源:ChannelFactory.java

示例2: copyThreadLocalToMetadata

import io.grpc.Metadata; //導入方法依賴的package包/類
private void copyThreadLocalToMetadata(Metadata headers) {
  Map<String, String> attachments = RpcContext.getContext().getAttachments();
  Map<String, Object> values = RpcContext.getContext().get();
  try {
    if (!attachments.isEmpty()) {
      headers.put(GrpcUtil.GRPC_CONTEXT_ATTACHMENTS, SerializerUtil.toJson(attachments));
    }
    if (!values.isEmpty()) {
      headers.put(GrpcUtil.GRPC_CONTEXT_VALUES, SerializerUtil.toJson(values));
    }
  } catch (Throwable e) {
    log.error(e.getMessage(), e);
  } finally {
    RpcContext.removeContext();
  }
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:17,代碼來源:HeaderClientInterceptor.java

示例3: toException

import io.grpc.Metadata; //導入方法依賴的package包/類
private static Exception toException(ErrorReporter errorReport) {
  Metadata trailers = new Metadata();
  trailers.put(errorDetailsKey, errorReport.toErrorDetails());
  switch (errorReport.getGeneralCode()) {
    case FUNCTION:
      return Status.FAILED_PRECONDITION.withCause(errorReport.getCause())
          .withDescription(errorReport.getSpecificErrorMsg()).asException(trailers);
    case UNAVAILABLE:
      return Status.UNAVAILABLE.withCause(errorReport.getCause())
          .withDescription(errorReport.getSpecificErrorMsg()).asRuntimeException(trailers);
    case INTERNAL:
      return Status.INTERNAL.withCause(errorReport.getCause())
          .withDescription(errorReport.getSpecificErrorMsg()).asRuntimeException(trailers);
    default:
      return Status.UNKNOWN.withCause(errorReport.getCause())
          .withDescription(errorReport.getSpecificErrorMsg()).asRuntimeException(trailers);
  }
}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:19,代碼來源:ServerErrorHandler.java

示例4: beforeMethod

import io.grpc.Metadata; //導入方法依賴的package包/類
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    final Metadata headers = (Metadata)allArguments[1];

    final ContextCarrier contextCarrier = new ContextCarrier();
    ContextManager.inject(contextCarrier);
    CarrierItem contextItem = contextCarrier.items();
    while (contextItem.hasNext()) {
        contextItem = contextItem.next();
        Metadata.Key<String> headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER);
        headers.put(headerKey, contextItem.getHeadValue());
    }

    GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField();
    GRPCDynamicFields listenerCachedObject = new GRPCDynamicFields();
    listenerCachedObject.setSnapshot(ContextManager.capture());
    listenerCachedObject.setDescriptor(cachedObjects.getDescriptor());
    ((EnhancedInstance)allArguments[0]).setSkyWalkingDynamicField(listenerCachedObject);
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:21,代碼來源:ClientCallStartInterceptor.java

示例5: decompressorNotFound

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void decompressorNotFound() throws Exception {
  String decompressorName = "NON_EXISTENT_DECOMPRESSOR";
  createAndStartServer();
  ServerTransportListener transportListener
      = transportServer.registerNewServerTransport(new SimpleServerTransport());
  transportListener.transportReady(Attributes.EMPTY);
  Metadata requestHeaders = new Metadata();
  requestHeaders.put(MESSAGE_ENCODING_KEY, decompressorName);
  StatsTraceContext statsTraceCtx =
      StatsTraceContext.newServerContext(
          streamTracerFactories, "Waiter/nonexist", requestHeaders);
  when(stream.statsTraceContext()).thenReturn(statsTraceCtx);

  transportListener.streamCreated(stream, "Waiter/nonexist", requestHeaders);

  verify(stream).close(statusCaptor.capture(), any(Metadata.class));
  Status status = statusCaptor.getValue();
  assertEquals(Status.Code.UNIMPLEMENTED, status.getCode());
  assertEquals("Can't find decompressor for " + decompressorName, status.getDescription());
  verifyNoMoreInteractions(stream);
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:23,代碼來源:ServerImplTest.java

示例6: transportHeadersReceived_wrongContentType_401

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void transportHeadersReceived_wrongContentType_401() {
  BaseTransportState state = new BaseTransportState(transportTracer);
  state.setListener(mockListener);
  Metadata headers = new Metadata();
  headers.put(testStatusMashaller, "401");
  headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "text/html");
  state.transportHeadersReceived(headers);
  state.transportDataReceived(ReadableBuffers.empty(), true);

  verify(mockListener, never()).headersRead(any(Metadata.class));
  verify(mockListener).closed(statusCaptor.capture(), same(headers));
  assertEquals(Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());
  assertTrue(statusCaptor.getValue().getDescription().contains("401"));
  assertTrue(statusCaptor.getValue().getDescription().contains("text/html"));
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:17,代碼來源:Http2ClientStreamTransportStateTest.java

示例7: transportHeadersReceived_twice

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void transportHeadersReceived_twice() {
  BaseTransportState state = new BaseTransportState(transportTracer);
  state.setListener(mockListener);
  Metadata headers = new Metadata();
  headers.put(testStatusMashaller, "200");
  headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER),
      "application/grpc");
  state.transportHeadersReceived(headers);
  Metadata headersAgain = new Metadata();
  state.transportHeadersReceived(headersAgain);
  state.transportDataReceived(ReadableBuffers.empty(), true);

  verify(mockListener).headersRead(headers);
  verify(mockListener).closed(statusCaptor.capture(), same(headersAgain));
  assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
  assertTrue(statusCaptor.getValue().getDescription().contains("twice"));
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:19,代碼來源:Http2ClientStreamTransportStateTest.java

示例8: start_headerFieldOrder

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void start_headerFieldOrder() {
  Metadata metaData = new Metadata();
  metaData.put(GrpcUtil.USER_AGENT_KEY, "misbehaving-application");
  stream = new OkHttpClientStream(methodDescriptor, metaData, frameWriter, transport,
      flowController, lock, MAX_MESSAGE_SIZE, "localhost", "good-application",
      StatsTraceContext.NOOP, transportTracer);
  stream.start(new BaseClientStreamListener());
  stream.transportState().start(3);

  verify(frameWriter).synStream(eq(false), eq(false), eq(3), eq(0), headersCaptor.capture());
  assertThat(headersCaptor.getValue()).containsExactly(
      Headers.SCHEME_HEADER,
      Headers.METHOD_HEADER,
      new Header(Header.TARGET_AUTHORITY, "localhost"),
      new Header(Header.TARGET_PATH, "/" + methodDescriptor.getFullMethodName()),
      new Header(GrpcUtil.USER_AGENT_KEY.name(), "good-application"),
      Headers.CONTENT_TYPE_HEADER,
      Headers.TE_HEADER)
          .inOrder();
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:22,代碼來源:OkHttpClientStreamTest.java

示例9: transportHeadersReceived_handles_1xx

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void transportHeadersReceived_handles_1xx() {
  BaseTransportState state = new BaseTransportState(transportTracer);
  state.setListener(mockListener);

  Metadata infoHeaders = new Metadata();
  infoHeaders.put(testStatusMashaller, "100");
  state.transportHeadersReceived(infoHeaders);
  Metadata infoHeaders2 = new Metadata();
  infoHeaders2.put(testStatusMashaller, "101");
  state.transportHeadersReceived(infoHeaders2);

  Metadata headers = new Metadata();
  headers.put(testStatusMashaller, "200");
  headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER),
      "application/grpc");
  state.transportHeadersReceived(headers);

  verify(mockListener, never()).closed(any(Status.class), any(Metadata.class));
  verify(mockListener).headersRead(headers);
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:22,代碼來源:Http2ClientStreamTransportStateTest.java

示例10: addClientIdentification

import io.grpc.Metadata; //導入方法依賴的package包/類
static SdkServerServiceBlockingStub addClientIdentification(SdkServerServiceBlockingStub stub) {
    // Optional client id header
    String clientId = AfricasTalking.getClientId();
    if (clientId != null) {
        Metadata headers = new Metadata();
        headers.put(CLIENT_ID_HEADER_KEY, clientId);
        stub = MetadataUtils.attachHeaders(stub, headers);
    }
    return stub;
}
 
開發者ID:aksalj,項目名稱:africastalking-android,代碼行數:11,代碼來源:Service.java

示例11: toHeaders

import io.grpc.Metadata; //導入方法依賴的package包/類
private static Metadata toHeaders(Map<String, List<String>> metadata) {
    Metadata headers = new Metadata();
    if (metadata != null) {
        for (String key : metadata.keySet()) {
            Metadata.Key<String> headerKey = Metadata.Key.of(
                    key, Metadata.ASCII_STRING_MARSHALLER);
            for (String value : metadata.get(key)) {
                headers.put(headerKey, value);
            }
        }
    }
    return headers;
}
 
開發者ID:hsavaliya,項目名稱:GoogleAssistantSDK,代碼行數:14,代碼來源:SpeechService.java

示例12: changeMetadataKeyType

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void changeMetadataKeyType() {
    Metadata.Key<String> stringKey = Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER);
    Metadata.Key<Long> longKey = Metadata.Key.of("key", MoreMetadata.LONG_MARSHALLER);

    Metadata metadata = new Metadata();
    metadata.put(stringKey, "12345");

    Long bool = metadata.get(longKey);
    assertThat(bool).isEqualTo(12345);
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:12,代碼來源:MoreMetadataTest.java

示例13: rawJsonToTypedJson

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void rawJsonToTypedJson() {
    Metadata.Key<String> stringKey = Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER);
    Metadata.Key<Bar> barKey = Metadata.Key.of("key", MoreMetadata.JSON_MARSHALLER(Bar.class));

    Metadata metadata = new Metadata();
    metadata.put(stringKey, "{'cheese': 'swiss', 'age': 42}");

    Bar bar = metadata.get(barKey);
    assertThat(bar).isNotNull();
    assertThat(bar.cheese).isEqualTo("swiss");
    assertThat(bar.age).isEqualTo(42);
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:14,代碼來源:MoreMetadataTest.java

示例14: rawBytesToTypedProto

import io.grpc.Metadata; //導入方法依賴的package包/類
@Test
public void rawBytesToTypedProto() {
    Metadata.Key<byte[]> byteKey = Metadata.Key.of("key-bin", Metadata.BINARY_BYTE_MARSHALLER);
    Metadata.Key<HelloRequest> protoKey = Metadata.Key.of("key-bin", MoreMetadata.PROTOBUF_MARSHALLER(HelloRequest.class));

    HelloRequest request = HelloRequest.newBuilder().setName("World").build();
    Metadata metadata = new Metadata();
    metadata.put(byteKey, request.toByteArray());

    HelloRequest request2 = metadata.get(protoKey);
    assertThat(request2).isNotNull();
    assertThat(request2.getName()).isEqualTo("World");
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:14,代碼來源:MoreMetadataTest.java

示例15: wrap

import io.grpc.Metadata; //導入方法依賴的package包/類
protected <RespT> ClientCall.Listener<RespT> wrap(final ClientCall.Listener<RespT> delegate,
    final Context timeContext, final AtomicBoolean decremented) {
  return new ClientCall.Listener<RespT>() {

    @Override
    public void onHeaders(Metadata headers) {
      delegate.onHeaders(headers);
    }

    @Override
    public void onMessage(RespT message) {
      delegate.onMessage(message);
    }

    @Override
    public void onClose(Status status, Metadata trailers) {
      try {
        if (trailers != null) {
          // Be extra defensive since this is only used for logging
          trailers.put(CHANNEL_ID_KEY, Integer.toString(channelId));
        }
        if (!decremented.getAndSet(true)) {
          getStats().ACTIVE_RPC_COUNTER.dec();
        }
        if (!status.isOk()) {
          ClientMetrics.meter(MetricLevel.Info, "grpc.errors." + status.getCode().name())
              .mark();
        }
        delegate.onClose(status, trailers);
      } finally {
        timeContext.close();
      }
    }

    @Override
    public void onReady() {
      delegate.onReady();
    }
  };
}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:41,代碼來源:ChannelPool.java


注:本文中的io.grpc.Metadata.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。