Search in sources :

Example 1 with OperationLocator

use of io.servicecomb.common.rest.locator.OperationLocator in project java-chassis by ServiceComb.

the class AbstractRestServer method findRestOperation.

protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
    String selfName = RegistryUtils.getMicroservice().getServiceName();
    MicroserviceMeta selfMicroserviceMeta = CseContext.getInstance().getMicroserviceMetaManager().ensureFindValue(selfName);
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(selfMicroserviceMeta);
    if (servicePathManager == null) {
        LOGGER.error("No schema in microservice");
        throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
    }
    OperationLocator locator = servicePathManager.locateOperation(restRequest.getPath(), restRequest.getMethod());
    restRequest.setPathParamMap(locator.getPathVarMap());
    return locator.getOperation();
}
Also used : OperationLocator(io.servicecomb.common.rest.locator.OperationLocator) InvocationException(io.servicecomb.core.exception.InvocationException) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Example 2 with OperationLocator

use of io.servicecomb.common.rest.locator.OperationLocator in project java-chassis by ServiceComb.

the class CseClientHttpRequest method createRequestMeta.

private RequestMeta createRequestMeta(String httpMetod, URI uri) {
    String microserviceName = uri.getAuthority();
    ReferenceConfig referenceConfig = CseContext.getInstance().getConsumerProviderManager().getReferenceConfig(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.locateOperation(uri.getPath(), httpMetod);
    RestOperationMeta swaggerRestOperation = locator.getOperation();
    Map<String, String> pathParams = locator.getPathVarMap();
    return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
Also used : OperationLocator(io.servicecomb.common.rest.locator.OperationLocator) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(io.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Aggregations

OperationLocator (io.servicecomb.common.rest.locator.OperationLocator)2 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)2 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)2 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 ReferenceConfig (io.servicecomb.core.provider.consumer.ReferenceConfig)1