当前位置: 首页>>代码示例>>Java>>正文


Java StatusException类代码示例

本文整理汇总了Java中io.grpc.StatusException的典型用法代码示例。如果您正苦于以下问题:Java StatusException类的具体用法?Java StatusException怎么用?Java StatusException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StatusException类属于io.grpc包,在下文中一共展示了StatusException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: metadataInterceptor

import io.grpc.StatusException; //导入依赖的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: interceptCall

import io.grpc.StatusException; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
        final 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 {
            Metadata cachedSaved;
            URI uri = serviceUri(next, method);
            synchronized (this) {
                Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
                if (mLastMetadata == null || mLastMetadata != latestMetadata) {
                    mLastMetadata = latestMetadata;
                    mCached = toHeaders(mLastMetadata);
                }
                cachedSaved = mCached;
            }
            headers.merge(cachedSaved);
            delegate().start(responseListener, headers);
        }
    };
}
 
开发者ID:hsavaliya,项目名称:GoogleAssistantSDK,代码行数:25,代码来源:SpeechService.java

示例3: getActionResult

import io.grpc.StatusException; //导入依赖的package包/类
@Override
public void getActionResult(
    GetActionResultRequest request,
    StreamObserver<ActionResult> responseObserver) {
  Instance instance;
  try {
    instance = instances.get(request.getInstanceName());
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  ActionResult actionResult =
    instance.getActionResult(request.getActionDigest());
  if (actionResult == null) {
    responseObserver.onError(new StatusException(Status.NOT_FOUND));
    return;
  }

  responseObserver.onNext(actionResult);
  responseObserver.onCompleted();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:23,代码来源:ActionCacheService.java

示例4: interceptCall

import io.grpc.StatusException; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final 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 {

            Metadata cachedSaved;
            URI uri = serviceUri(next, method);
            synchronized (GoogleCredentialsInterceptor.this) {
                Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
                if (mLastMetadata == null || mLastMetadata != latestMetadata) {
                    mLastMetadata = latestMetadata;
                    mCached = toHeaders(mLastMetadata);
                }
                cachedSaved = mCached;
            }
            headers.merge(cachedSaved);
            delegate().start(responseListener, headers);
        }
    };
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:25,代码来源:GoogleCredentialsInterceptor.java

示例5: classify

import io.grpc.StatusException; //导入依赖的package包/类
@Override
public void classify(ClassificationRequest request, StreamObserver<ClassificationReply> responseObserver)
{
	final String client = clientThreadLocal.get();
	if (StringUtils.notEmpty(client))
	{
		clientThreadLocal.set(null);
		ClassificationReply reply = predictionService.predict(client, request);
		responseObserver.onNext(reply);
		responseObserver.onCompleted();
		predictLogger.log(client, request, reply);
	}
	else
	{
		logger.info("Failed to get token");
		responseObserver.onError(new StatusException(io.grpc.Status.PERMISSION_DENIED.withDescription("Could not determine client from oauth_token")));
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:19,代码来源:ExternalRpcServer.java

示例6: createBook

import io.grpc.StatusException; //导入依赖的package包/类
public Book createBook(long shelfId, Book book) throws StatusException {
  synchronized (lock) {
    @Nullable ShelfInfo shelfInfo = shelves.get(shelfId);
    if (shelfInfo == null) {
      throw Status.NOT_FOUND
          .withDescription("Unknown shelf ID")
          .asException();
    }
    shelfInfo.lastBookId++;
    book = book.toBuilder()
        .setId(shelfInfo.lastBookId)
        .build();
    shelfInfo.books.put(shelfInfo.lastBookId, book);
  }
  return book;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:BookstoreData.java

示例7: getBook

import io.grpc.StatusException; //导入依赖的package包/类
public Book getBook(long shelfId, long bookId) throws StatusException {
  synchronized (lock) {
    @Nullable ShelfInfo shelfInfo = shelves.get(shelfId);
    if (shelfInfo == null) {
      throw Status.NOT_FOUND
          .withDescription("Unknown shelf ID")
          .asException();
    }
    @Nullable Book book = shelfInfo.books.get(bookId);
    if (book == null) {
      throw Status.NOT_FOUND
          .withDescription("Unknown book ID")
          .asException();
    }
    return book;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:18,代码来源:BookstoreData.java

示例8: dockerContainer

import io.grpc.StatusException; //导入依赖的package包/类
private String dockerContainer(Action action) throws StatusException {
  String result = null;
  for (Platform.Property property : action.getPlatform().getPropertiesList()) {
    if (property.getName().equals(CONTAINER_IMAGE_ENTRY_NAME)) {
      if (result != null) {
        // Multiple container name entries
        throw StatusUtils.invalidArgumentError(
            "platform", // Field name.
            String.format(
                "Multiple entries for %s in action.Platform", CONTAINER_IMAGE_ENTRY_NAME));
      }
      result = property.getValue();
      if (!result.startsWith(DOCKER_IMAGE_PREFIX)) {
        throw StatusUtils.invalidArgumentError(
            "platform", // Field name.
            String.format(
                "%s: Docker images must be stored in gcr.io with an image spec in the form "
                    + "'docker://gcr.io/{IMAGE_NAME}'",
                CONTAINER_IMAGE_ENTRY_NAME));
      }
      result = result.substring(DOCKER_IMAGE_PREFIX.length());
    }
  }
  return result;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:26,代码来源:ExecutionServer.java

示例9: ping_failsWhenTransportShutdown

import io.grpc.StatusException; //导入依赖的package包/类
@Test
public void ping_failsWhenTransportShutdown() throws Exception {
  initTransport();
  PingCallbackImpl callback = new PingCallbackImpl();
  clientTransport.ping(callback, MoreExecutors.directExecutor());
  assertEquals(1, clientTransport.getStats().get().keepAlivesSent);
  assertEquals(0, callback.invocationCount);

  clientTransport.shutdown(SHUTDOWN_REASON);
  // ping failed on channel shutdown
  assertEquals(1, callback.invocationCount);
  assertTrue(callback.failureCause instanceof StatusException);
  assertSame(SHUTDOWN_REASON, ((StatusException) callback.failureCause).getStatus());

  // now that handler is in terminal state, all future pings fail immediately
  callback = new PingCallbackImpl();
  clientTransport.ping(callback, MoreExecutors.directExecutor());
  assertEquals(1, clientTransport.getStats().get().keepAlivesSent);
  assertEquals(1, callback.invocationCount);
  assertTrue(callback.failureCause instanceof StatusException);
  assertSame(SHUTDOWN_REASON, ((StatusException) callback.failureCause).getStatus());
  shutdownAndVerify();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:24,代码来源:OkHttpClientTransportTest.java

示例10: ping_failsIfTransportFails

import io.grpc.StatusException; //导入依赖的package包/类
@Test
public void ping_failsIfTransportFails() throws Exception {
  initTransport();
  PingCallbackImpl callback = new PingCallbackImpl();
  clientTransport.ping(callback, MoreExecutors.directExecutor());
  assertEquals(1, clientTransport.getStats().get().keepAlivesSent);
  assertEquals(0, callback.invocationCount);

  clientTransport.onException(new IOException());
  // ping failed on error
  assertEquals(1, callback.invocationCount);
  assertTrue(callback.failureCause instanceof StatusException);
  assertEquals(Status.Code.UNAVAILABLE,
      ((StatusException) callback.failureCause).getStatus().getCode());

  // now that handler is in terminal state, all future pings fail immediately
  callback = new PingCallbackImpl();
  clientTransport.ping(callback, MoreExecutors.directExecutor());
  assertEquals(1, clientTransport.getStats().get().keepAlivesSent);
  assertEquals(1, callback.invocationCount);
  assertTrue(callback.failureCause instanceof StatusException);
  assertEquals(Status.Code.UNAVAILABLE,
      ((StatusException) callback.failureCause).getStatus().getCode());
  shutdownAndVerify();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:OkHttpClientTransportTest.java

示例11: maxHeaderListSizeShouldBeEnforcedOnClient

import io.grpc.StatusException; //导入依赖的package包/类
@Test
public void maxHeaderListSizeShouldBeEnforcedOnClient() throws Exception {
  startServer();

  NettyClientTransport transport =
      newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, 1, null, true);
  callMeMaybe(transport.start(clientTransportListener));

  try {
    // Send a single RPC and wait for the response.
    new Rpc(transport, new Metadata()).halfClose().waitForResponse();
    fail("The stream should have been failed due to client received header exceeds header list"
        + " size limit!");
  } catch (Exception e) {
    Throwable rootCause = getRootCause(e);
    Status status = ((StatusException) rootCause).getStatus();
    assertEquals(Status.Code.INTERNAL, status.getCode());
    assertEquals("HTTP/2 error code: PROTOCOL_ERROR\nReceived Rst Stream",
        status.getDescription());
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:NettyClientTransportTest.java

示例12: serviceUri

import io.grpc.StatusException; //导入依赖的package包/类
/**
 * Generate a JWT-specific service URI. The URI is simply an identifier with enough information
 * for a service to know that the JWT was intended for it. The URI will commonly be verified with
 * a simple string equality check.
 */
private URI serviceUri(Channel channel, MethodDescriptor<?, ?> method) throws StatusException {
  String authority = channel.authority();
  if (authority == null) {
    throw Status.UNAUTHENTICATED.withDescription("Channel has no authority").asException();
  }
  // Always use HTTPS, by definition.
  final String scheme = "https";
  final int defaultPort = 443;
  String path = "/" + MethodDescriptor.extractFullServiceName(method.getFullMethodName());
  URI uri;
  try {
    uri = new URI(scheme, authority, path, null, null);
  } catch (URISyntaxException e) {
    throw Status.UNAUTHENTICATED.withDescription("Unable to construct service URI for auth")
        .withCause(e).asException();
  }
  // The default port must not be present. Alternative ports should be present.
  if (uri.getPort() == defaultPort) {
    uri = removePort(uri);
  }
  return uri;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:28,代码来源:ClientAuthInterceptor.java

示例13: serviceUri

import io.grpc.StatusException; //导入依赖的package包/类
/**
 * Generate a JWT-specific service URI. The URI is simply an identifier with enough information
 * for a service to know that the JWT was intended for it. The URI will commonly be verified with
 * a simple string equality check.
 */
private static URI serviceUri(String authority, MethodDescriptor<?, ?> method)
    throws StatusException {
  if (authority == null) {
    throw Status.UNAUTHENTICATED.withDescription("Channel has no authority").asException();
  }
  // Always use HTTPS, by definition.
  final String scheme = "https";
  final int defaultPort = 443;
  String path = "/" + MethodDescriptor.extractFullServiceName(method.getFullMethodName());
  URI uri;
  try {
    uri = new URI(scheme, authority, path, null, null);
  } catch (URISyntaxException e) {
    throw Status.UNAUTHENTICATED.withDescription("Unable to construct service URI for auth")
        .withCause(e).asException();
  }
  // The default port must not be present. Alternative ports should be present.
  if (uri.getPort() == defaultPort) {
    uri = removePort(uri);
  }
  return uri;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:28,代码来源:GoogleAuthLibraryCallCredentials.java

示例14: checkStatusNotFound

import io.grpc.StatusException; //导入依赖的package包/类
@Test
public void checkStatusNotFound() throws Exception {
  //setup
  manager.setStatus("", status);
  HealthCheckRequest request
      = HealthCheckRequest.newBuilder().setService("invalid").build();
  @SuppressWarnings("unchecked")
  StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);

  //test
  health.check(request, observer);

  //verify
  ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
  verify(observer, times(1)).onError(exception.capture());
  assertEquals(Status.Code.NOT_FOUND, exception.getValue().getStatus().getCode());

  verify(observer, never()).onCompleted();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:HealthStatusManagerTest.java

示例15: notFoundForClearedStatus

import io.grpc.StatusException; //导入依赖的package包/类
@Test
public void notFoundForClearedStatus() throws Exception {
  //setup
  manager.setStatus("", status);
  manager.clearStatus("");
  HealthCheckRequest request
      = HealthCheckRequest.newBuilder().setService("").build();
  @SuppressWarnings("unchecked")
  StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);

  //test
  health.check(request, observer);

  //verify
  ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
  verify(observer, times(1)).onError(exception.capture());
  assertEquals(Status.Code.NOT_FOUND, exception.getValue().getStatus().getCode());

  verify(observer, never()).onCompleted();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:HealthStatusManagerTest.java


注:本文中的io.grpc.StatusException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。