The original problem is when I sent a http request with method 'DELETE', the body part couldn't be sent to the server.
After googling, I found this article that suggests modifying the server.xml file and adding 'parseBodyMethods' to the Connector part can solve the problem:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
parseBodyMethods="POST,PUT,DELETE"
redirectPort="8443" />
However, because I'm using spring's embedded tomcat, I have to find a way to do the same in spring's way. So, I found this article that seems to allow me to add ConnectorCustomizer and add additional attribute to the Connector. The following is my code:
public class MyTomcatConnectorCustomizer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer factory) {
if(factory instanceof TomcatEmbeddedServletContainerFactory) {
customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
}
}
public void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) factory;
tomcat.addConnectorCustomizers(connector -> {
connector.setAttribute("parseBodyMethods", "POST,PUT,DELETE");
});
}
}
@Bean
MyTomcatConnectorCustomizer myTomcatConnectorCustomizer() {
MyTomcatConnectorCustomizer myTomcatConnectorCustomizer = new MyTomcatConnectorCustomizer();
return myTomcatConnectorCustomizer;
}
But still, the same issue exists. the body is still empty when I send a 'DELETE' request to the server. Does anyone have encountered the same issue before? Help appreciated!