Search in sources :

Example 6 with ServicePathManager

use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project java-chassis by ServiceComb.

the class CseClientHttpRequest method createRequestMeta.

protected RequestMeta createRequestMeta(String httpMethod, URI uri) {
    String microserviceName = uri.getAuthority();
    MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(microserviceName);
    MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager == null) {
        throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName()));
    }
    OperationLocator locator = servicePathManager.consumerLocateOperation(path, httpMethod);
    RestOperationMeta swaggerRestOperation = locator.getOperation();
    OperationMeta operationMeta = locator.getOperation().getOperationMeta();
    ReferenceConfig referenceConfig = microserviceReferenceConfig.createReferenceConfig(operationMeta);
    Map<String, String> pathParams = locator.getPathVarMap();
    return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(org.apache.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 7 with ServicePathManager

use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.

the class TestAbstractRestInvocation method findRestOperationNormal.

@Test
public void findRestOperationNormal(@Mocked MicroserviceMeta microserviceMeta, @Mocked ServicePathManager servicePathManager, @Mocked OperationLocator locator) {
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected OperationLocator locateOperation(ServicePathManager servicePathManager) {
            return locator;
        }
    };
    requestEx = new AbstractHttpServletRequest() {
    };
    restInvocation.requestEx = requestEx;
    Map<String, String> pathVars = new HashMap<>();
    new Expectations(ServicePathManager.class) {

        {
            ServicePathManager.getServicePathManager(microserviceMeta);
            result = servicePathManager;
            locator.getPathVarMap();
            result = pathVars;
            locator.getOperation();
            result = restOperation;
        }
    };
    restInvocation.findRestOperation(microserviceMeta);
    Assert.assertSame(restOperation, restInvocation.restOperationMeta);
    Assert.assertSame(pathVars, requestEx.getAttribute(RestConst.PATH_PARAMETERS));
}
Also used : Expectations(mockit.Expectations) OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) AbstractHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest) HashMap(java.util.HashMap) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager) Test(org.junit.Test)

Example 8 with ServicePathManager

use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.

the class AbstractRestInvocation method findRestOperation.

protected void findRestOperation(MicroserviceMeta microserviceMeta) {
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager == null) {
        LOGGER.error("No schema defined for {}:{}.", microserviceMeta.getAppId(), microserviceMeta.getName());
        throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
    }
    OperationLocator locator = locateOperation(servicePathManager);
    requestEx.setAttribute(RestConst.PATH_PARAMETERS, locator.getPathVarMap());
    this.restOperationMeta = locator.getOperation();
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 9 with ServicePathManager

use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.

the class RestEngineSchemaListener method onBootEvent.

@Override
public void onBootEvent(BootEvent event) {
    if (!event.getEventType().equals(EventType.BEFORE_REGISTRY)) {
        return;
    }
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(RegistryUtils.getMicroservice());
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager != null) {
        servicePathManager.buildProducerPaths();
    }
}
Also used : MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 10 with ServicePathManager

use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project java-chassis by ServiceComb.

the class TestAbstractRestInvocation method findRestOperationNormal.

@Test
public void findRestOperationNormal(@Mocked MicroserviceMeta microserviceMeta, @Mocked ServicePathManager servicePathManager, @Mocked OperationLocator locator) {
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected OperationLocator locateOperation(ServicePathManager servicePathManager) {
            return locator;
        }
    };
    requestEx = new AbstractHttpServletRequest() {
    };
    restInvocation.requestEx = requestEx;
    Map<String, String> pathVars = new HashMap<>();
    new Expectations(ServicePathManager.class) {

        {
            ServicePathManager.getServicePathManager(microserviceMeta);
            result = servicePathManager;
            locator.getPathVarMap();
            result = pathVars;
            locator.getOperation();
            result = restOperation;
        }
    };
    restInvocation.findRestOperation(microserviceMeta);
    Assert.assertSame(restOperation, restInvocation.restOperationMeta);
    Assert.assertSame(pathVars, requestEx.getAttribute(RestConst.PATH_PARAMETERS));
}
Also used : Expectations(mockit.Expectations) OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) AbstractHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest) HashMap(java.util.HashMap) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Aggregations

ServicePathManager (org.apache.servicecomb.common.rest.locator.ServicePathManager)11 OperationLocator (org.apache.servicecomb.common.rest.locator.OperationLocator)6 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)6 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Expectations (mockit.Expectations)2 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)2 AbstractHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest)2 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)2 Swagger (io.swagger.models.Swagger)1 ArrayList (java.util.ArrayList)1 Mock (mockit.Mock)1 HttpServerFilterBaseForTest (org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 ConsumerSchemaFactory (org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory)1 MicroserviceReferenceConfig (org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig)1 SwaggerGenerator (org.apache.servicecomb.swagger.generator.core.SwaggerGenerator)1 ApplicationContext (org.springframework.context.ApplicationContext)1