use of org.apache.dubbo.metadata.rest.RestMethodMetadata in project dubbo by alibaba.
the class AbstractServiceRestMetadataResolver method resolveRestMethodMetadata.
protected Optional<RestMethodMetadata> resolveRestMethodMetadata(ProcessingEnvironment processingEnv, TypeElement serviceType, TypeElement serviceInterfaceType, ExecutableElement serviceMethod) {
ExecutableElement restCapableMethod = findRestCapableMethod(processingEnv, serviceType, serviceInterfaceType, serviceMethod);
if (restCapableMethod == null) {
// if can't be found
return empty();
}
// requestPath is required
String requestPath = resolveRequestPath(processingEnv, serviceType, restCapableMethod);
if (requestPath == null) {
return empty();
}
// requestMethod is required
String requestMethod = resolveRequestMethod(processingEnv, serviceType, restCapableMethod);
if (requestMethod == null) {
return empty();
}
RestMethodMetadata metadata = new RestMethodMetadata();
MethodDefinition methodDefinition = resolveMethodDefinition(processingEnv, serviceType, restCapableMethod);
// Set MethodDefinition
metadata.setMethod(methodDefinition);
// process the annotated method parameters
processAnnotatedMethodParameters(restCapableMethod, serviceType, metadata);
// process produces
Set<String> produces = new LinkedHashSet<>();
processProduces(processingEnv, serviceType, restCapableMethod, produces);
// process consumes
Set<String> consumes = new LinkedHashSet<>();
processConsumes(processingEnv, serviceType, restCapableMethod, consumes);
// Initialize RequestMetadata
RequestMetadata request = metadata.getRequest();
request.setPath(requestPath);
request.setMethod(requestMethod);
request.setProduces(produces);
request.setConsumes(consumes);
// Post-Process
postProcessRestMethodMetadata(processingEnv, serviceType, serviceMethod, metadata);
return of(metadata);
}
use of org.apache.dubbo.metadata.rest.RestMethodMetadata 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);
}
use of org.apache.dubbo.metadata.rest.RestMethodMetadata 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);
}
Aggregations