Search in sources :

Example 1 with ServiceRestMetadata

use of org.apache.dubbo.metadata.rest.ServiceRestMetadata in project dubbo by alibaba.

the class AbstractServiceRestMetadataResolver method resolve.

@Override
public final ServiceRestMetadata resolve(ProcessingEnvironment processingEnv, TypeElement serviceType, Set<? extends TypeElement> annotations) {
    info("%s is processing the service type[%s] with annotations[%s]", processorName, serviceType, annotations.stream().map(t -> "@" + t.toString()).collect(Collectors.joining(",")));
    ServiceRestMetadata serviceRestMetadata = new ServiceRestMetadata();
    Elements elements = processingEnv.getElementUtils();
    try {
        AnnotationMirror serviceAnnotation = getAnnotation(serviceType);
        String serviceInterfaceName = resolveServiceInterfaceName(serviceType, serviceAnnotation);
        serviceRestMetadata.setServiceInterface(serviceInterfaceName);
        serviceRestMetadata.setGroup(getGroup(serviceAnnotation));
        serviceRestMetadata.setVersion(getVersion(serviceAnnotation));
        TypeElement serviceInterfaceType = elements.getTypeElement(serviceInterfaceName);
        List<? extends ExecutableElement> serviceMethods = new LinkedList<>(getPublicNonStaticMethods(serviceInterfaceType, Object.class));
        // Sorts
        sort(serviceMethods, ExecutableElementComparator.INSTANCE);
        serviceMethods.forEach(serviceMethod -> {
            resolveRestMethodMetadata(processingEnv, serviceType, serviceInterfaceType, serviceMethod).ifPresent(serviceRestMetadata.getMeta()::add);
        });
    } finally {
        clearCache();
    }
    info("The %s's process result : %s", processorName, serviceRestMetadata);
    return serviceRestMetadata;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ServiceRestMetadata(org.apache.dubbo.metadata.rest.ServiceRestMetadata) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements) LinkedList(java.util.LinkedList)

Example 2 with ServiceRestMetadata

use of org.apache.dubbo.metadata.rest.ServiceRestMetadata in project dubbo by alibaba.

the class SpringMvcServiceRestMetadataResolverTest method testResolve.

@Test
public void testResolve() {
    // Generated by "dubbo-metadata-processor"
    ClassPathServiceRestMetadataReader reader = new ClassPathServiceRestMetadataReader("META-INF/dubbo/spring-mvc-servoce-rest-metadata.json");
    List<ServiceRestMetadata> serviceRestMetadataList = reader.read();
    ServiceRestMetadata expectedServiceRestMetadata = serviceRestMetadataList.get(0);
    ServiceRestMetadata serviceRestMetadata = instance.resolve(SpringRestService.class);
    List<RestMethodMetadata> meta1 = new LinkedList<>(expectedServiceRestMetadata.getMeta());
    List<RestMethodMetadata> meta2 = new LinkedList<>(serviceRestMetadata.getMeta());
    for (int i = 0; i < meta1.size(); i++) {
        RestMethodMetadata restMethodMetadata = meta1.get(i);
        RestMethodMetadata restMethodMetadata2 = meta2.get(i);
        assertEquals(restMethodMetadata, restMethodMetadata2);
    }
    assertEquals(expectedServiceRestMetadata, serviceRestMetadata);
}
Also used : ServiceRestMetadata(org.apache.dubbo.metadata.rest.ServiceRestMetadata) ClassPathServiceRestMetadataReader(org.apache.dubbo.metadata.rest.ClassPathServiceRestMetadataReader) LinkedList(java.util.LinkedList) RestMethodMetadata(org.apache.dubbo.metadata.rest.RestMethodMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceRestMetadata

use of org.apache.dubbo.metadata.rest.ServiceRestMetadata in project dubbo by alibaba.

the class JAXRSServiceRestMetadataResolverTest method testResolve.

@Test
public void testResolve() {
    // Generated by "dubbo-metadata-processor"
    ClassPathServiceRestMetadataReader reader = new ClassPathServiceRestMetadataReader("META-INF/dubbo/jax-rs-service-rest-metadata.json");
    List<ServiceRestMetadata> serviceRestMetadataList = reader.read();
    ServiceRestMetadata expectedServiceRestMetadata = serviceRestMetadataList.get(0);
    ServiceRestMetadata serviceRestMetadata = instance.resolve(StandardRestService.class);
    List<RestMethodMetadata> meta1 = new LinkedList<>(expectedServiceRestMetadata.getMeta());
    List<RestMethodMetadata> meta2 = new LinkedList<>(serviceRestMetadata.getMeta());
    for (int i = 0; i < meta1.size(); i++) {
        RestMethodMetadata restMethodMetadata = meta1.get(i);
        RestMethodMetadata restMethodMetadata2 = meta2.get(i);
        assertEquals(restMethodMetadata, restMethodMetadata2);
    }
    assertEquals(expectedServiceRestMetadata, serviceRestMetadata);
}
Also used : ServiceRestMetadata(org.apache.dubbo.metadata.rest.ServiceRestMetadata) ClassPathServiceRestMetadataReader(org.apache.dubbo.metadata.rest.ClassPathServiceRestMetadataReader) LinkedList(java.util.LinkedList) RestMethodMetadata(org.apache.dubbo.metadata.rest.RestMethodMetadata) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceRestMetadata

use of org.apache.dubbo.metadata.rest.ServiceRestMetadata in project dubbo by alibaba.

the class ServiceRestMetadataStorage method append.

public void append(Set<ServiceRestMetadata> serviceRestMetadata) throws IOException {
    storage.read(SERVICE_REST_METADATA_RESOURCE_PATH, reader -> {
        Gson gson = new Gson();
        return (List) gson.fromJson(reader, getParameterized(List.class, ServiceRestMetadata.class).getType());
    }).ifPresent(existedMetadata -> {
        // Add all existed ServiceRestMetadata
        serviceRestMetadata.addAll(existedMetadata);
    });
    write(serviceRestMetadata);
}
Also used : List(java.util.List) ServiceRestMetadata(org.apache.dubbo.metadata.rest.ServiceRestMetadata) ClassPathMetadataStorage(org.apache.dubbo.metadata.annotation.processing.ClassPathMetadataStorage) TypeToken.getParameterized(com.google.gson.reflect.TypeToken.getParameterized) Gson(com.google.gson.Gson) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Set(java.util.Set) IOException(java.io.IOException) SERVICE_REST_METADATA_RESOURCE_PATH(org.apache.dubbo.metadata.rest.RestMetadataConstants.SERVICE_REST_METADATA_RESOURCE_PATH) Gson(com.google.gson.Gson)

Aggregations

ServiceRestMetadata (org.apache.dubbo.metadata.rest.ServiceRestMetadata)4 LinkedList (java.util.LinkedList)3 ClassPathServiceRestMetadataReader (org.apache.dubbo.metadata.rest.ClassPathServiceRestMetadataReader)2 RestMethodMetadata (org.apache.dubbo.metadata.rest.RestMethodMetadata)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 TypeToken.getParameterized (com.google.gson.reflect.TypeToken.getParameterized)1 IOException (java.io.IOException)1 List (java.util.List)1 Set (java.util.Set)1 ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 TypeElement (javax.lang.model.element.TypeElement)1 Elements (javax.lang.model.util.Elements)1 ClassPathMetadataStorage (org.apache.dubbo.metadata.annotation.processing.ClassPathMetadataStorage)1 SERVICE_REST_METADATA_RESOURCE_PATH (org.apache.dubbo.metadata.rest.RestMetadataConstants.SERVICE_REST_METADATA_RESOURCE_PATH)1