All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.didiglobal.logi.log.common.web.spring.TunnelRequestBodyAdvice Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.didiglobal.logi.log.common.web.spring;

import com.didiglobal.logi.log.common.json.TunnelJsonUtil;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @author jinbinbin
 * @version $Id: TunnelRequestBodyAdvice.java, v 0.1 2017年07月25日 12:17 jinbinbin Exp $
 */
@RestControllerAdvice
public class TunnelRequestBodyAdvice implements RequestBodyAdvice {

    @Override
    public boolean supports(MethodParameter methodParameter, Type targetType,
                            Class> converterType) {
        return true;
    }

    @Override
    public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
                                  Type targetType, Class> converterType) {
        return body;
    }

    @Override
    public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
                                           Class> converterType) throws IOException {
        return inputMessage;
    }

    @Override
    public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
                                Class> converterType) {
        RequestBodyCache.setRequestBody(TunnelJsonUtil.toJSONString(body));
        return body;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy