use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
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 java-chassis by ServiceComb.
the class ServicePathManager method addProducerPaths.
private void addProducerPaths(String urlPrefix, Collection<RestOperationMeta> restOperationMetas) {
for (RestOperationMeta swaggerRestOperation : restOperationMetas) {
RestOperationMeta producerRestOperation = swaggerRestOperation;
if (!swaggerRestOperation.getAbsolutePath().startsWith(urlPrefix)) {
producerRestOperation = new RestOperationMeta();
producerRestOperation.init(swaggerRestOperation.getOperationMeta());
producerRestOperation.setAbsolutePath(urlPrefix + swaggerRestOperation.getAbsolutePath());
}
producerPaths.addResource(producerRestOperation);
}
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class ClientRestArgsFilter method beforeSendRequest.
@Override
@SuppressWarnings("unchecked")
public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) {
RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
try {
RestCodec.argsToRest(invocation.getSwaggerArguments(), swaggerRestOperation, restClientRequest);
requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertConsumerException(e);
}
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
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 java-chassis by ServiceComb.
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);
});
}
Aggregations