use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class TestLocator method testLocateStatic.
@Test
public void testLocateStatic() {
MicroserviceMeta msm = new MicroserviceMeta("app:ms");
ServicePathManager spm = new ServicePathManager(msm);
RestOperationMeta rom = createRestOperatonMeta("GET", "abc/");
spm.addResource(rom);
rom = createRestOperatonMeta("POST", "abc/");
spm.addResource(rom);
try {
spm.addResource(rom);
} catch (Throwable e) {
Assert.assertEquals("operation with url abc/, method POST is duplicated", e.getMessage());
}
Assert.assertEquals(1, spm.getStaticPathOperationMap().size());
Assert.assertEquals(2, spm.getStaticPathOperationMap().get("abc/").values().size());
try {
spm.locateOperation("abcd", "GET");
} catch (InvocationException e) {
Assert.assertEquals("Not Found", ((CommonExceptionData) e.getErrorData()).getMessage());
}
try {
spm.locateOperation("abc/", "PUT");
} catch (InvocationException e) {
Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
}
OperationLocator locator = spm.locateOperation("abc/", "GET");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
locator.locate(spm, "abc/", "POST");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class SchemaListenerManager method notifySchemaListener.
public void notifySchemaListener(MicroserviceMeta... microserviceMetas) {
List<SchemaMeta> schemaMetaList = new ArrayList<>();
for (MicroserviceMeta microserviceMeta : microserviceMetas) {
schemaMetaList.addAll(microserviceMeta.getSchemaMetas());
}
notifySchemaListener(schemaMetaList.toArray(new SchemaMeta[schemaMetaList.size()]));
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class ProducerSchemaFactory method getOrCreateProducerSchema.
// 只会在启动流程中调用
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) {
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName);
ProducerSchemaContext context = new ProducerSchemaContext();
context.setMicroserviceMeta(microserviceMeta);
context.setSchemaId(schemaId);
context.setProviderClass(producerClass);
context.setProducerInstance(producerInstance);
return getOrCreateSchema(context);
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class AbstractSchemaFactory method getOrCreateSchema.
// 因为aop的存在,schemaInstance的class不一定等于schemaClass
protected SchemaMeta getOrCreateSchema(CONTEXT context) {
MicroserviceMeta microserviceMeta = context.getMicroserviceMeta();
SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(context.getSchemaId());
if (schemaMeta == null) {
schemaMeta = createSchema(context);
}
context.setSchemaMeta(schemaMeta);
connectToProvider(context);
return schemaMeta;
}
use of io.servicecomb.core.definition.MicroserviceMeta 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();
}
Aggregations