@Override protected void channelRead0(final ChannelHandlerContext ctx, final Pair<RequestMessage, ThrowingConsumer<Context>> objects) throws Exception { final RequestMessage msg = objects.getValue0(); final ThrowingConsumer<Context> op = objects.getValue1(); final Context gremlinServerContext = new Context(msg, ctx, settings, graphManager, gremlinExecutor, scheduledExecutorService); try { op.accept(gremlinServerContext); } catch (OpProcessorException ope) { // Ops may choose to throw OpProcessorException or write the error ResponseMessage down the line // themselves logger.warn(ope.getMessage(), ope); ctx.writeAndFlush(ope.getResponseMessage()); } catch (Exception ex) { // It is possible that an unplanned exception might raise out of an OpProcessor execution. Build a general // error to send back to the client logger.warn(ex.getMessage(), ex); ctx.writeAndFlush(ResponseMessage.build(msg) .code(ResponseStatusCode.SERVER_ERROR) .statusAttributeException(ex) .statusMessage(ex.getMessage()).create()); } finally { ReferenceCountUtil.release(objects); } } }
final ResponseMessage error = ResponseMessage.build(o.getRequestId()) .statusMessage(errorMessage) .statusAttributeException(ex) .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create(); if (useBinary) {
ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); return; ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); } finally { ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create());
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider") .statusAttributeException(t).create()); } else if (t instanceof TimeoutException) { final String errorMessage = String.format("Script evaluation exceeded the configured threshold for request [%s]", msg); rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage(t.getMessage()) .statusAttributeException(t).create()); } else { rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(errorMessage) .statusAttributeException(t).create()); } else { logger.warn(String.format("Exception processing a script on request [%s].", msg), t); rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(t.getMessage()) .statusAttributeException(t).create());
ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage(errorMessage) .statusAttributeException(ex).create()); onError(graph, context); } else { ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); } finally {
ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); return; ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); } finally { ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create());
final ResponseMessage error = ResponseMessage.build(o.getRequestId()) .statusMessage(errorMessage) .statusAttributeException(ex) .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create(); if (useBinary) {
final ResponseMessage error = ResponseMessage.build(msg.getRequestId()) .statusMessage(errorMessage) .statusAttributeException(ex) .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create(); rhc.writeAndFlush(error);
/** * A generalized implementation of the "eval" operation. It handles script evaluation and iteration of results * so as to write {@link ResponseMessage} objects down the Netty pipeline. It also handles script timeouts, * iteration timeouts, metrics and building bindings. Note that result iteration is delegated to the * {@link #handleIterator} method, so those extending this class could override that method for better control * over result iteration. * * @param context The current Gremlin Server {@link Context} * @param gremlinExecutorSupplier A function that returns the {@link GremlinExecutor} to use in executing the * script evaluation. * @param bindingsSupplier A function that returns the {@link Bindings} to provide to the * {@link GremlinExecutor#eval} method. * @see #evalOpInternal(ResponseHandlerContext, Supplier, BindingSupplier) */ protected void evalOpInternal(final Context context, final Supplier<GremlinExecutor> gremlinExecutorSupplier, final BindingSupplier bindingsSupplier) throws OpProcessorException { final ResponseHandlerContext rhc = new ResponseHandlerContext(context); try { evalOpInternal(rhc, gremlinExecutorSupplier, bindingsSupplier); } catch (Exception ex) { // Exceptions may occur on after the script started executing, therefore corresponding errors must be // reported via the ResponseHandlerContext. logger.warn("Unable to process script evaluation request: " + ex, ex); rhc.writeAndFlush(ResponseMessage.build(context.getRequestMessage()) .code(ResponseStatusCode.SERVER_ERROR) .statusAttributeException(ex) .statusMessage(ex.getMessage()).create()); } }
@Override protected void channelRead0(final ChannelHandlerContext ctx, final Pair<RequestMessage, ThrowingConsumer<Context>> objects) throws Exception { final RequestMessage msg = objects.getValue0(); final ThrowingConsumer<Context> op = objects.getValue1(); final Context gremlinServerContext = new Context(msg, ctx, settings, graphManager, gremlinExecutor, scheduledExecutorService); try { op.accept(gremlinServerContext); } catch (OpProcessorException ope) { // Ops may choose to throw OpProcessorException or write the error ResponseMessage down the line // themselves logger.warn(ope.getMessage(), ope); ctx.writeAndFlush(ope.getResponseMessage()); } catch (Exception ex) { // It is possible that an unplanned exception might raise out of an OpProcessor execution. Build a general // error to send back to the client logger.warn(ex.getMessage(), ex); ctx.writeAndFlush(ResponseMessage.build(msg) .code(ResponseStatusCode.SERVER_ERROR) .statusAttributeException(ex) .statusMessage(ex.getMessage()).create()); } finally { ReferenceCountUtil.release(objects); } } }
private void handleIterator(Context context, Traversal traversal) { try { super.handleIterator(context, traversal); } catch (Exception ex) { logger.error("Error during traversal iteration", ex); ChannelHandlerContext ctx = context.getChannelHandlerContext(); ctx.writeAndFlush(ResponseMessage.build(context.getRequestMessage()) .code(SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex) .create()); } }
ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage(errorMessage) .statusAttributeException(ex).create()); onError(graph, context); } else { ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR) .statusMessage(ex.getMessage()) .statusAttributeException(ex).create()); onError(graph, context); } finally {
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider") .statusAttributeException(t).create()); } else if (t instanceof TimeoutException) { final String errorMessage = String.format("Script evaluation exceeded the configured threshold for request [%s]", msg); rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT) .statusMessage(t.getMessage()) .statusAttributeException(t).create()); } else { rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(errorMessage) .statusAttributeException(t).create()); } else { logger.warn(String.format("Exception processing a script on request [%s].", msg), t); rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(t.getMessage()) .statusAttributeException(t).create());
final ResponseMessage error = ResponseMessage.build(msg.getRequestId()) .statusMessage(errorMessage) .statusAttributeException(ex) .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create(); rhc.writeAndFlush(error);
/** * A generalized implementation of the "eval" operation. It handles script evaluation and iteration of results * so as to write {@link ResponseMessage} objects down the Netty pipeline. It also handles script timeouts, * iteration timeouts, metrics and building bindings. Note that result iteration is delegated to the * {@link #handleIterator} method, so those extending this class could override that method for better control * over result iteration. * * @param context The current Gremlin Server {@link Context} * @param gremlinExecutorSupplier A function that returns the {@link GremlinExecutor} to use in executing the * script evaluation. * @param bindingsSupplier A function that returns the {@link Bindings} to provide to the * {@link GremlinExecutor#eval} method. * @see #evalOpInternal(ResponseHandlerContext, Supplier, BindingSupplier) */ protected void evalOpInternal(final Context context, final Supplier<GremlinExecutor> gremlinExecutorSupplier, final BindingSupplier bindingsSupplier) throws OpProcessorException { final ResponseHandlerContext rhc = new ResponseHandlerContext(context); try { evalOpInternal(rhc, gremlinExecutorSupplier, bindingsSupplier); } catch (Exception ex) { // Exceptions may occur on after the script started executing, therefore corresponding errors must be // reported via the ResponseHandlerContext. logger.warn("Unable to process script evaluation request: " + ex, ex); rhc.writeAndFlush(ResponseMessage.build(context.getRequestMessage()) .code(ResponseStatusCode.SERVER_ERROR) .statusAttributeException(ex) .statusMessage(ex.getMessage()).create()); } }