org.apache.servicecomb.swagger.invocation.AsyncResponse.handle()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.apache.servicecomb.swagger.invocation.AsyncResponse.handle()方法的一些代码示例,展示了AsyncResponse.handle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AsyncResponse.handle()方法的具体详情如下:
包路径:org.apache.servicecomb.swagger.invocation.AsyncResponse
类名称:AsyncResponse
方法名:handle

AsyncResponse.handle介绍

暂无

代码示例

代码示例来源:origin: apache/servicecomb-java-chassis

default void complete(Response resp) {
  handle(resp);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void success(Object result) {
 handle(Response.ok(result));
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void consumerFail(Throwable e) {
 handle(Response.createConsumerFail(e));
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void fail(InvocationType type, Throwable e) {
 handle(Response.createFail(type, e));
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void producerFail(Throwable e) {
 handle(Response.createProducerFail(e));
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void success(StatusType status, Object result) {
 handle(Response.status(status).entity(result));
}

代码示例来源:origin: apache/servicecomb-java-chassis

public void syncInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
 ContextUtils.setInvocationContext(invocation);
 Response response = doInvoke(invocation);
 ContextUtils.removeInvocationContext();
 asyncResp.handle(response);
}

代码示例来源:origin: apache/servicecomb-java-chassis

private AsyncResponse onResponse(Invocation invocation, AsyncResponse asyncResp, Span span) {
  return response -> {
   Throwable error = response.isFailed() ? response.getResult() : null;
   tracingDelegate.onResponse(span, response, error);

   LOGGER.debug("{}: Completed invocation on {}",
     tracingDelegate.name(),
     invocation.getOperationName(),
     error);

   asyncResp.handle(response);
  };
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

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;
}

代码示例来源:origin: apache/servicecomb-java-chassis

@SuppressWarnings("unchecked")
public void doCompletableFutureInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
 try {
  invocation.onBusinessMethodStart();
  Object[] args = argumentsMapper.toProducerArgs(invocation);
  for (ProducerInvokeExtension producerInvokeExtension : producerInvokeExtenstionList) {
   producerInvokeExtension.beforeMethodInvoke(invocation, this, args);
  }
  Object result = producerMethod.invoke(producerInstance, args);
  invocation.onBusinessMethodFinish();
  ((CompletableFuture<Object>) result).whenComplete((realResult, ex) -> {
   invocation.onBusinessFinish();
   if (ex == null) {
    asyncResp.handle(responseMapper.mapResponse(invocation.getStatus(), realResult));
    return;
   }
   asyncResp.handle(processException(invocation, ex));
  });
 } catch (IllegalArgumentException ae) {
  invocation.onBusinessMethodFinish();
  invocation.onBusinessFinish();
  asyncResp.handle(processException(invocation,
    new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
      new CommonExceptionData("Parameters not valid or types not match."), ae)));
 } catch (Throwable e) {
  invocation.onBusinessMethodFinish();
  invocation.onBusinessFinish();
  asyncResp.handle(processException(invocation, e));
 }
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void complete(Response resp) {
  handle(resp);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

invocation.getInvocationStageTrace().finishHandlersResponse();
  invocation.onFinish(ar);
  asyncResp.handle(ar);
 } finally {
  ContextUtils.removeInvocationContext();
invocation.onFinish(response);
LOGGER.error("invoke failed, {}", invocation.getOperationMeta().getMicroserviceQualifiedName());
asyncResp.handle(response);

代码示例来源:origin: apache/servicecomb-java-chassis

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);
 });
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void success(Object result) {
 handle(Response.ok(result));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void consumerFail(Throwable e) {
 handle(Response.createConsumerFail(e));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void producerFail(Throwable e) {
 handle(Response.createProducerFail(e));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void fail(InvocationType type, Throwable e) {
 handle(Response.createFail(type, e));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

default void success(StatusType status, Object result) {
 handle(Response.status(status).entity(result));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-core

public void syncInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
 ContextUtils.setInvocationContext(invocation);
 Response response = doInvoke(invocation);
 ContextUtils.removeInvocationContext();
 asyncResp.handle(response);
}

代码示例来源:origin: org.apache.servicecomb/handler-tracing-zipkin

private AsyncResponse onResponse(Invocation invocation, AsyncResponse asyncResp, Span span) {
  return response -> {
   Throwable error = response.isFailed() ? response.getResult() : null;
   tracingDelegate.onResponse(span, response, error);

   LOGGER.debug("{}: Completed invocation on {}",
     tracingDelegate.name(),
     invocation.getOperationName(),
     error);

   asyncResp.handle(response);
  };
 }
}

相关文章