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);
}
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));
}
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();
}
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();
}
}
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));
}
Aggregations