Search in sources :

Example 21 with MetaRequest

use of com.dtflys.forest.reflection.MetaRequest in project forest by dromara.

the class PostRequestLifeCycle method onMethodInitialized.

@Override
public void onMethodInitialized(ForestMethod method, Annotation annotation) {
    MetaRequest metaRequest = createMetaRequest(annotation);
    metaRequest.setType(ForestRequestType.POST.getName());
    method.setMetaRequest(metaRequest);
}
Also used : MetaRequest(com.dtflys.forest.reflection.MetaRequest)

Example 22 with MetaRequest

use of com.dtflys.forest.reflection.MetaRequest in project forest by dromara.

the class PutRequestLifeCycle method onMethodInitialized.

@Override
public void onMethodInitialized(ForestMethod method, Annotation annotation) {
    MetaRequest metaRequest = createMetaRequest(annotation);
    metaRequest.setType(ForestRequestType.PUT.getName());
    method.setMetaRequest(metaRequest);
}
Also used : MetaRequest(com.dtflys.forest.reflection.MetaRequest)

Example 23 with MetaRequest

use of com.dtflys.forest.reflection.MetaRequest in project forest by dromara.

the class ProtobufBodyLifeCycle method onParameterInitialized.

@Override
public void onParameterInitialized(ForestMethod method, MappingParameter parameter, ProtobufBody annotation) {
    super.onParameterInitialized(method, parameter, annotation);
    MetaRequest metaRequest = method.getMetaRequest();
    String methodName = methodName(method);
    if (metaRequest == null) {
        throw new ForestRuntimeException("[Forest] method '" + methodName + "' has not bind a Forest request annotation. Hence the annotation @BinaryBody cannot be bind on a parameter in this method.");
    }
    boolean hasDataFileAnn = false;
    for (Parameter param : method.getMethod().getParameters()) {
        Annotation dataFileAnn = param.getAnnotation(DataFile.class);
        if (dataFileAnn != null) {
            hasDataFileAnn = true;
            break;
        }
    }
    String contentTypeStr = metaRequest.getContentType();
    if (StringUtils.isBlank(contentTypeStr) && !hasDataFileAnn) {
        metaRequest.setContentType(ContentType.APPLICATION_X_PROTOBUF);
    }
    if (metaRequest.getBodyType() == null) {
        metaRequest.setBodyType(ForestDataType.PROTOBUF);
    }
    parameter.setTarget(MappingParameter.TARGET_BODY);
}
Also used : MetaRequest(com.dtflys.forest.reflection.MetaRequest) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) Parameter(java.lang.reflect.Parameter) MappingParameter(com.dtflys.forest.mapping.MappingParameter) Annotation(java.lang.annotation.Annotation)

Example 24 with MetaRequest

use of com.dtflys.forest.reflection.MetaRequest in project forest by dromara.

the class TestInterfaceProxyHandler method testEmptyBaseURL.

@Test
public void testEmptyBaseURL() {
    ProxyFactory<EmptyBaseURLClient> getClientProxyFactory = new ProxyFactory<>(configuration, EmptyBaseURLClient.class);
    InterfaceProxyHandler<EmptyBaseURLClient> interfaceProxyHandler = new InterfaceProxyHandler(configuration, getClientProxyFactory, EmptyBaseURLClient.class);
    MetaRequest metaRequest = interfaceProxyHandler.getBaseMetaRequest();
    assertNull(metaRequest.getUrl());
}
Also used : InterfaceProxyHandler(com.dtflys.forest.proxy.InterfaceProxyHandler) ProxyFactory(com.dtflys.forest.proxy.ProxyFactory) MetaRequest(com.dtflys.forest.reflection.MetaRequest) Test(org.junit.Test)

Aggregations

MetaRequest (com.dtflys.forest.reflection.MetaRequest)24 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)6 MappingParameter (com.dtflys.forest.mapping.MappingParameter)4 Annotation (java.lang.annotation.Annotation)4 Parameter (java.lang.reflect.Parameter)4 InterfaceProxyHandler (com.dtflys.forest.proxy.InterfaceProxyHandler)3 ProxyFactory (com.dtflys.forest.proxy.ProxyFactory)3 Test (org.junit.Test)3 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)2 LogConfiguration (com.dtflys.forest.logging.LogConfiguration)2 ForestEncoder (com.dtflys.forest.converter.ForestEncoder)1 Filter (com.dtflys.forest.filter.Filter)1 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)1 MappingTemplate (com.dtflys.forest.mapping.MappingTemplate)1 ForestMultipartFactory (com.dtflys.forest.multipart.ForestMultipartFactory)1