Search in sources :

Example 41 with RestOperationMeta

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());
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 42 with RestOperationMeta

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);
    }
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 43 with RestOperationMeta

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);
    }
}
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 44 with RestOperationMeta

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);
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 45 with RestOperationMeta

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);
    });
}
Also used : CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) OperationConfig(org.apache.servicecomb.core.definition.OperationConfig) VertxClientRequestToHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.VertxClientRequestToHttpServletRequest) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) RequestOptions(io.vertx.core.http.RequestOptions) DefinitionConst(org.apache.servicecomb.registry.definition.DefinitionConst) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) StringUtils(org.apache.commons.lang3.StringUtils) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) ExceptionUtils(org.apache.servicecomb.foundation.common.utils.ExceptionUtils) JsonUtils(org.apache.servicecomb.foundation.common.utils.JsonUtils) ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) RestConst(org.apache.servicecomb.common.rest.RestConst) HttpClientFilter(org.apache.servicecomb.common.rest.filter.HttpClientFilter) Status(javax.ws.rs.core.Response.Status) Response(org.apache.servicecomb.swagger.invocation.Response) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace) HttpStatus(org.apache.servicecomb.foundation.common.http.HttpStatus) Logger(org.slf4j.Logger) HttpClientWithContext(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext) VertxClientResponseToHttpServletResponse(org.apache.servicecomb.foundation.vertx.http.VertxClientResponseToHttpServletResponse) Const(org.apache.servicecomb.core.Const) Future(io.vertx.core.Future) Invocation(org.apache.servicecomb.core.Invocation) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Handler(io.vertx.core.Handler) Buffer(io.vertx.core.buffer.Buffer) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientFilter(org.apache.servicecomb.common.rest.filter.HttpClientFilter) 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) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) TimeoutException(java.util.concurrent.TimeoutException) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)

Aggregations

RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)55 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)24 Test (org.junit.Test)20 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)10 Response (org.apache.servicecomb.swagger.invocation.Response)9 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)9 InvocationStageTrace (org.apache.servicecomb.core.invocation.InvocationStageTrace)8 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)7 Invocation (org.apache.servicecomb.core.Invocation)6 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)6 HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)5 HttpMethod (io.vertx.core.http.HttpMethod)5 HashMap (java.util.HashMap)5 RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)5 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)5 HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)5 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)4 RequestOptions (io.vertx.core.http.RequestOptions)4