use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestMicroservicePaths method staticGroup.
@Test
public void staticGroup() {
RestOperationMeta meta = paths.getStaticPathOperationMap().get("/static/").findValue("POST");
Assert.assertSame("postStatic", meta.getOperationMeta().getOperationId());
meta = paths.getStaticPathOperationMap().get("/static/").findValue("GET");
Assert.assertSame("getStatic", meta.getOperationMeta().getOperationId());
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class SlowInvocationLogger method logSlowProducer.
private void logSlowProducer(Invocation invocation, Response response, OperationConfig operationConfig) {
RestOperationMeta restOperationMeta = invocation.getOperationMeta().getExtData(RestConst.SWAGGER_REST_OPERATION);
InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
invocation.getTraceIdLogger().warn(LOGGER, "" + "slow({} ms) invocation, {}:\n" + " http method: {}\n" + " url : {}\n" + " client : {}\n" + " status code: {}\n" + " total : {} ms\n" + " prepare : {} ms\n" + " threadPoolQueue : {} ms\n" + " server filters request : {} ms\n" + " handlers request : {} ms\n" + " business execute : {} ms\n" + " handlers response : {} ms\n" + " server filters response: {} ms\n" + " send response : {} ms", operationConfig.getMsSlowInvocation(), invocation.getInvocationQualifiedName(), restOperationMeta.getHttpMethod(), restOperationMeta.getAbsolutePath(), collectClientAddress(invocation), response.getStatusCode(), formatTime(stageTrace.calcTotalTime()), formatTime(stageTrace.calcInvocationPrepareTime()), formatTime(stageTrace.calcThreadPoolQueueTime()), formatTime(stageTrace.calcServerFiltersRequestTime()), formatTime(stageTrace.calcHandlersRequestTime()), formatTime(stageTrace.calcBusinessTime()), formatTime(stageTrace.calcHandlersResponseTime()), formatTime(stageTrace.calcServerFiltersResponseTime()), formatTime(stageTrace.calcSendResponseTime()));
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestRequestMeta method testGetSwaggerRestOperation.
@Test
public void testGetSwaggerRestOperation() {
RestOperationMeta value = requestmeta.getSwaggerRestOperation();
Assert.assertNotNull(value);
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class RestClientInvocation method invoke.
public void invoke(Invocation invocation, AsyncResponse asyncResp) throws Exception {
this.invocation = invocation;
this.asyncResp = asyncResp;
OperationMeta operationMeta = invocation.getOperationMeta();
restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
String path = this.createRequestPath(restOperationMeta);
IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
Future<HttpClientRequest> requestFuture = createRequest(ipPort, path);
invocation.getInvocationStageTrace().startGetConnection();
requestFuture.compose(clientRequest -> {
invocation.getInvocationStageTrace().finishGetConnection();
this.clientRequest = clientRequest;
clientRequest.putHeader(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE, invocation.getMicroserviceName());
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest, httpClientWithContext.context(), asyncResp, throwableHandler);
invocation.getHandlerContext().put(RestConst.INVOCATION_HANDLER_REQUESTCLIENT, restClientRequest);
Buffer requestBodyBuffer;
try {
requestBodyBuffer = restClientRequest.getBodyBuffer();
} catch (Exception e) {
return Future.failedFuture(e);
}
HttpServletRequestEx requestEx = new VertxClientRequestToHttpServletRequest(clientRequest, requestBodyBuffer);
invocation.getInvocationStageTrace().startClientFiltersRequest();
for (HttpClientFilter filter : httpClientFilters) {
if (filter.enabled()) {
filter.beforeSendRequest(invocation, requestEx);
}
}
// 从业务线程转移到网络线程中去发送
invocation.onStartSendRequest();
httpClientWithContext.runOnContext(httpClient -> {
clientRequest.setTimeout(operationMeta.getConfig().getMsRequestTimeout());
clientRequest.response().onComplete(asyncResult -> {
if (asyncResult.failed()) {
fail(asyncResult.cause());
return;
}
handleResponse(asyncResult.result());
});
processServiceCombHeaders(invocation, operationMeta);
restClientRequest.end().onComplete((t) -> invocation.getInvocationStageTrace().finishWriteToBuffer(System.nanoTime()));
});
return Future.succeededFuture();
}).onFailure(failure -> {
invocation.getTraceIdLogger().error(LOGGER, "Failed to send request, alreadyFailed:{}, local:{}, remote:{}, message={}.", alreadyFailed, getLocalAddress(), ipPort.getSocketAddress(), ExceptionUtils.getExceptionMessageWithoutTrace(failure));
throwableHandler.handle(failure);
});
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class DefaultHttpClientFilter method extractResponse.
protected Response extractResponse(Invocation invocation, HttpServletResponseEx responseEx) {
Object result = invocation.getHandlerContext().get(RestConst.READ_STREAM_PART);
if (result != null) {
return Response.create(responseEx.getStatusType(), result);
}
OperationMeta operationMeta = invocation.getOperationMeta();
JavaType responseType = invocation.findResponseType(responseEx.getStatus());
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
ProduceProcessor produceProcessor = findProduceProcessor(swaggerRestOperation, responseEx);
if (produceProcessor == null) {
// This happens outside the runtime such as Servlet filter response. Here we give a default json parser to it
// and keep user data not get lose.
String msg = String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", swaggerRestOperation.getHttpMethod(), swaggerRestOperation.getAbsolutePath(), responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
LOGGER.warn(msg);
produceProcessor = ProduceProcessorManager.INSTANCE.findDefaultProcessor();
}
try {
result = produceProcessor.decodeResponse(responseEx.getBodyBuffer(), responseType);
Response response = Response.create(responseEx.getStatusType(), result);
if (response.isFailed()) {
LOGGER.warn("invoke operation [{}] failed, status={}, msg={}", invocation.getMicroserviceQualifiedName(), responseEx.getStatusType().getStatusCode(), result == null ? "" : result.toString());
}
return response;
} catch (Exception e) {
LOGGER.error("failed to decode response body, exception is [{}]", e.getMessage());
String msg = String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", swaggerRestOperation.getHttpMethod(), swaggerRestOperation.getAbsolutePath(), responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
if (HttpStatus.isSuccess(responseEx.getStatus())) {
return Response.createConsumerFail(new InvocationException(400, responseEx.getStatusType().getReasonPhrase(), new CommonExceptionData(msg), e));
}
return Response.createConsumerFail(new InvocationException(responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), new CommonExceptionData(msg), e));
}
}
Aggregations