@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()); } }
@Override public synchronized void onCompleted() { maybeReopenStream(new StatusException(Status.fromCode(Code.UNKNOWN))); }
private void destroy(Code code) throws InterruptedException { streamObserverCapture.getValue().onError(new StatusException(io.grpc.Status.fromCode(code))); }
LOG.warn("Could not serialize the cause: {}. Failed with: {}", cause, exc); return Status.fromCode(code).asException(trailers);
responseObserver.onError( new StatusException( Status.fromCode(Code.ABORTED) .withDescription("Can only set one subscription."))); return; responseObserver.onError( new StatusException( Status.fromCode(Code.INVALID_ARGUMENT) .withDescription("A stream must be initialized with a ack deadline."))); responseObserver.onError( new StatusException( Status.fromCode(Code.ABORTED) .withDescription( "The stream has not been properly initialized with a " responseObserver.onError( new StatusException( Status.fromCode(Code.ABORTED) .withDescription("Invalid modify ack deadline request."))); return;
responseObserver.onError(Status.fromCode(expectedRpc.resultCode).asRuntimeException()); return;
@Override public synchronized void onCompleted() { maybeReopenStream(new StatusException(Status.fromCode(Code.UNKNOWN))); }
private StatusRuntimeException getBadRequestException(Exception e) { return new StatusRuntimeException( Status.fromCode(Status.Code.OUT_OF_RANGE).withDescription(e.getMessage()).withCause(e)); } }
private StatusRuntimeException getBadRequestException(Exception e) { return new StatusRuntimeException( Status.fromCode(Status.Code.OUT_OF_RANGE).withDescription(e.getMessage()).withCause(e)); } }
private StatusRuntimeException getRuntimeException(Exception e) { return new StatusRuntimeException( Status.fromCode(Status.Code.INTERNAL).withDescription(e.getMessage()).withCause(e)); }
private StatusRuntimeException getRuntimeException(Exception e) { return new StatusRuntimeException( Status.fromCode(Status.Code.INTERNAL).withDescription(e.getMessage()).withCause(e)); }
private void onError(StreamObserver<?> responseObserver, Code errCode, String message, Throwable cause) { responseObserver.onError(Status.fromCode(errCode) .withDescription(message) .withCause(cause) .asException()); } }
@Override public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) { Context context = Context.current(); String credentials = headers.get(Metadata.Key.of(AuthConstants.AUTHORIZATION, Metadata.ASCII_STRING_MARSHALLER)); if (!Strings.isNullOrEmpty(credentials)) { String[] parts = credentials.split("\\s+", 2); if (parts.length == 2) { String method = parts[0]; String token = parts[1]; if (!Strings.isNullOrEmpty(method)) { if (method.equals(handler.getHandlerName())) { Principal principal; try { if ((principal = handler.authenticate(token)) == null) { call.close(Status.fromCode(Status.Code.UNAUTHENTICATED), headers); return null; } } catch (AuthException e) { call.close(Status.fromCode(Status.Code.UNAUTHENTICATED), headers); return null; } context = context.withValue(AUTH_CONTEXT_TOKEN, principal); context = context.withValue(INTERCEPTOR_OBJECT, this); } } } } // reaching this point means that the handler wasn't applicable to this request. return Contexts.interceptCall(context, call, headers, next); }
/** * Convert server exception to one that can be passed back via GRPC. * * @param t * @return */ public static StatusException convertServerException(Throwable t) { StatusException thrown = null; if (t instanceof SiteWhereSystemException) { SiteWhereSystemException sysex = (SiteWhereSystemException) t; Status status = Status.fromCode(Code.FAILED_PRECONDITION) .withDescription(sysex.getCode().getCode() + ":" + sysex.getCode().getMessage()); thrown = status.asException(); } else if (t instanceof SiteWhereException) { SiteWhereException sw = (SiteWhereException) t; Status status = Status.fromCode(Code.FAILED_PRECONDITION) .withDescription(ErrorCode.Error.getCode() + ":" + sw.getMessage()); thrown = status.asException(); } else if (t instanceof TenantEngineNotAvailableException) { TenantEngineNotAvailableException sw = (TenantEngineNotAvailableException) t; Status status = Status.fromCode(Code.UNAVAILABLE).withDescription(sw.getMessage()); thrown = status.asException(); } else { thrown = Status.fromThrowable(t).asException(); } return thrown; } }
} catch (IllegalArgumentException e) { responseObserver.onError( Status.fromCode(Code.INVALID_ARGUMENT) .withCause(e) .withDescription(e.getMessage()) log.error("Training dataset creation failed", e); responseObserver.onError( Status.fromCode(Code.INTERNAL) .withCause(e) .withDescription("Training dataset creation failed: " + e.getMessage())
responseObserver.onError( new StatusRuntimeException( Status.fromCode(INTERNAL).withDescription(e.getMessage()).withCause(e))); } finally { statsDClient
@Test public void convertFromGrpcStatus() { // Without description for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) { io.grpc.Status grpcStatus = io.grpc.Status.fromCode(grpcCanonicalCode); io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus); assertThat(opencensusStatus.getCanonicalCode().toString()) .isEqualTo(grpcStatus.getCode().toString()); assertThat(opencensusStatus.getDescription()).isNull(); } // With description for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) { io.grpc.Status grpcStatus = io.grpc.Status.fromCode(grpcCanonicalCode).withDescription("This is my description"); io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus); assertThat(opencensusStatus.getCanonicalCode().toString()) .isEqualTo(grpcStatus.getCode().toString()); assertThat(opencensusStatus.getDescription()).isEqualTo(grpcStatus.getDescription()); } }