Search in sources :

Example 1 with OperationLocator

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

the class CseClientHttpRequest method createRequestMeta.

private RequestMeta createRequestMeta(String httpMetod, URI uri) {
    String microserviceName = uri.getAuthority();
    ReferenceConfig referenceConfig = ReferenceConfigUtils.getForInvoke(microserviceName);
    MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager == null) {
        throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getName()));
    }
    OperationLocator locator = servicePathManager.consumerLocateOperation(path, httpMetod);
    RestOperationMeta swaggerRestOperation = locator.getOperation();
    Map<String, String> pathParams = locator.getPathVarMap();
    return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(org.apache.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 2 with OperationLocator

use of org.apache.servicecomb.common.rest.locator.OperationLocator 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 3 with OperationLocator

use of org.apache.servicecomb.common.rest.locator.OperationLocator 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)

Aggregations

OperationLocator (org.apache.servicecomb.common.rest.locator.OperationLocator)3 ServicePathManager (org.apache.servicecomb.common.rest.locator.ServicePathManager)3 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)1 AbstractHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest)1 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)1 Test (org.junit.Test)1