Заголовок запроса постмэппинга Spring Boot слишком великJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Заголовок запроса постмэппинга Spring Boot слишком велик

Сообщение Anonymous »

Я пытаюсь преобразовать строку html в pdf с помощью летающей тарелки, код работает нормально на моем локальном компьютере, но затем, когда я развертываю в dev environemtn, я получаю слишком большую ошибку заголовка запроса. Я попробовал добавить server.max-http-header-request-size=32KB, но все равно не вижу никакой разницы. как я могу отправить большую строку HTML в качестве тела ответа?вот мой код, может ли кто-нибудь мне помочь?

Код: Выделить всё

@RequestMapping(value = "/generatePdfFile", method = RequestMethod.POST)
public ResponseEntity generatePdfFile(String htmlContent, HttpServletResponse response) throws IOException {
try {
logger.info("triggered generatePdfFile API.");
ByteArrayInputStream byteArrayInputStream = convertHtmlToPdfusingFlyingSaucer(htmlContent);
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=file.pdf");
IOUtils.copy(byteArrayInputStream, response.getOutputStream());
response.flushBuffer();
logger.info("PDF Generation successful.");
return ResponseEntity.ok("PDF generated successfully.");
} catch (Exception e) {
logger.error("Error generating PDF: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to generate PDF.");
}
}
и вот что у меня есть в файле app.props:

Код: Выделить всё

server.max-http-request-header-size=4MB
server.tomcat.max-http-request-header-size=4MB
server.max-request-size=4MB
server.max-form-headers=4MB
Вот какую ошибку я получаю:

Код: Выделить всё

this is the error that im getting

HTTP Status 400 – Bad Requestbody {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}HTTP Status 400 – Bad Request
Type[/b] Exception Report

[b]Message[/b] Request header is too large

[b]Description[/b] The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

[b]Exception[/b]

java.lang.IllegalArgumentException: Request header is too large[b]    org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:770)
org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:442)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:264)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
java.base/java.lang.Thread.run(Thread.java:833)
Note[/b] The full stack trace of the root cause is available in the server logs.
Apache Tomcat/10.1.19
или если я добавлю RequestBody в свой html-контент

Код: Выделить всё

@RequestMapping(value = "/generatePdfFile", method = RequestMethod.POST)
public ResponseEntity generatePdfFile(@RequestBody String htmlContent, HttpServletResponse response) throws IOException {}
тогда я получаю 400, неправильный запрос, не знаю, что я здесь делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/787 ... -too-large
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»