use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl 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.codec.param.RestClientRequestImpl 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);
});
}
use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.
the class HttpMethodAccessItem method appendClientFormattedItem.
@Override
public void appendClientFormattedItem(InvocationFinishEvent finishEvent, StringBuilder builder) {
OperationMeta operationMeta = finishEvent.getInvocation().getOperationMeta();
if (operationMeta != null && !StringUtils.isEmpty(operationMeta.getHttpMethod())) {
builder.append(operationMeta.getHttpMethod());
return;
}
RestClientRequestImpl restRequestImpl = (RestClientRequestImpl) finishEvent.getInvocation().getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
if (null == restRequestImpl || null == restRequestImpl.getRequest() || null == restRequestImpl.getRequest().getMethod()) {
builder.append(EMPTY_RESULT);
return;
}
builder.append(restRequestImpl.getRequest().getMethod().toString());
}
use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.
the class LocalPortAccessItem method appendClientFormattedItem.
@Override
public void appendClientFormattedItem(InvocationFinishEvent finishEvent, StringBuilder builder) {
RestClientRequestImpl restRequestImpl = (RestClientRequestImpl) finishEvent.getInvocation().getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
if (null == restRequestImpl || null == restRequestImpl.getRequest() || null == restRequestImpl.getRequest().connection() || null == restRequestImpl.getRequest().connection().localAddress()) {
builder.append(EMPTY_RESULT);
return;
}
builder.append(restRequestImpl.getRequest().connection().localAddress().port());
}
use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.
the class QueryStringAccessItem method appendClientFormattedItem.
@Override
public void appendClientFormattedItem(InvocationFinishEvent finishEvent, StringBuilder builder) {
RestClientRequestImpl restRequestImpl = (RestClientRequestImpl) finishEvent.getInvocation().getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
if (null == restRequestImpl || null == restRequestImpl.getRequest() || StringUtils.isEmpty(restRequestImpl.getRequest().query())) {
builder.append(EMPTY_RESULT);
return;
}
builder.append(restRequestImpl.getRequest().query());
}
Aggregations