Score:0

Apache Tomcat reject post request for more than 19KB and return 400 BAD REQUEST

il flag

Spring boot application deployed on apache tomcat 9 reject post request larger than 19kb.

the bookController:

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1/book")
@AllArgsConstructor
public class BookController {
    private final static Logger logger = LoggerFactory.getLogger(BookController.class);
    
    private final BookServices bookServices;
    private final BookRepository bookRepository;
    
    @PostMapping("/add")  @ResponseStatus(code = HttpStatus.CREATED)
    public void addBook(@Valid @RequestBody BookModel bookModel) throws SanprException {
        try {
            logger.info("success...");
            bookServices.addBook(bookModel);
        } catch (Exception e) {
            StringBuilder message = new StringBuilder("Failed...");
            throw new SanprException(message.toString(), e, Boolean.FALSE, Boolean.TRUE);
        }
    }
}  

the bookModel class :

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BookModel {    
        @Id
        private long id;
        private String title;
        private boolean isPublish;
        private boolean isDuplicated;
        private MediaModel background;
        private String pdfFile;
        private String description;
        private List<TableContentsModel> tableContents;
        private GlobalReferentialModel level;
        private GlobalReferentialModel type;

}

here my server.xml configuration for apache tomcat,

 <Connector port="8010" 
            protocol="HTTP/1.1" 
            compression="on" 
            compressionMinSize="2048"
            maxPostSize="26214400" maxHttpHeaderSize="26214400"
            maxSavePostSize="-1"    
            URIEncoding="UTF-8"
            address="*.*.*.*"
            redirectPort="8443"
            useIPVHosts="true" />
<Connector SSLEnabled="true" 
           acceptCount="100" clientAuth="false"
           disableUploadTimeout="true" enableLookups="false" 
           maxThreads="25"  port="8443" 
           connectionTimeout="20000" maxSwallowSize = "-1" 
           maxHttpHeaderSize="819200" 
           keystoreFile="....keystore" keystorePass="****"
           protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
           secure="true" sslProtocol="TLS" compression="on" SSSLVerifyClient="none" />

here scrrenshots on postman testing :

working : https://ibb.co/0K679Hf

not working : https://ibb.co/4JG2WSR

Michael Hampton avatar
cz flag
Check your application's logs.
Asher avatar
il flag
@MichaelHampton as the app is deployed on tomcat so in the log '400 bad req' doesn't appear
Michael Hampton avatar
cz flag
Then it would be in something like catalina.out or wherever you configured Tomcat to log.
Asher avatar
il flag
@MichaelHampton what will log helps ! here the log on catalina of two diffrent request https://ibb.co/PNm0DYt
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.