本文整理了Java中io.grpc.Status.withCause()
方法的一些代码示例,展示了Status.withCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.withCause()
方法的具体详情如下:
包路径:io.grpc.Status
类名称:Status
方法名:withCause
[英]Create a derived instance of Status with the given cause. However, the cause is not transmitted from server to client.
[中]创建具有给定原因的状态的派生实例。但是,原因不会从服务器传输到客户端。
代码示例来源:origin: weibocom/motan
@Override
public void onError(Throwable t) {
Metadata metadata = Status.trailersFromThrowable(t);
if (metadata == null) {
metadata = new Metadata();
}
if (t instanceof MotanBizException) {
call.close(Status.INTERNAL.withDescription(t.getMessage()).withCause(t), metadata);
} else {
call.close(Status.UNAVAILABLE.withDescription(t.getMessage()).withCause(t), metadata);
}
}
代码示例来源:origin: line/armeria
private static Status addCause(Status status, String serializedThrowableProto) {
final byte[] decoded;
try {
decoded = Base64.getDecoder().decode(serializedThrowableProto);
} catch (IllegalArgumentException e) {
logger.warn("Invalid Base64 in status cause proto, ignoring.", e);
return status;
}
final ThrowableProto grpcThrowableProto;
try {
grpcThrowableProto = ThrowableProto.parseFrom(decoded);
} catch (InvalidProtocolBufferException e) {
logger.warn("Invalid serialized status cause proto, ignoring.", e);
return status;
}
return status.withCause(new StatusCauseException(grpcThrowableProto));
}
}
代码示例来源:origin: line/armeria
return Status.UNKNOWN.withCause(t);
return Status.UNAVAILABLE.withCause(t);
return Status.INTERNAL.withCause(t);
return Status.DEADLINE_EXCEEDED.withCause(t);
代码示例来源:origin: Alluxio/alluxio
@Override
public void onNext(SaslMessage saslMessage) {
try {
SaslMessage response = mSaslHandshakeClientHandler.handleSaslMessage(saslMessage);
if (response == null) {
mRequestObserver.onCompleted();
} else {
mRequestObserver.onNext(response);
}
} catch (SaslException e) {
mAuthenticated.setException(e);
mRequestObserver
.onError(Status.fromCode(Status.Code.UNAUTHENTICATED).withCause(e).asException());
}
}
代码示例来源:origin: line/armeria
private void doCancel(@Nullable String message, @Nullable Throwable cause) {
if (message == null && cause == null) {
cause = new CancellationException("Cancelled without a message or cause");
logger.warn("Cancelling without a message or cause is suboptimal", cause);
}
if (cancelCalled) {
return;
}
cancelCalled = true;
Status status = Status.CANCELLED;
if (message != null) {
status = status.withDescription(message);
}
if (cause != null) {
status = status.withCause(cause);
}
close(status);
req.abort();
}
代码示例来源:origin: apache/avro
@Override
public Object[] parse(InputStream stream) {
try {
BinaryDecoder in = DECODER_FACTORY.binaryDecoder(stream, null);
Schema reqSchema = message.getRequest();
GenericRecord request = (GenericRecord) new SpecificDatumReader<>(reqSchema).read(null, in);
Object[] args = new Object[reqSchema.getFields().size()];
int i = 0;
for (Schema.Field field : reqSchema.getFields()) {
args[i++] = request.get(field.name());
}
return args;
} catch (IOException e) {
throw Status.INTERNAL.withCause(e).
withDescription("Error deserializing avro request arguments").asRuntimeException();
} finally {
AvroGrpcUtils.skipAndCloseQuietly(stream);
}
}
代码示例来源:origin: line/armeria
@Override
public void unaryCall(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
IllegalStateException e1 = new IllegalStateException("Exception 1");
IllegalArgumentException e2 = new IllegalArgumentException();
AssertionError e3 = new AssertionError("Exception 3");
Exceptions.clearTrace(e3);
RuntimeException e4 = new RuntimeException("Exception 4");
e1.initCause(e2);
e2.initCause(e3);
e3.initCause(e4);
Status status = Status.ABORTED.withCause(e1);
responseObserver.onError(status.asRuntimeException());
}
}
代码示例来源:origin: line/armeria
/**
* Writes out a payload message.
*
* @param message the message to be written out. Ownership is taken by {@link ArmeriaMessageFramer}.
*
* @return a {@link ByteBufHttpData} with the framed payload. Ownership is passed to caller.
*/
public ByteBufHttpData writePayload(ByteBuf message) {
verifyNotClosed();
final boolean compressed = messageCompression && compressor != Codec.Identity.NONE;
final int messageLength = message.readableBytes();
try {
final ByteBuf buf;
if (messageLength != 0 && compressed) {
buf = writeCompressed(message);
} else {
buf = writeUncompressed(message);
}
return new ByteBufHttpData(buf, false);
} catch (IOException | RuntimeException e) {
// IOException will not be thrown, since sink#deliverFrame doesn't throw.
throw Status.INTERNAL
.withDescription("Failed to frame message")
.withCause(e)
.asRuntimeException();
}
}
代码示例来源:origin: line/armeria
} catch (InvalidProtocolBufferException e) {
throw Status.INTERNAL.withDescription("Invalid protobuf byte sequence")
.withCause(e).asRuntimeException();
代码示例来源:origin: apache/avro
@Override
public Object parse(InputStream stream) {
try {
if (message.isOneWay()) return null;
BinaryDecoder in = DECODER_FACTORY.binaryDecoder(stream, null);
if (!in.readBoolean()) {
Object response = new SpecificDatumReader(message.getResponse()).read(null, in);
return response;
} else {
Object value = new SpecificDatumReader(message.getErrors()).read(null, in);
if (value instanceof Exception) {
return value;
}
return new AvroRuntimeException(value.toString());
}
} catch (IOException e) {
throw Status.INTERNAL.withCause(e).
withDescription("Error deserializing avro response").asRuntimeException();
} finally {
AvroGrpcUtils.skipAndCloseQuietly(stream);
}
}
代码示例来源:origin: Netflix/conductor
.withCause(t)
.asException(metadata);
代码示例来源:origin: yidongnan/grpc-spring-boot-starter
/**
* Close the call with {@link Status#PERMISSION_DENIED}.
*
* @param call The call to close.
* @param aex The exception that was the cause.
*/
protected void closeCallAccessDenied(final ServerCall<?, ?> call, final AccessDeniedException aex) {
call.close(Status.PERMISSION_DENIED.withCause(aex).withDescription(ACCESS_DENIED_DESCRIPTION), new Metadata());
}
代码示例来源:origin: yidongnan/grpc-spring-boot-starter
/**
* Close the call with {@link Status#UNAUTHENTICATED}.
*
* @param call The call to close.
* @param aex The exception that was the cause.
*/
protected void closeCallUnauthenticated(final ServerCall<?, ?> call, final AuthenticationException aex) {
call.close(Status.UNAUTHENTICATED.withCause(aex).withDescription(UNAUTHENTICATED_DESCRIPTION), new Metadata());
}
代码示例来源:origin: line/armeria
obs.onError(Status.UNIMPLEMENTED
.withDescription("compression not supported.")
.withCause(e)
.asRuntimeException());
return;
代码示例来源:origin: yidongnan/grpc-spring-boot-starter
newServiceInstanceList = client.getInstances(name);
} catch (Exception e) {
savedListener.onError(Status.UNAVAILABLE.withCause(e));
return;
} else {
savedListener.onError(Status.UNAVAILABLE
.withCause(new RuntimeException("UNAVAILABLE: NameResolver returned an empty list")));
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@Override
public InputStream stream(T value) {
try {
return new ByteArrayInputStream(printer.print(value).getBytes(charset));
} catch (InvalidProtocolBufferException e) {
throw Status.INTERNAL
.withCause(e)
.withDescription("Unable to print json proto")
.asRuntimeException();
}
}
代码示例来源:origin: gojek/feast
private StatusRuntimeException getBadRequestException(Exception e) {
return new StatusRuntimeException(
Status.fromCode(Status.Code.OUT_OF_RANGE).withDescription(e.getMessage()).withCause(e));
}
}
代码示例来源:origin: net.devh/grpc-server-spring-boot-autoconfigure
/**
* Close the call with {@link Status#UNAUTHENTICATED}.
*
* @param call The call to close.
* @param aex The exception that was the cause.
*/
protected void closeCallUnauthenticated(final ServerCall<?, ?> call, final AuthenticationException aex) {
call.close(Status.UNAUTHENTICATED.withCause(aex).withDescription(UNAUTHENTICATED_DESCRIPTION), new Metadata());
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
public ResultT getBlockingResult() {
try {
return getAsyncResult().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
cancel();
throw Status.CANCELLED.withCause(e).asRuntimeException();
} catch (ExecutionException e) {
cancel();
throw Status.fromThrowable(e).asRuntimeException();
}
}
代码示例来源:origin: saturnism/grpc-java-by-example
@Override
public void customException(EchoRequest request, StreamObserver<EchoResponse> responseObserver) {
try {
throw new CustomException("Custom exception!");
} catch (Exception e) {
responseObserver.onError(Status.INTERNAL
.withDescription(e.getMessage())
.augmentDescription("customException()")
.withCause(e) // This can be attached to the Status locally, but NOT transmitted to the client!
.asRuntimeException());
}
}
内容来源于网络,如有侵权,请联系作者删除!