use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.
the class TestIgnoreStaticMethod method ignoreStaticMethod_Jaxrs.
@Test
public void ignoreStaticMethod_Jaxrs() {
SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta("ignoreStaticMethodJaxrsSchema");
OperationMeta add = schemaMeta.findOperation("add");
Assert.assertNotNull(add);
OperationMeta sub = schemaMeta.findOperation("staticSub");
Assert.assertNull(sub);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.
the class TestSchemaMetaCodec method mockSchemaMeta.
private void mockSchemaMeta(String schemaId, AbstractSwaggerGenerator swaggerGenerator, Object producerInstance) throws Exception {
new Expectations() {
{
providerMicroserviceMeta.getMicroserviceName();
result = "test";
providerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
result = null;
consumerMicroserviceMeta.getMicroserviceName();
result = "test";
consumerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
result = null;
}
};
Swagger swagger = swaggerGenerator.generate();
SwaggerEnvironment swaggerEnvironment = new SwaggerEnvironment();
providerSchemaMeta = new SchemaMeta(providerMicroserviceMeta, schemaId, swagger);
SwaggerProducer swaggerProducer = swaggerEnvironment.createProducer(producerInstance, swagger);
for (SwaggerProducerOperation producerOperation : swaggerProducer.getAllOperations()) {
OperationMeta operationMeta = providerSchemaMeta.ensureFindOperation(producerOperation.getOperationId());
operationMeta.setSwaggerProducerOperation(producerOperation);
}
consumerSchemaMeta = new SchemaMeta(consumerMicroserviceMeta, schemaId, swagger);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.
the class ProducerBootListener method saveBasePaths.
// just compatible to old 3rd components, servicecomb not use it......
private void saveBasePaths(MicroserviceMeta microserviceMeta) {
if (!DynamicPropertyFactory.getInstance().getBooleanProperty(DefinitionConst.REGISTER_SERVICE_PATH, false).get()) {
return;
}
String urlPrefix = ClassLoaderScopeContext.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX);
Map<String, BasePath> basePaths = new LinkedHashMap<>();
for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
Swagger swagger = schemaMeta.getSwagger();
String basePath = swagger.getBasePath();
if (StringUtils.isNotEmpty(urlPrefix) && !basePath.startsWith(urlPrefix)) {
basePath = urlPrefix + basePath;
}
if (StringUtils.isNotEmpty(basePath)) {
BasePath basePathObj = new BasePath();
basePathObj.setPath(basePath);
basePaths.put(basePath, basePathObj);
}
}
RegistrationManager.INSTANCE.addBasePath(basePaths.values());
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.
the class ProducerBootListener method onAfterTransport.
@Override
public void onAfterTransport(BootEvent event) {
// register schema to microservice;
Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
String swaggerSchema = "http";
for (String endpoint : microservice.getInstance().getEndpoints()) {
if (endpoint.startsWith("rest://") && endpoint.indexOf("sslEnabled=true") > 0) {
swaggerSchema = "https";
}
}
MicroserviceMeta microserviceMeta = event.getScbEngine().getProducerMicroserviceMeta();
for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
Swagger swagger = schemaMeta.getSwagger();
swagger.addScheme(Scheme.forValue(swaggerSchema));
String content = SwaggerUtils.swaggerToString(swagger);
LOGGER.info("generate swagger for {}/{}/{}, swagger: {}", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName(), schemaMeta.getSchemaId(), content);
RegistrationManager.INSTANCE.addSchema(schemaMeta.getSchemaId(), content);
}
saveBasePaths(microserviceMeta);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.
the class ProducerProviderManager method registerSchema.
public SchemaMeta registerSchema(String schemaId, Class<?> schemaInterface, Object instance) {
MicroserviceMeta producerMicroserviceMeta = scbEngine.getProducerMicroserviceMeta();
Swagger swagger = scbEngine.getSwaggerLoader().loadLocalSwagger(producerMicroserviceMeta.getAppId(), producerMicroserviceMeta.getShortName(), schemaId);
SwaggerProducer swaggerProducer = scbEngine.getSwaggerEnvironment().createProducer(instance, schemaInterface, swagger);
swagger = swaggerProducer.getSwagger();
registerUrlPrefixToSwagger(swagger);
SchemaMeta schemaMeta = producerMicroserviceMeta.registerSchemaMeta(schemaId, swagger);
schemaMeta.putExtData(CoreMetaUtils.SWAGGER_PRODUCER, swaggerProducer);
Executor reactiveExecutor = scbEngine.getExecutorManager().findExecutorById(ExecutorManager.EXECUTOR_REACTIVE);
for (SwaggerProducerOperation producerOperation : swaggerProducer.getAllOperations()) {
OperationMeta operationMeta = schemaMeta.ensureFindOperation(producerOperation.getOperationId());
operationMeta.setSwaggerProducerOperation(producerOperation);
if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
operationMeta.setExecutor(scbEngine.getExecutorManager().findExecutor(operationMeta, reactiveExecutor));
}
}
return schemaMeta;
}
Aggregations