本文整理汇总了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;
}
示例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);
}
};
}
示例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();
}
示例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);
}
};
}
示例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")));
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
示例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();
}
示例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());
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}