Search in sources :

Example 1 with RestClientRequestImpl

use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project incubator-servicecomb-java-chassis by apache.

the class ClientRestArgsFilter method beforeSendRequest.

@Override
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.getArgs(), swaggerRestOperation, restClientRequest);
        requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
    } catch (Throwable e) {
        throw ExceptionFactory.convertConsumerException(e);
    }
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 2 with RestClientRequestImpl

use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.

the class LocalHostAccessItem method appendClientFormattedItem.

/**
 * client do not need localhost
 */
@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() || StringUtils.isEmpty(restRequestImpl.getRequest().connection().localAddress().host())) {
        builder.append(EMPTY_RESULT);
        return;
    }
    builder.append(restRequestImpl.getRequest().connection().localAddress().host());
}
Also used : RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)

Example 3 with RestClientRequestImpl

use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.

the class RequestHeaderAccessItem method appendClientFormattedItem.

@Override
public void appendClientFormattedItem(InvocationFinishEvent clientLogEvent, StringBuilder builder) {
    RestClientRequestImpl restRequestImpl = (RestClientRequestImpl) clientLogEvent.getInvocation().getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
    if (null == restRequestImpl || null == restRequestImpl.getRequest() || null == restRequestImpl.getRequest().headers() || StringUtils.isEmpty(restRequestImpl.getRequest().headers().get(varName))) {
        builder.append(RESULT_NOT_FOUND);
        return;
    }
    builder.append(restRequestImpl.getRequest().headers().get(varName));
}
Also used : RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)

Example 4 with RestClientRequestImpl

use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.

the class CookieAccessItem 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.getCookieMap()) {
        builder.append(RESULT_NOT_FOUND);
        return;
    }
    for (Entry<String, String> entry : restRequestImpl.getCookieMap().entrySet()) {
        if (entry.getKey().equals(varName)) {
            builder.append(entry.getValue());
            return;
        }
    }
    builder.append(RESULT_NOT_FOUND);
}
Also used : RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)

Example 5 with RestClientRequestImpl

use of org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl in project incubator-servicecomb-java-chassis by apache.

the class VertxHttpMethod method doMethod.

public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String path = this.createRequestPath(invocation, swaggerRestOperation);
    IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
    HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, asyncResp);
    clientRequest.putHeader(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE, invocation.getMicroserviceName());
    RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest, httpClientWithContext.context().owner(), asyncResp);
    invocation.getHandlerContext().put(RestConst.INVOCATION_HANDLER_REQUESTCLIENT, restClientRequest);
    Buffer requestBodyBuffer = restClientRequest.getBodyBuffer();
    HttpServletRequestEx requestEx = new VertxClientRequestToHttpServletRequest(clientRequest, requestBodyBuffer);
    for (HttpClientFilter filter : httpClientFilters) {
        filter.beforeSendRequest(invocation, requestEx);
    }
    clientRequest.exceptionHandler(e -> {
        LOGGER.error(e.toString());
        asyncResp.fail(invocation.getInvocationType(), e);
    });
    // 从业务线程转移到网络线程中去发送
    httpClientWithContext.runOnContext(httpClient -> {
        this.setCseContext(invocation, clientRequest);
        clientRequest.setTimeout(AbstractTransport.getRequestTimeoutProperty().get());
        try {
            restClientRequest.end();
        } catch (Throwable e) {
            LOGGER.error("send http request failed,", e);
            asyncResp.fail(invocation.getInvocationType(), e);
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientFilter(org.apache.servicecomb.common.rest.filter.HttpClientFilter) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) VertxClientRequestToHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.VertxClientRequestToHttpServletRequest) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)

Aggregations

RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)11 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)6 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)4 Buffer (io.vertx.core.buffer.Buffer)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpClientFilter (org.apache.servicecomb.common.rest.filter.HttpClientFilter)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)2 VertxClientRequestToHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.VertxClientRequestToHttpServletRequest)2 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 HttpMethod (io.vertx.core.http.HttpMethod)1 RequestOptions (io.vertx.core.http.RequestOptions)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Status (javax.ws.rs.core.Response.Status)1 StringUtils (org.apache.commons.lang3.StringUtils)1 RestConst (org.apache.servicecomb.common.rest.RestConst)1 Const (org.apache.servicecomb.core.Const)1