com.didiglobal.logi.log.common.web.spring.TunnelRequestBodyAdvice Maven / Gradle / Ivy
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 extends HttpMessageConverter>> converterType) {
return true;
}
@Override
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class extends HttpMessageConverter>> converterType) {
return body;
}
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class extends HttpMessageConverter>> converterType) throws IOException {
return inputMessage;
}
@Override
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class extends HttpMessageConverter>> converterType) {
RequestBodyCache.setRequestBody(TunnelJsonUtil.toJSONString(body));
return body;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy