Search in sources :

Example 1 with RequestMetadata

use of org.apache.dubbo.metadata.rest.RequestMetadata 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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) ExecutableElement(javax.lang.model.element.ExecutableElement) RestMethodMetadata(org.apache.dubbo.metadata.rest.RestMethodMetadata) RequestMetadata(org.apache.dubbo.metadata.rest.RequestMetadata)

Example 2 with RequestMetadata

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

the class ParamAnnotationParameterProcessor method process.

protected void process(String name, String defaultValue, AnnotationMirror annotation, VariableElement parameter, int parameterIndex, ExecutableElement method, RestMethodMetadata restMethodMetadata) {
    RequestMetadata requestMetadata = restMethodMetadata.getRequest();
    requestMetadata.addParam(name, defaultValue);
}
Also used : RequestMetadata(org.apache.dubbo.metadata.rest.RequestMetadata)

Example 3 with RequestMetadata

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

the class DefaultValueParameterProcessor method process.

@Override
protected void process(String annotationValue, String defaultValue, AnnotationMirror annotation, VariableElement parameter, int parameterIndex, ExecutableElement method, RestMethodMetadata restMethodMetadata) {
    RequestMetadata requestMetadata = restMethodMetadata.getRequest();
    // process the request parameters
    setDefaultValue(requestMetadata.getParams(), defaultValue, annotationValue);
    // process the request headers
    setDefaultValue(requestMetadata.getHeaders(), defaultValue, annotationValue);
}
Also used : RequestMetadata(org.apache.dubbo.metadata.rest.RequestMetadata)

Example 4 with RequestMetadata

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

the class DefaultValueParameterProcessor method process.

@Override
protected void process(String annotationValue, String defaultValue, Annotation annotation, Object parameter, int parameterIndex, Method method, RestMethodMetadata restMethodMetadata) {
    RequestMetadata requestMetadata = restMethodMetadata.getRequest();
    // process the request parameters
    setDefaultValue(requestMetadata.getParams(), defaultValue, annotationValue);
    // process the request headers
    setDefaultValue(requestMetadata.getHeaders(), defaultValue, annotationValue);
}
Also used : RequestMetadata(org.apache.dubbo.metadata.rest.RequestMetadata)

Example 5 with RequestMetadata

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

the class ParamAnnotationParameterProcessor method process.

@Override
protected void process(String name, String defaultValue, Annotation annotation, Object parameter, int parameterIndex, Method method, RestMethodMetadata restMethodMetadata) {
    RequestMetadata requestMetadata = restMethodMetadata.getRequest();
    requestMetadata.addParam(name, defaultValue);
}
Also used : RequestMetadata(org.apache.dubbo.metadata.rest.RequestMetadata)

Aggregations

RequestMetadata (org.apache.dubbo.metadata.rest.RequestMetadata)7 LinkedHashSet (java.util.LinkedHashSet)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)1 RestMethodMetadata (org.apache.dubbo.metadata.rest.RestMethodMetadata)1