Search in sources :

Example 21 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) NormalWrapSchema(io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) Test(org.junit.Test)

Example 22 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class AbstractRestServer method handleRequest.

protected void handleRequest(RestServerRequestInternal restRequest, HTTP_RESPONSE httpResponse) {
    try {
        RestOperationMeta restOperation = findRestOperation(restRequest);
        OperationMeta operationMeta = restOperation.getOperationMeta();
        operationMeta.getExecutor().execute(() -> {
            try {
                runOnExecutor(restRequest, restOperation, httpResponse);
            } catch (Exception e) {
                LOGGER.error("rest server onRequest error", e);
                sendFailResponse(restRequest, httpResponse, e);
            }
        });
    } catch (Exception e) {
        LOGGER.error("rest server onRequest error", e);
        sendFailResponse(restRequest, httpResponse, e);
    }
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) InvocationException(io.servicecomb.core.exception.InvocationException)

Example 23 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class MockUtil method mockRequestMeta.

public void mockRequestMeta() {
    new MockUp<RequestMeta>() {

        @Mock
        public OperationMeta getOperationMeta() throws Exception {
            OperationMeta om = new OperationMeta();
            om.init(new SchemaMeta(null, new MicroserviceMeta("test"), null), this.getClass().getMethods()[0], "path", "get", null);
            return om;
        }
    };
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 24 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestHttpRequestParamCreator method testCreateMockParam.

@Test
public void testCreateMockParam() throws Exception {
    ProducerHttpRequestArgMapper lHttpRequestParamCreator = new ProducerHttpRequestArgMapper(0);
    Invocation invocation = Mockito.mock(Invocation.class);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    RestOperationMeta swaggerOperation = Mockito.mock(RestOperationMeta.class);
    Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerOperation);
    HttpServletRequest lHttpServletRequest = (HttpServletRequest) lHttpRequestParamCreator.createContextArg(invocation);
    Assert.assertNull(lHttpServletRequest.getMethod());
}
Also used : ProducerHttpRequestArgMapper(io.servicecomb.provider.rest.common.ProducerHttpRequestArgMapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 25 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class RestEngineSchemaListener method onSchemaLoaded.

@Override
public void onSchemaLoaded(SchemaMeta... schemaMetas) {
    // 此时相应的ServicePathManager可能正在被使用,为避免太高的复杂度,使用copy on write逻辑
    Map<String, ServicePathManager> mgrMap = new HashMap<>();
    for (SchemaMeta schemaMeta : schemaMetas) {
        MicroserviceMeta microserviceMeta = schemaMeta.getMicroserviceMeta();
        ServicePathManager mgr = findPathManager(mgrMap, microserviceMeta);
        if (mgr.isSchemaExists(schemaMeta.getSchemaId())) {
            LOGGER.info("on schema loaded, exists schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
            continue;
        }
        LOGGER.info("on schema loaded, new schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
        mgr.addSchema(schemaMeta.getSchemaId());
        for (OperationMeta operationMeta : schemaMeta.getOperations()) {
            RestOperationMeta restOperationMeta = new RestOperationMeta();
            restOperationMeta.init(operationMeta);
            operationMeta.putExtData(RestConst.SWAGGER_REST_OPERATION, restOperationMeta);
            mgr.addResource(restOperationMeta);
        }
    }
    for (ServicePathManager mgr : mgrMap.values()) {
        // 对具有动态path operation进行排序
        mgr.sortPath();
        mgr.printService();
        mgr.saveToMicroserviceMeta();
    }
}
Also used : HashMap(java.util.HashMap) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Aggregations

OperationMeta (io.servicecomb.core.definition.OperationMeta)36 Test (org.junit.Test)18 Invocation (io.servicecomb.core.Invocation)15 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)12 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)8 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)7 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)6 AsyncResponse (io.servicecomb.core.AsyncResponse)6 Endpoint (io.servicecomb.core.Endpoint)6 Response (io.servicecomb.core.Response)5 InvocationException (io.servicecomb.core.exception.InvocationException)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)5 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)4 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)4 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)4 Buffer (io.vertx.core.buffer.Buffer)4 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 IpPort (io.servicecomb.foundation.common.net.IpPort)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3