本文整理了Java中org.apache.servicecomb.swagger.invocation.AsyncResponse.consumerFail()
方法的一些代码示例,展示了AsyncResponse.consumerFail()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AsyncResponse.consumerFail()
方法的具体详情如下:
包路径:org.apache.servicecomb.swagger.invocation.AsyncResponse
类名称:AsyncResponse
方法名:consumerFail
暂无
代码示例来源:origin: apache/servicecomb-java-chassis
private void fail(Throwable finalException) {
int depth = 10;
Throwable t = finalException;
while (depth-- > 0) {
if (t instanceof InvocationException) {
asyncResp.consumerFail(t);
return;
}
t = finalException.getCause();
}
asyncResp.consumerFail(finalException);
}
};
代码示例来源:origin: apache/servicecomb-java-chassis
@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);
}
代码示例来源:origin: apache/servicecomb-java-chassis
protected void doEndNormal() {
try {
genBodyBuffer();
} catch (Exception e) {
asyncResp.consumerFail(e);
return;
}
if (bodyBuffer == null) {
request.end();
return;
}
request.end(bodyBuffer);
}
代码示例来源:origin: apache/servicecomb-java-chassis
private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
if (!uploadsIterator.hasNext()) {
request.write(boundaryEndInfo(boundary));
request.end();
return;
}
Entry<String, Part> entry = uploadsIterator.next();
// do not use part.getName() to get parameter name
// because pojo consumer not easy to set name to part
String name = entry.getKey();
Part part = entry.getValue();
String filename = part.getSubmittedFileName();
Buffer fileHeader = fileBoundaryInfo(boundary, name, part);
request.write(fileHeader);
new PumpFromPart(context, part).toWriteStream(request).whenComplete((v, e) -> {
if (e != null) {
LOGGER.debug("Failed to sending file [{}:{}].", name, filename, e);
asyncResp.consumerFail(e);
return;
}
LOGGER.debug("finish sending file [{}:{}].", name, filename);
attachFile(boundary, uploadsIterator);
});
}
代码示例来源:origin: apache/servicecomb-java-chassis
private void genBodyForm(String boundary) {
if (formMap == null) {
return;
}
try {
try (BufferOutputStream output = new BufferOutputStream()) {
for (Entry<String, Object> entry : formMap.entrySet()) {
output.write(bytesOf("\r\n"));
output.write(bytesOf("--" + boundary + "\r\n"));
output.write(bytesOf("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"\r\n\r\n"));
if (entry.getValue() != null) {
String value = RestObjectMapperFactory.getRestObjectMapper().convertToString(entry.getValue());
output.write(value.getBytes(StandardCharsets.UTF_8));
}
}
request.write(output.getBuffer());
}
} catch (Exception e) {
asyncResp.consumerFail(e);
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public void injectFault(Invocation invocation, FaultParam faultParam, AsyncResponse asyncResponse) {
if (!shouldAbort(invocation, faultParam)) {
asyncResponse.success(SUCCESS_RESPONSE);
return;
}
// get the config values related to abort percentage.
int errorCode = FaultInjectionUtil.getFaultInjectionConfig(invocation, "abort.httpStatus");
if (errorCode == FaultInjectionConst.FAULT_INJECTION_DEFAULT_VALUE) {
LOGGER.debug("Fault injection: Abort error code is not configured");
asyncResponse.success(SUCCESS_RESPONSE);
return;
}
// if request need to be abort then return failure with given error code
CommonExceptionData errorData = new CommonExceptionData(ABORTED_ERROR_MSG);
asyncResponse.consumerFail(new InvocationException(errorCode, ABORTED_ERROR_MSG, errorData));
}
代码示例来源:origin: apache/servicecomb-java-chassis
invocation.getMicroserviceVersionRule());
if (endpointsVersionedCache.isEmpty()) {
asyncResp.consumerFail(ExceptionUtils.lbAddressNotFound(invocation.getMicroserviceName(),
invocation.getMicroserviceVersionRule(),
endpointsVersionedCache.name()));
代码示例来源:origin: apache/servicecomb-java-chassis
@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);
}
}
代码示例来源:origin: org.apache.servicecomb/handler-loadbalance
private void fail(Throwable finalException) {
int depth = 10;
Throwable t = finalException;
while (depth-- > 0) {
if (t instanceof InvocationException) {
asyncResp.consumerFail(t);
return;
}
t = finalException.getCause();
}
asyncResp.consumerFail(finalException);
}
};
代码示例来源: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: apache/servicecomb-java-chassis
@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);
}
});
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
asyncResp.consumerFail(ar.cause());
return;
} catch (Throwable e) {
invocation.getInvocationStageTrace().finishClientFiltersResponse();
asyncResp.consumerFail(e);
代码示例来源:origin: org.apache.servicecomb/common-rest
protected void doEndNormal() {
try {
genBodyBuffer();
} catch (Exception e) {
asyncResp.consumerFail(e);
return;
}
if (bodyBuffer == null) {
request.end();
return;
}
request.end(bodyBuffer);
}
代码示例来源:origin: org.apache.servicecomb/common-rest
private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
if (!uploadsIterator.hasNext()) {
request.write(boundaryEndInfo(boundary));
request.end();
return;
}
Entry<String, Part> entry = uploadsIterator.next();
// do not use part.getName() to get parameter name
// because pojo consumer not easy to set name to part
String name = entry.getKey();
Part part = entry.getValue();
String filename = part.getSubmittedFileName();
Buffer fileHeader = fileBoundaryInfo(boundary, name, part);
request.write(fileHeader);
new PumpFromPart(context, part).toWriteStream(request).whenComplete((v, e) -> {
if (e != null) {
LOGGER.debug("Failed to sending file [{}:{}].", name, filename, e);
asyncResp.consumerFail(e);
return;
}
LOGGER.debug("finish sending file [{}:{}].", name, filename);
attachFile(boundary, uploadsIterator);
});
}
代码示例来源:origin: org.apache.servicecomb/handler-fault-injection
@Override
public void injectFault(Invocation invocation, FaultParam faultParam, AsyncResponse asyncResponse) {
if (!shouldAbort(invocation, faultParam)) {
asyncResponse.success(SUCCESS_RESPONSE);
return;
}
// get the config values related to abort percentage.
int errorCode = FaultInjectionUtil.getFaultInjectionConfig(invocation, "abort.httpStatus");
if (errorCode == FaultInjectionConst.FAULT_INJECTION_DEFAULT_VALUE) {
LOGGER.debug("Fault injection: Abort error code is not configured");
asyncResponse.success(SUCCESS_RESPONSE);
return;
}
// if request need to be abort then return failure with given error code
CommonExceptionData errorData = new CommonExceptionData(ABORTED_ERROR_MSG);
asyncResponse.consumerFail(new InvocationException(errorCode, ABORTED_ERROR_MSG, errorData));
}
代码示例来源:origin: org.apache.servicecomb/common-rest
private void genBodyForm(String boundary) {
if (formMap == null) {
return;
}
try {
try (BufferOutputStream output = new BufferOutputStream()) {
for (Entry<String, Object> entry : formMap.entrySet()) {
output.write(bytesOf("\r\n"));
output.write(bytesOf("--" + boundary + "\r\n"));
output.write(bytesOf("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"\r\n\r\n"));
if (entry.getValue() != null) {
String value = RestObjectMapperFactory.getRestObjectMapper().convertToString(entry.getValue());
output.write(value.getBytes(StandardCharsets.UTF_8));
}
}
request.write(output.getBuffer());
}
} catch (Exception e) {
asyncResp.consumerFail(e);
}
}
代码示例来源:origin: org.apache.servicecomb/java-chassis-core
invocation.getMicroserviceVersionRule());
if (endpointsVersionedCache.isEmpty()) {
asyncResp.consumerFail(ExceptionUtils.lbAddressNotFound(invocation.getMicroserviceName(),
invocation.getMicroserviceVersionRule(),
endpointsVersionedCache.name()));
代码示例来源:origin: org.apache.servicecomb/handler-flowcontrol-qps
@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);
}
}
代码示例来源:origin: org.apache.servicecomb/handler-loadbalance
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/handler-fault-injection
@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);
}
});
}
}
内容来源于网络,如有侵权,请联系作者删除!