/** * Creates a new exceptionally complete {@link RpcResponse}. */ static RpcResponse ofFailure(Throwable cause) { return new DefaultRpcResponse(cause); }
/** * Creates a new successfully complete {@link RpcResponse}. */ static RpcResponse of(@Nullable Object value) { return new DefaultRpcResponse(value); }
private static void handlePreDecodeException( ServiceRequestContext ctx, CompletableFuture<HttpResponse> httpRes, Throwable cause, SerializationFormat serializationFormat, int seqId, String methodName) { final HttpData content = encodeException( ctx, new DefaultRpcResponse(cause), serializationFormat, seqId, methodName, cause); respond(serializationFormat, content, httpRes); }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest call) throws Exception { final int colonPos = call.method().indexOf(':'); final String method; final String serviceName; if (colonPos < 0) { serviceName = ""; method = call.method(); } else { serviceName = call.method().substring(0, colonPos); method = call.method().substring(colonPos + 1); } // Ensure that such a service exists. final ThriftServiceEntry e = entries.get(serviceName); if (e != null) { // Ensure that such a method exists. final ThriftFunction f = e.metadata.function(method); if (f != null) { final DefaultRpcResponse reply = new DefaultRpcResponse(); invoke(ctx, e.implementation, f, call.params(), reply); return reply; } } return new DefaultRpcResponse(new TApplicationException( TApplicationException.UNKNOWN_METHOD, "unknown method: " + call.method())); }
/** * Creates a new {@link RpcResponse} that is completed successfully or exceptionally based on the * completion of the specified {@link CompletionStage}. */ static RpcResponse from(CompletionStage<?> stage) { requireNonNull(stage, "stage"); final DefaultRpcResponse res = new DefaultRpcResponse(); stage.handle((value, cause) -> { if (cause != null) { res.completeExceptionally(cause); } else if (value instanceof RpcResponse) { ((RpcResponse) value).handle((rpcResponseResult, rpcResponseCause) -> { if (rpcResponseCause != null) { res.completeExceptionally(Exceptions.peel(rpcResponseCause)); } else { res.complete(rpcResponseResult); } return null; }); } else { res.complete(value); } return null; }); return res; }
private void invoke( ServiceRequestContext ctx, SerializationFormat serializationFormat, int seqId, ThriftFunction func, RpcRequest call, CompletableFuture<HttpResponse> res) { final RpcResponse reply; try (SafeCloseable ignored = ctx.push()) { reply = delegate.serve(ctx, call); } catch (Throwable cause) { handleException(ctx, new DefaultRpcResponse(cause), res, serializationFormat, seqId, func, cause); return; } reply.handle((result, cause) -> { if (func.isOneWay()) { handleOneWaySuccess(ctx, reply, res, serializationFormat); return null; } if (cause != null) { handleException(ctx, reply, res, serializationFormat, seqId, func, cause); return null; } try { handleSuccess(ctx, reply, res, serializationFormat, seqId, func, result); } catch (Throwable t) { handleException(ctx, new DefaultRpcResponse(t), res, serializationFormat, seqId, func, t); } return null; }).exceptionally(CompletionActions::log); }
ctx.logBuilder().addChild(derivedCtx.log()); final BiFunction<ClientRequestContext, Throwable, RpcResponse> fallback = (context, cause) -> new DefaultRpcResponse(cause); final RpcResponse res = executeWithFallback(delegate(), derivedCtx, req, fallback);
final String method = call.method(); final List<Object> args = call.params(); final DefaultRpcResponse reply = new DefaultRpcResponse();
private static void handlePreDecodeException( ServiceRequestContext ctx, CompletableFuture<HttpResponse> httpRes, Throwable cause, SerializationFormat serializationFormat, int seqId, String methodName) { final HttpData content = encodeException( ctx, new DefaultRpcResponse(cause), serializationFormat, seqId, methodName, cause); respond(serializationFormat, content, httpRes); }
private static void handlePreDecodeException( ServiceRequestContext ctx, CompletableFuture<HttpResponse> httpRes, Throwable cause, SerializationFormat serializationFormat, int seqId, String methodName) { final HttpData content = encodeException( ctx, new DefaultRpcResponse(cause), serializationFormat, seqId, methodName, cause); respond(serializationFormat, content, httpRes); }
private static void handlePreDecodeException( ServiceRequestContext ctx, CompletableFuture<HttpResponse> httpRes, Throwable cause, SerializationFormat serializationFormat, int seqId, String methodName) { final HttpData content = encodeException( ctx, new DefaultRpcResponse(cause), serializationFormat, seqId, methodName, cause); respond(serializationFormat, content, httpRes); }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest call) throws Exception { final int colonPos = call.method().indexOf(':'); final String method; final String serviceName; if (colonPos < 0) { serviceName = ""; method = call.method(); } else { serviceName = call.method().substring(0, colonPos); method = call.method().substring(colonPos + 1); } // Ensure that such a service exists. final ThriftServiceEntry e = entries.get(serviceName); if (e != null) { // Ensure that such a method exists. final ThriftFunction f = e.metadata.function(method); if (f != null) { final DefaultRpcResponse reply = new DefaultRpcResponse(); invoke(ctx, e.implementation, f, call.params(), reply); return reply; } } return new DefaultRpcResponse(new TApplicationException( TApplicationException.UNKNOWN_METHOD, "unknown method: " + call.method())); }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest call) throws Exception { final int colonPos = call.method().indexOf(':'); final String method; final String serviceName; if (colonPos < 0) { serviceName = ""; method = call.method(); } else { serviceName = call.method().substring(0, colonPos); method = call.method().substring(colonPos + 1); } // Ensure that such a service exists. final ThriftServiceEntry e = entries.get(serviceName); if (e != null) { // Ensure that such a method exists. final ThriftFunction f = e.metadata.function(method); if (f != null) { final DefaultRpcResponse reply = new DefaultRpcResponse(); invoke(ctx, e.implementation, f, call.params(), reply); return reply; } } return new DefaultRpcResponse(new TApplicationException( TApplicationException.UNKNOWN_METHOD, "unknown method: " + call.method())); }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest req) throws Exception { final DefaultRpcResponse newRes = new DefaultRpcResponse(); try { final RpcResponse oldRes = delegate().serve(ctx, req); oldRes.handle((res, cause) -> { if (cause != null) { handleException(req, newRes, cause); } else { newRes.complete(res); } return null; }); } catch (Throwable cause) { handleException(req, newRes, cause); } return newRes; }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest req) throws Exception { final DefaultRpcResponse newRes = new DefaultRpcResponse(); try { final RpcResponse oldRes = delegate().serve(ctx, req); oldRes.handle((res, cause) -> { if (cause != null) { handleException(req, newRes, cause); } else { newRes.complete(res); } return null; }); } catch (Throwable cause) { handleException(req, newRes, cause); } return newRes; }
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest req) throws Exception { final DefaultRpcResponse newRes = new DefaultRpcResponse(); try { final RpcResponse oldRes = delegate().serve(ctx, req); oldRes.handle((res, cause) -> { if (cause != null) { handleException(req, newRes, cause); } else { newRes.complete(res); } return null; }); } catch (Throwable cause) { handleException(req, newRes, cause); } return newRes; }