Search in sources :

Example 6 with MetaRequest

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

the class LogEnabledLifeCycle method onMethodInitialized.

@Override
public void onMethodInitialized(ForestMethod method, LogEnabled annotation) {
    MetaRequest metaRequest = method.getMetaRequest();
    if (metaRequest == null) {
        return;
    }
    ForestConfiguration configuration = method.getConfiguration();
    LogConfiguration logConfiguration = metaRequest.getLogConfiguration();
    if (logConfiguration == null) {
        logConfiguration = new LogConfiguration();
        metaRequest.setLogConfiguration(logConfiguration);
    }
    boolean logEnabled = annotation.value();
    boolean logRequest = annotation.logRequest();
    boolean logResponseStatus = annotation.logResponseStatus();
    boolean logResponseContent = annotation.logResponseContent();
    logConfiguration.setLogEnabled(logEnabled);
    logConfiguration.setLogRequest(logRequest);
    logConfiguration.setLogResponseStatus(logResponseStatus);
    logConfiguration.setLogResponseContent(logResponseContent);
    metaRequest.setLogConfiguration(logConfiguration);
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) MetaRequest(com.dtflys.forest.reflection.MetaRequest) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 7 with MetaRequest

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

the class BodyTypeLifeCycle method onMethodInitialized.

@Override
public void onMethodInitialized(ForestMethod method, BodyType annotation) {
    Map<String, Object> attrs = ReflectUtils.getAttributesFromAnnotation(annotation);
    String type = (String) attrs.get("type");
    Object encodeClass = attrs.get("encoder");
    MetaRequest metaRequest = method.getMetaRequest();
    if (metaRequest == null) {
        return;
    }
    metaRequest.setBodyType(type);
    if (encodeClass != null && encodeClass instanceof Class && !((Class<?>) encodeClass).isInterface() && ForestEncoder.class.isAssignableFrom((Class<?>) encodeClass)) {
        metaRequest.setEncoder((Class<? extends ForestEncoder>) encodeClass);
    }
}
Also used : ForestEncoder(com.dtflys.forest.converter.ForestEncoder) MetaRequest(com.dtflys.forest.reflection.MetaRequest)

Example 8 with MetaRequest

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

the class DeleteRequestLifeCycle method onMethodInitialized.

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

Example 9 with MetaRequest

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

the class GetRequestLifeCycle method onMethodInitialized.

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

Example 10 with MetaRequest

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

the class HeadersLifeCycle method onMethodInitialized.

@Override
public void onMethodInitialized(ForestMethod method, Headers annotation) {
    MetaRequest metaRequest = method.getMetaRequest();
    String[] headers = annotation.value();
    String[] oldHeaders = metaRequest.getHeaders();
    int len = headers.length + oldHeaders.length;
    String[] newHeaders = new String[headers.length + oldHeaders.length];
    for (int i = 0; i < oldHeaders.length; i++) {
        newHeaders[i] = oldHeaders[i];
    }
    for (int i = 0; i < headers.length; i++) {
        newHeaders[oldHeaders.length + i] = headers[i];
    }
    // String[] newHeaders = ArrayUtils.addAll(oldHeaders, headers);
    metaRequest.setHeaders(newHeaders);
}
Also used : MetaRequest(com.dtflys.forest.reflection.MetaRequest)

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