@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { Optional<String> token = Optional.ofNullable(athenticationTokenManager.getToken()); if (!token.isPresent()) { asyncResp.consumerFail( new IllegalStateException("rejected by consumer authentication handler")); return; } invocation.addContext(Const.AUTH_TOKEN, token.get()); invocation.next(asyncResp); }
protected void doInvoke() throws Throwable { invocation.getInvocationStageTrace().startHandlersRequest(); invocation.next(resp -> sendResponseQuietly(resp)); }
@Override public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception { if (omegaContext != null) { String globalTxId = invocation.getContext().get(GLOBAL_TX_ID_KEY); if (globalTxId == null) { LOG.debug("Cannot inject transaction ID, no such header: {}", GLOBAL_TX_ID_KEY); } else { omegaContext.setGlobalTxId(globalTxId); omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY)); } } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null."); } try { invocation.next(asyncResponse); } finally { // Clean up the OmegaContext if(omegaContext != null) { omegaContext.clear(); } } } }
@Override public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception { if (omegaContext != null && omegaContext.globalTxId() != null) { invocation.getContext().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId()); invocation.getContext().put(LOCAL_TX_ID_KEY, omegaContext.localTxId()); LOG.debug("Added {} {} and {} {} to request header", GLOBAL_TX_ID_KEY, omegaContext.globalTxId(), LOCAL_TX_ID_KEY, omegaContext.localTxId()); } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null or cannot get the globalTxId."); } invocation.next(asyncResponse); } }
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { if (!Config.INSTANCE.isConsumerEnabled()) { invocation.next(asyncResp); return; } QpsController qpsController = qpsControllerMgr.getOrCreate(invocation.getMicroserviceName(), invocation); if (qpsController.isLimitNewRequest()) { // return http status 429 CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol"); asyncResp.consumerFail( new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData)); return; } invocation.next(asyncResp); } }
private boolean defineEndpointAndHandle(Invocation invocation, AsyncResponse asyncResp) throws Exception { String endpointUri = invocation.getLocalContext(SERVICECOMB_SERVER_ENDPOINT); if (endpointUri == null) { return false; } URI formatUri = new URI(endpointUri); Transport transport = SCBEngine.getInstance().getTransportManager().findTransport(formatUri.getScheme()); if (transport == null) { LOGGER.error("not deployed transport {}, ignore {}.", formatUri.getScheme(), endpointUri); throw new InvocationException(Status.BAD_REQUEST, "the endpoint's transport is not found."); } Endpoint endpoint = new Endpoint(transport, endpointUri); invocation.setEndpoint(endpoint); invocation.next(resp -> { asyncResp.handle(resp); }); return true; }
@Override protected Observable<Response> construct() { Observable<Response> observable = Observable.create(f -> { try { invocation.next(resp -> { if (isFailedResponse(resp)) { // e should implements toString LOG.warn("bizkeeper command {} failed due to {}", invocation.getInvocationQualifiedName(), resp.getResult()); f.onError(resp.getResult()); FallbackPolicyManager.record(type, invocation, resp, false); } else { f.onNext(resp); f.onCompleted(); FallbackPolicyManager.record(type, invocation, resp, true); } }); } catch (Exception e) { LOG.warn("bizkeeper command {} execute failed due to {}", invocation.getInvocationQualifiedName(), e.getClass().getName()); f.onError(e); } }); return observable; }
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { if (invocation.getHandlerIndex() > 0) { // handlerIndex > 0, which means this handler is executed in handler chain. // As this flow control logic has been executed in advance, this time it should be ignored. invocation.next(asyncResp); return; } // The real executing position of this handler is no longer in handler chain, but in AbstractRestInvocation. // Therefore, the Invocation#next() method should not be called below. if (!Config.INSTANCE.isProviderEnabled()) { return; } String microserviceName = invocation.getContext(Const.SRC_MICROSERVICE); QpsController qpsController = StringUtils.isEmpty(microserviceName) ? qpsControllerMgr.getGlobalQpsController() : qpsControllerMgr.getOrCreate(microserviceName, invocation); isLimitNewRequest(qpsController, asyncResp); }
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { String token = invocation.getContext(Const.AUTH_TOKEN); if (null != token && authenticationTokenManager.valid(token)) { invocation.next(asyncResp); } else { asyncResp.producerFail(new InvocationException(new HttpStatus(401, "UNAUTHORIZED"), "UNAUTHORIZED")); } } }
@SuppressWarnings({"try", "unused"}) @Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { Span span = tracingDelegate.createSpan(invocation); try (SpanInScope scope = tracer.tracer().withSpanInScope(span)) { LOGGER.debug("{}: Generated tracing span for {}", tracingDelegate.name(), invocation.getOperationName()); invocation.next(onResponse(invocation, asyncResp, span)); } catch (Exception e) { LOGGER.debug("{}: Failed invocation on {}", tracingDelegate.name(), invocation.getOperationName(), e); tracingDelegate.onResponse(span, null, e); throw e; } }
invocation.next(asyncResp);
private void doRunInExecutor() throws Exception { invocation.onExecuteStart(); invocation.getInvocationStageTrace().startServerFiltersRequest(); HighwayCodec.decodeRequest(invocation, header, operationProtobuf, bodyBuffer); invocation.getHandlerContext().put(Const.REMOTE_ADDRESS, this.connection.getNetSocket().remoteAddress()); invocation.getInvocationStageTrace().startHandlersRequest(); invocation.next(response -> { sendResponse(invocation.getContext(), response); }); }
/** * it's a internal API, caller make sure already invoked SCBEngine.ensureStatusUp * @param invocation * @return servicecomb response object */ public static Response innerSyncInvoke(Invocation invocation) { try { invocation.onStart(null, System.nanoTime()); SyncResponseExecutor respExecutor = new SyncResponseExecutor(); invocation.setResponseExecutor(respExecutor); invocation.getInvocationStageTrace().startHandlersRequest(); invocation.next(respExecutor::setResponse); Response response = respExecutor.waitResponse(); invocation.getInvocationStageTrace().finishHandlersResponse(); invocation.onFinish(response); return response; } catch (Throwable e) { String msg = String.format("invoke failed, %s", invocation.getOperationMeta().getMicroserviceQualifiedName()); LOGGER.error(msg, e); Response response = Response.createConsumerFail(e); invocation.onFinish(response); return response; } }
invocation.next(resp -> { if (isFailedResponse(resp)) { LOGGER.error("service {}, call error, msg is {}, server is {} ",
private void send(Invocation invocation, AsyncResponse asyncResp, final LoadBalancer chosenLB) throws Exception { long time = System.currentTimeMillis(); ServiceCombServer server = chosenLB.chooseServer(invocation); if (null == server) { asyncResp.consumerFail(new InvocationException(Status.INTERNAL_SERVER_ERROR, "No available address found.")); return; } chosenLB.getLoadBalancerStats().incrementNumRequests(server); invocation.setEndpoint(server.getEndpoint()); invocation.next(resp -> { // this stats is for WeightedResponseTimeRule chosenLB.getLoadBalancerStats().noteResponseTime(server, (System.currentTimeMillis() - time)); if (isFailedResponse(resp)) { chosenLB.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(server); ServiceCombLoadBalancerStats.INSTANCE.markFailure(server); } else { chosenLB.getLoadBalancerStats().incrementActiveRequestsCount(server); ServiceCombLoadBalancerStats.INSTANCE.markSuccess(server); } asyncResp.handle(resp); }); }
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { // prepare the key and lookup for request count. String key = invocation.getTransport().getName() + invocation.getMicroserviceQualifiedName(); AtomicLong reqCount = FaultInjectionUtil.getOperMetTotalReq(key); // increment the request count here after checking the delay/abort condition. long reqCountCurrent = reqCount.getAndIncrement(); FaultParam param = new FaultParam(reqCountCurrent); Context currentContext = Vertx.currentContext(); if (currentContext != null && currentContext.isEventLoopContext()) { param.setVertx(currentContext.owner()); } FaultExecutor executor = new FaultExecutor(faultInjectionFeatureList, invocation, param); executor.execute(response -> { try { if (response.isFailed()) { asyncResp.complete(response); } else { invocation.next(asyncResp); } } catch (Exception e) { asyncResp.consumerFail(e); } }); } }
invocation.next(ar -> { ContextUtils.setInvocationContext(invocation.getParentContext()); try {
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { if (!Config.INSTANCE.isProviderEnabled()) { invocation.next(asyncResp); return; } String microserviceName = invocation.getContext(Const.SRC_MICROSERVICE); QpsController qpsController = StringUtils.isEmpty(microserviceName) ? qpsControllerMgr.getGlobalQpsController() : qpsControllerMgr.getOrCreate(microserviceName, invocation); if (isLimitNewRequest(qpsController, asyncResp)) { return; } invocation.next(asyncResp); }
protected void doInvoke() throws Throwable { invocation.getInvocationStageTrace().startHandlersRequest(); invocation.next(resp -> { sendResponseQuietly(resp); }); }
private void doRunInExecutor() throws Exception { invocation.onExecuteStart(); invocation.getInvocationStageTrace().startServerFiltersRequest(); HighwayCodec.decodeRequest(invocation, header, operationProtobuf, bodyBuffer); invocation.getHandlerContext().put(Const.REMOTE_ADDRESS, this.connection.getNetSocket().remoteAddress()); invocation.getInvocationStageTrace().startHandlersRequest(); invocation.next(response -> { sendResponse(invocation.getContext(), response); }); }