
artoria.context.spring.ContextSupportRequestBodyAdvice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artoria-extend Show documentation
Show all versions of artoria-extend Show documentation
Artoria is a java technology framework based on the facade pattern.
The newest version!
package artoria.context.spring;
import artoria.bean.BeanHolder;
import artoria.context.support.ServletContext;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter;
import java.lang.reflect.Type;
import java.util.Map;
/**
* The request body advice for the servlet context.
* @author Kahle
* @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice
*/
@ControllerAdvice
public class ContextSupportRequestBodyAdvice extends RequestBodyAdviceAdapter {
@Override
public boolean supports(@NonNull MethodParameter methodParameter,
@NonNull Type targetType,
@NonNull Class extends HttpMessageConverter>> converterType) {
return true;
}
@NonNull
@Override
public Object afterBodyRead(@NonNull Object body,
@NonNull HttpInputMessage inputMessage,
@NonNull MethodParameter parameter,
@NonNull Type targetType,
@NonNull Class extends HttpMessageConverter>> converterType) {
Map beans = BeanHolder.getBeans(ServletContext.class);
if (beans == null || beans.isEmpty()) { return body; }
for (Map.Entry entry : beans.entrySet()) {
ServletContext context = entry.getValue();
context.setRequestBody(body);
}
return body;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy